summaryrefslogtreecommitdiff
path: root/cli/atomicgroup_unittest.py
blob: 27a1c989057f1852c18c48936e96968c3ea134a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/python -u

"""Tests for atomicgroup."""

import unittest

import common
from autotest_lib.cli import cli_mock, topic_common, atomicgroup


class atomicgroup_unittest(cli_mock.cli_unittest):
    def setUp(self):
        super(atomicgroup_unittest, self).setUp()


    def run_cmd(self, argv, *args, **kwargs):
        atomicgroup_argv = ['atest', 'atomicgroup'] + argv
        super(atomicgroup_unittest, self).run_cmd(
                argv=atomicgroup_argv, *args, **kwargs)


    atomicgroups = [
                {'name': 'group0',
                 'description': 'description0',
                 'max_number_of_machines': 3,
                 'invalid': True},
                {'name': 'group1',
                 'description': 'description1',
                 'max_number_of_machines': 13,
                 'invalid': False},
                {'name': 'group2',
                 'description': 'description2',
                 'max_number_of_machines': 23,
                 'invalid': False},
            ]


    def test_atomicgroup_list(self):
        valid_groups = [ag for ag in self.atomicgroups if not ag['invalid']]
        self.run_cmd(argv=['list'],
                     rpcs=[('get_atomic_groups', {},
                            True, valid_groups)],
                     out_words_ok=['group1', 'description2', '23', 'True'],
                     out_words_no=['group0', 'description0', 'False'],
                    )


    def test_atomicgroup_list_show_invalid(self):
        self.run_cmd(argv=['list', '--show-invalid'],
                     rpcs=[('get_atomic_groups', {},
                            True, self.atomicgroups)],
                     out_words_ok=['group1', 'description2', '23', 'True'],
                    )


    def test_atomicgroup_create(self):
        self.run_cmd(argv=['create', '-n', '33', '-d', 'Fruits', 'ag-name'],
                     rpcs=[('add_atomic_group',
                            dict(name='ag-name', description='Fruits',
                                 max_number_of_machines=33),
                            True, 1)],
                     out_words_ok=['Created', 'atomicgroup', 'ag-name'],
                    )

    def test_atomicgroup_create_longargs(self):
        self.run_cmd(argv=['create', '--max_number_of_machines', '33',
                           '--description', 'Fruits', 'ag-name'],
                     rpcs=[('add_atomic_group',
                            dict(name='ag-name', description='Fruits',
                                 max_number_of_machines=33),
                            True, 1)],
                     out_words_ok=['Created', 'atomicgroup', 'ag-name'],
                    )


    def test_atomicgroup_delete(self):
        self.run_cmd(argv=['delete', 'ag-name'],
                     rpcs=[('delete_atomic_group', dict(id='ag-name'),
                            True, None)],
                     out_words_ok=['Deleted', 'atomicgroup', 'ag-name'],
                    )


    def test_atomicgroup_add(self):
        self.run_cmd(argv=['add', '--label', 'One', 'ag-name'],
                     rpcs=[('atomic_group_add_labels',
                            dict(id='ag-name', labels=['One']),
                            True, None)],
                     out_words_ok=['Added', 'atomicgroup', 'ag-name'],
                    )

    def test_atomicgroup_remove(self):
        self.run_cmd(argv=['remove', '--label', 'One', 'ag-name'],
                     rpcs=[('atomic_group_remove_labels',
                            dict(id='ag-name', labels=['One']),
                            True, None)],
                     out_words_ok=['Removed', 'atomicgroup', 'ag-name'],
                    )


if __name__ == '__main__':
    unittest.main()