Home | History | Annotate | Download | only in cli
      1 # pylint: disable-msg=C0111
      2 #!/usr/bin/python -u
      3 
      4 """Tests for atomicgroup."""
      5 
      6 import unittest
      7 
      8 import common
      9 from autotest_lib.cli import cli_mock
     10 
     11 
     12 class atomicgroup_unittest(cli_mock.cli_unittest):
     13     def setUp(self):
     14         super(atomicgroup_unittest, self).setUp()
     15 
     16 
     17     def run_cmd(self, argv, *args, **kwargs):
     18         atomicgroup_argv = ['atest', 'atomicgroup'] + argv
     19         super(atomicgroup_unittest, self).run_cmd(
     20                 argv=atomicgroup_argv, *args, **kwargs)
     21 
     22 
     23     atomicgroups = [
     24                 {'name': 'group0',
     25                  'description': 'description0',
     26                  'max_number_of_machines': 3,
     27                  'invalid': True},
     28                 {'name': 'group1',
     29                  'description': 'description1',
     30                  'max_number_of_machines': 13,
     31                  'invalid': False},
     32                 {'name': 'group2',
     33                  'description': 'description2',
     34                  'max_number_of_machines': 23,
     35                  'invalid': False},
     36             ]
     37 
     38 
     39     def test_atomicgroup_list(self):
     40         valid_groups = [ag for ag in self.atomicgroups if not ag['invalid']]
     41         self.run_cmd(argv=['list'],
     42                      rpcs=[('get_atomic_groups', {},
     43                             True, valid_groups)],
     44                      out_words_ok=['group1', 'description2', '23', 'True'],
     45                      out_words_no=['group0', 'description0', 'False'],
     46                     )
     47 
     48 
     49     def test_atomicgroup_list_show_invalid(self):
     50         self.run_cmd(argv=['list', '--show-invalid'],
     51                      rpcs=[('get_atomic_groups', {},
     52                             True, self.atomicgroups)],
     53                      out_words_ok=['group1', 'description2', '23', 'True'],
     54                     )
     55 
     56 
     57     def test_atomicgroup_create(self):
     58         self.run_cmd(argv=['create', '-n', '33', '-d', 'Fruits', 'ag-name'],
     59                      rpcs=[('add_atomic_group',
     60                             dict(name='ag-name', description='Fruits',
     61                                  max_number_of_machines=33),
     62                             True, 1)],
     63                      out_words_ok=['Created', 'atomicgroup', 'ag-name'],
     64                     )
     65 
     66     def test_atomicgroup_create_longargs(self):
     67         self.run_cmd(argv=['create', '--max_number_of_machines', '33',
     68                            '--description', 'Fruits', 'ag-name'],
     69                      rpcs=[('add_atomic_group',
     70                             dict(name='ag-name', description='Fruits',
     71                                  max_number_of_machines=33),
     72                             True, 1)],
     73                      out_words_ok=['Created', 'atomicgroup', 'ag-name'],
     74                     )
     75 
     76 
     77     def test_atomicgroup_delete(self):
     78         self.run_cmd(argv=['delete', 'ag-name', '--no-confirmation'],
     79                      rpcs=[('delete_atomic_group', dict(id='ag-name'),
     80                             True, None)],
     81                      out_words_ok=['Deleted', 'atomicgroup', 'ag-name'],
     82                     )
     83 
     84 
     85     def test_atomicgroup_add(self):
     86         self.run_cmd(argv=['add', '--label', 'One', 'ag-name'],
     87                      rpcs=[('atomic_group_add_labels',
     88                             dict(id='ag-name', labels=['One']),
     89                             True, None)],
     90                      out_words_ok=['Added', 'atomicgroup', 'ag-name'],
     91                     )
     92 
     93     def test_atomicgroup_remove(self):
     94         self.run_cmd(argv=['remove', '--label', 'One', 'ag-name'],
     95                      rpcs=[('atomic_group_remove_labels',
     96                             dict(id='ag-name', labels=['One']),
     97                             True, None)],
     98                      out_words_ok=['Removed', 'atomicgroup', 'ag-name'],
     99                     )
    100 
    101 
    102 if __name__ == '__main__':
    103     unittest.main()
    104