Home | History | Annotate | Download | only in cli
      1 #!/usr/bin/python
      2 #
      3 # Copyright 2008 Google Inc. All Rights Reserved.
      4 
      5 """Test for host."""
      6 
      7 import unittest, os, sys
      8 
      9 import common
     10 from autotest_lib.cli import cli_mock, host
     11 from autotest_lib.client.common_lib import control_data
     12 
     13 CLIENT = control_data.CONTROL_TYPE_NAMES.CLIENT
     14 SERVER = control_data.CONTROL_TYPE_NAMES.SERVER
     15 
     16 class host_ut(cli_mock.cli_unittest):
     17     def test_parse_lock_options_both_set(self):
     18         hh = host.host()
     19         class opt(object):
     20             lock = True
     21             unlock = True
     22         options = opt()
     23         self.usage = "unused"
     24         sys.exit.expect_call(1).and_raises(cli_mock.ExitException)
     25         self.god.mock_io()
     26         self.assertRaises(cli_mock.ExitException,
     27                           hh._parse_lock_options, options)
     28         self.god.unmock_io()
     29 
     30 
     31     def test_cleanup_labels_with_platform(self):
     32         labels = ['l0', 'l1', 'l2', 'p0', 'l3']
     33         hh = host.host()
     34         self.assertEqual(['l0', 'l1', 'l2', 'l3'],
     35                          hh._cleanup_labels(labels, 'p0'))
     36 
     37 
     38     def test_cleanup_labels_no_platform(self):
     39         labels = ['l0', 'l1', 'l2', 'l3']
     40         hh = host.host()
     41         self.assertEqual(['l0', 'l1', 'l2', 'l3'],
     42                          hh._cleanup_labels(labels))
     43 
     44 
     45     def test_cleanup_labels_with_non_avail_platform(self):
     46         labels = ['l0', 'l1', 'l2', 'l3']
     47         hh = host.host()
     48         self.assertEqual(['l0', 'l1', 'l2', 'l3'],
     49                          hh._cleanup_labels(labels, 'p0'))
     50 
     51 
     52 class host_list_unittest(cli_mock.cli_unittest):
     53     def test_parse_host_not_required(self):
     54         hl = host.host_list()
     55         sys.argv = ['atest']
     56         (options, leftover) = hl.parse()
     57         self.assertEqual([], hl.hosts)
     58         self.assertEqual([], leftover)
     59 
     60 
     61     def test_parse_with_hosts(self):
     62         hl = host.host_list()
     63         mfile = cli_mock.create_file('host0\nhost3\nhost4\n')
     64         sys.argv = ['atest', 'host1', '--mlist', mfile.name, 'host3']
     65         (options, leftover) = hl.parse()
     66         self.assertEqualNoOrder(['host0', 'host1','host3', 'host4'],
     67                                 hl.hosts)
     68         self.assertEqual(leftover, [])
     69         mfile.clean()
     70 
     71 
     72     def test_parse_with_labels(self):
     73         hl = host.host_list()
     74         sys.argv = ['atest', '--label', 'label0']
     75         (options, leftover) = hl.parse()
     76         self.assertEqual(['label0'], hl.labels)
     77         self.assertEqual(leftover, [])
     78 
     79 
     80     def test_parse_with_multi_labels(self):
     81         hl = host.host_list()
     82         sys.argv = ['atest', '--label', 'label0,label2']
     83         (options, leftover) = hl.parse()
     84         self.assertEqualNoOrder(['label0', 'label2'], hl.labels)
     85         self.assertEqual(leftover, [])
     86 
     87 
     88     def test_parse_with_escaped_commas_label(self):
     89         hl = host.host_list()
     90         sys.argv = ['atest', '--label', 'label\\,0']
     91         (options, leftover) = hl.parse()
     92         self.assertEqual(['label,0'], hl.labels)
     93         self.assertEqual(leftover, [])
     94 
     95 
     96     def test_parse_with_escaped_commas_multi_labels(self):
     97         hl = host.host_list()
     98         sys.argv = ['atest', '--label', 'label\\,0,label\\,2']
     99         (options, leftover) = hl.parse()
    100         self.assertEqualNoOrder(['label,0', 'label,2'], hl.labels)
    101         self.assertEqual(leftover, [])
    102 
    103 
    104     def test_parse_with_both(self):
    105         hl = host.host_list()
    106         mfile = cli_mock.create_file('host0\nhost3\nhost4\n')
    107         sys.argv = ['atest', 'host1', '--mlist', mfile.name, 'host3',
    108                     '--label', 'label0']
    109         (options, leftover) = hl.parse()
    110         self.assertEqualNoOrder(['host0', 'host1','host3', 'host4'],
    111                                 hl.hosts)
    112         self.assertEqual(['label0'], hl.labels)
    113         self.assertEqual(leftover, [])
    114         mfile.clean()
    115 
    116 
    117     def test_execute_list_all_no_labels(self):
    118         self.run_cmd(argv=['atest', 'host', 'list', '--ignore_site_file'],
    119                      rpcs=[('get_hosts', {},
    120                             True,
    121                             [{u'status': u'Ready',
    122                               u'hostname': u'host0',
    123                               u'locked': False,
    124                               u'locked_by': 'user0',
    125                               u'lock_time': u'2008-07-23 12:54:15',
    126                               u'lock_reason': u'',
    127                               u'labels': [],
    128                               u'invalid': False,
    129                               u'synch_id': None,
    130                               u'platform': None,
    131                               u'shard': None,
    132                               u'id': 1},
    133                              {u'status': u'Ready',
    134                               u'hostname': u'host1',
    135                               u'locked': True,
    136                               u'locked_by': 'user0',
    137                               u'lock_time': u'2008-07-23 12:54:15',
    138                               u'lock_reason': u'',
    139                               u'labels': [u'plat1'],
    140                               u'invalid': False,
    141                               u'synch_id': None,
    142                               u'platform': u'plat1',
    143                               u'shard': None,
    144                               u'id': 2}])],
    145                      out_words_ok=['host0', 'host1', 'Ready',
    146                                    'plat1', 'False', 'True', 'None'])
    147 
    148 
    149     def test_execute_list_all_with_labels(self):
    150         self.run_cmd(argv=['atest', 'host', 'list', '--ignore_site_file'],
    151                      rpcs=[('get_hosts', {},
    152                             True,
    153                             [{u'status': u'Ready',
    154                               u'hostname': u'host0',
    155                               u'locked': False,
    156                               u'locked_by': 'user0',
    157                               u'lock_time': u'2008-07-23 12:54:15',
    158                               u'lock_reason': u'',
    159                               u'labels': [u'label0', u'label1'],
    160                               u'invalid': False,
    161                               u'synch_id': None,
    162                               u'platform': None,
    163                               u'shard': None,
    164                               u'id': 1},
    165                              {u'status': u'Ready',
    166                               u'hostname': u'host1',
    167                               u'locked': True,
    168                               u'locked_by': 'user0',
    169                               u'lock_time': u'2008-07-23 12:54:15',
    170                               u'lock_reason': u'',
    171                               u'labels': [u'label2', u'label3', u'plat1'],
    172                               u'invalid': False,
    173                               u'synch_id': None,
    174                               u'shard': None,
    175                               u'platform': u'plat1',
    176                               u'id': 2}])],
    177                      out_words_ok=['host0', 'host1', 'Ready', 'plat1',
    178                                    'label0', 'label1', 'label2', 'label3',
    179                                    'False', 'True', 'None'])
    180 
    181 
    182     def test_execute_list_filter_one_host(self):
    183         self.run_cmd(argv=['atest', 'host', 'list', 'host1',
    184                            '--ignore_site_file'],
    185                      rpcs=[('get_hosts', {'hostname__in': ['host1']},
    186                             True,
    187                             [{u'status': u'Ready',
    188                               u'hostname': u'host1',
    189                               u'locked': True,
    190                               u'locked_by': 'user0',
    191                               u'lock_time': u'2008-07-23 12:54:15',
    192                               u'lock_reason': u'',
    193                               u'labels': [u'label2', u'label3', u'plat1'],
    194                               u'invalid': False,
    195                               u'synch_id': None,
    196                               u'platform': u'plat1',
    197                               u'shard': None,
    198                               u'id': 2}])],
    199                      out_words_ok=['host1', 'Ready', 'plat1',
    200                                    'label2', 'label3', 'True', 'None'],
    201                      out_words_no=['host0', 'host2',
    202                                    'label1', 'label4', 'False'])
    203 
    204 
    205     def test_execute_list_filter_two_hosts(self):
    206         mfile = cli_mock.create_file('host2')
    207         self.run_cmd(argv=['atest', 'host', 'list', 'host1',
    208                            '--mlist', mfile.name, '--ignore_site_file'],
    209                      # This is a bit fragile as the list order may change...
    210                      rpcs=[('get_hosts', {'hostname__in': ['host2', 'host1']},
    211                             True,
    212                             [{u'status': u'Ready',
    213                               u'hostname': u'host1',
    214                               u'locked': True,
    215                               u'locked_by': 'user0',
    216                               u'lock_time': u'2008-07-23 12:54:15',
    217                               u'lock_reason': u'',
    218                               u'labels': [u'label2', u'label3', u'plat1'],
    219                               u'invalid': False,
    220                               u'synch_id': None,
    221                               u'platform': u'plat1',
    222                               u'shard': None,
    223                               u'id': 2},
    224                              {u'status': u'Ready',
    225                               u'hostname': u'host2',
    226                               u'locked': True,
    227                               u'locked_by': 'user0',
    228                               u'lock_time': u'2008-07-23 12:54:15',
    229                               u'lock_reason': u'',
    230                               u'labels': [u'label3', u'label4', u'plat1'],
    231                               u'invalid': False,
    232                               u'synch_id': None,
    233                               u'shard': None,
    234                               u'platform': u'plat1',
    235                               u'id': 3}])],
    236                      out_words_ok=['host1', 'Ready', 'plat1',
    237                                    'label2', 'label3', 'True',
    238                                    'host2', 'label4', 'None'],
    239                      out_words_no=['host0', 'label1', 'False'])
    240         mfile.clean()
    241 
    242 
    243     def test_execute_list_filter_two_hosts_one_not_found(self):
    244         mfile = cli_mock.create_file('host2')
    245         self.run_cmd(argv=['atest', 'host', 'list', 'host1',
    246                            '--mlist', mfile.name, '--ignore_site_file'],
    247                      # This is a bit fragile as the list order may change...
    248                      rpcs=[('get_hosts', {'hostname__in': ['host2', 'host1']},
    249                             True,
    250                             [{u'status': u'Ready',
    251                               u'hostname': u'host2',
    252                               u'locked': True,
    253                               u'locked_by': 'user0',
    254                               u'lock_time': u'2008-07-23 12:54:15',
    255                               u'lock_reason': u'',
    256                               u'labels': [u'label3', u'label4', u'plat1'],
    257                               u'invalid': False,
    258                               u'synch_id': None,
    259                               u'shard': None,
    260                               u'platform': u'plat1',
    261                               u'id': 3}])],
    262                      out_words_ok=['Ready', 'plat1',
    263                                    'label3', 'label4', 'True', 'None'],
    264                      out_words_no=['host1', 'False'],
    265                      err_words_ok=['host1'])
    266         mfile.clean()
    267 
    268 
    269     def test_execute_list_filter_two_hosts_none_found(self):
    270         self.run_cmd(argv=['atest', 'host', 'list',
    271                            'host1', 'host2', '--ignore_site_file'],
    272                      # This is a bit fragile as the list order may change...
    273                      rpcs=[('get_hosts', {'hostname__in': ['host2', 'host1']},
    274                             True,
    275                             [])],
    276                      out_words_ok=[],
    277                      out_words_no=['Hostname', 'Status'],
    278                      err_words_ok=['Unknown', 'host1', 'host2'])
    279 
    280 
    281     def test_execute_list_filter_label(self):
    282         self.run_cmd(argv=['atest', 'host', 'list',
    283                            '-b', 'label3', '--ignore_site_file'],
    284                      rpcs=[('get_hosts', {'labels__name__in': ['label3']},
    285                             True,
    286                             [{u'status': u'Ready',
    287                               u'hostname': u'host1',
    288                               u'locked': True,
    289                               u'locked_by': 'user0',
    290                               u'lock_time': u'2008-07-23 12:54:15',
    291                               u'lock_reason': u'',
    292                               u'labels': [u'label2', u'label3', u'plat1'],
    293                               u'invalid': False,
    294                               u'synch_id': None,
    295                               u'platform': u'plat1',
    296                               u'shard': None,
    297                               u'id': 2},
    298                              {u'status': u'Ready',
    299                               u'hostname': u'host2',
    300                               u'locked': True,
    301                               u'locked_by': 'user0',
    302                               u'lock_time': u'2008-07-23 12:54:15',
    303                               u'lock_reason': u'',
    304                               u'labels': [u'label3', u'label4', u'plat1'],
    305                               u'invalid': False,
    306                               u'shard': None,
    307                               u'synch_id': None,
    308                               u'platform': u'plat1',
    309                               u'id': 3}])],
    310                      out_words_ok=['host1', 'Ready', 'plat1',
    311                                    'label2', 'label3', 'True',
    312                                    'host2', 'label4', 'None'],
    313                      out_words_no=['host0', 'label1', 'False'])
    314 
    315 
    316     def test_execute_list_filter_multi_labels(self):
    317         self.run_cmd(argv=['atest', 'host', 'list',
    318                            '-b', 'label3,label2', '--ignore_site_file'],
    319                      rpcs=[('get_hosts', {'multiple_labels': ['label2',
    320                                                               'label3']},
    321                             True,
    322                             [{u'status': u'Ready',
    323                               u'hostname': u'host1',
    324                               u'locked': True,
    325                               u'locked_by': 'user0',
    326                               u'lock_time': u'2008-07-23 12:54:15',
    327                               u'lock_reason': u'',
    328                               u'labels': [u'label2', u'label3', u'plat0'],
    329                               u'invalid': False,
    330                               u'synch_id': None,
    331                               u'shard': None,
    332                               u'platform': u'plat0',
    333                               u'id': 2},
    334                              {u'status': u'Ready',
    335                               u'hostname': u'host3',
    336                               u'locked': True,
    337                               u'locked_by': 'user0',
    338                               u'lock_time': u'2008-07-23 12:54:15',
    339                               u'lock_reason': u'',
    340                               u'labels': [u'label3', u'label2', u'plat2'],
    341                               u'invalid': False,
    342                               u'synch_id': None,
    343                               u'shard': None,
    344                               u'platform': u'plat2',
    345                               u'id': 4}])],
    346                      out_words_ok=['host1', 'host3', 'Ready', 'plat0',
    347                                    'label2', 'label3', 'plat2', 'None'],
    348                      out_words_no=['host2', 'label4', 'False', 'plat1'])
    349 
    350 
    351     def test_execute_list_filter_three_labels(self):
    352         self.run_cmd(argv=['atest', 'host', 'list',
    353                            '-b', 'label3,label2, label4',
    354                            '--ignore_site_file'],
    355                      rpcs=[('get_hosts', {'multiple_labels': ['label2',
    356                                                               'label3',
    357                                                               'label4']},
    358                             True,
    359                             [{u'status': u'Ready',
    360                               u'hostname': u'host2',
    361                               u'locked': True,
    362                               u'locked_by': 'user0',
    363                               u'lock_time': u'2008-07-23 12:54:15',
    364                               u'lock_reason': u'',
    365                               u'labels': [u'label3', u'label2', u'label4',
    366                                           u'plat1'],
    367                               u'invalid': False,
    368                               u'synch_id': None,
    369                               u'platform': u'plat1',
    370                               u'shard': None,
    371                               u'id': 3}])],
    372                      out_words_ok=['host2', 'plat1',
    373                                    'label2', 'label3', 'label4', 'None'],
    374                      out_words_no=['host1', 'host3'])
    375 
    376 
    377     def test_execute_list_filter_wild_labels(self):
    378         self.run_cmd(argv=['atest', 'host', 'list',
    379                            '-b', 'label*',
    380                            '--ignore_site_file'],
    381                      rpcs=[('get_hosts',
    382                             {'labels__name__startswith': 'label'},
    383                             True,
    384                             [{u'status': u'Ready',
    385                               u'hostname': u'host2',
    386                               u'locked': 1,
    387                               u'shard': None,
    388                               u'locked_by': 'user0',
    389                               u'lock_time': u'2008-07-23 12:54:15',
    390                               u'lock_reason': u'',
    391                               u'labels': [u'label3', u'label2', u'label4',
    392                                           u'plat1'],
    393                               u'invalid': 0,
    394                               u'synch_id': None,
    395                               u'platform': u'plat1',
    396                               u'id': 3}])],
    397                      out_words_ok=['host2', 'plat1',
    398                                    'label2', 'label3', 'label4', 'None'],
    399                      out_words_no=['host1', 'host3'])
    400 
    401 
    402     def test_execute_list_filter_multi_labels_no_results(self):
    403         self.run_cmd(argv=['atest', 'host', 'list',
    404                            '-b', 'label3,label2, ', '--ignore_site_file'],
    405                      rpcs=[('get_hosts', {'multiple_labels': ['label2',
    406                                                               'label3']},
    407                             True,
    408                             [])],
    409                      out_words_ok=[],
    410                      out_words_no=['host1', 'host2', 'host3',
    411                                    'label2', 'label3', 'label4'])
    412 
    413 
    414     def test_execute_list_filter_label_and_hosts(self):
    415         self.run_cmd(argv=['atest', 'host', 'list', 'host1',
    416                            '-b', 'label3', 'host2', '--ignore_site_file'],
    417                      rpcs=[('get_hosts', {'labels__name__in': ['label3'],
    418                                           'hostname__in': ['host2', 'host1']},
    419                             True,
    420                             [{u'status': u'Ready',
    421                               u'hostname': u'host1',
    422                               u'locked': True,
    423                               u'locked_by': 'user0',
    424                               u'lock_time': u'2008-07-23 12:54:15',
    425                               u'labels': [u'label2', u'label3', u'plat1'],
    426                               u'lock_reason': u'',
    427                               u'invalid': False,
    428                               u'synch_id': None,
    429                               u'platform': u'plat1',
    430                               u'shard': None,
    431                               u'id': 2},
    432                              {u'status': u'Ready',
    433                               u'hostname': u'host2',
    434                               u'locked': True,
    435                               u'locked_by': 'user0',
    436                               u'lock_time': u'2008-07-23 12:54:15',
    437                               u'lock_reason': u'',
    438                               u'labels': [u'label3', u'label4', u'plat1'],
    439                               u'invalid': False,
    440                               u'synch_id': None,
    441                               u'shard': None,
    442                               u'platform': u'plat1',
    443                               u'id': 3}])],
    444                      out_words_ok=['host1', 'Ready', 'plat1',
    445                                    'label2', 'label3', 'True',
    446                                    'host2', 'label4', 'None'],
    447                      out_words_no=['host0', 'label1', 'False'])
    448 
    449 
    450     def test_execute_list_filter_label_and_hosts_none(self):
    451         self.run_cmd(argv=['atest', 'host', 'list', 'host1',
    452                            '-b', 'label3', 'host2', '--ignore_site_file'],
    453                      rpcs=[('get_hosts', {'labels__name__in': ['label3'],
    454                                           'hostname__in': ['host2', 'host1']},
    455                             True,
    456                             [])],
    457                      out_words_ok=[],
    458                      out_words_no=['Hostname', 'Status'],
    459                      err_words_ok=['Unknown', 'host1', 'host2'])
    460 
    461 
    462     def test_execute_list_filter_status(self):
    463         self.run_cmd(argv=['atest', 'host', 'list',
    464                            '-s', 'Ready', '--ignore_site_file'],
    465                      rpcs=[('get_hosts', {'status__in': ['Ready']},
    466                             True,
    467                             [{u'status': u'Ready',
    468                               u'hostname': u'host1',
    469                               u'locked': True,
    470                               u'locked_by': 'user0',
    471                               u'lock_time': u'2008-07-23 12:54:15',
    472                               u'lock_reason': u'',
    473                               u'labels': [u'label2', u'label3', u'plat1'],
    474                               u'invalid': False,
    475                               u'synch_id': None,
    476                               u'platform': u'plat1',
    477                               u'shard': None,
    478                               u'id': 2},
    479                              {u'status': u'Ready',
    480                               u'hostname': u'host2',
    481                               u'locked': True,
    482                               u'locked_by': 'user0',
    483                               u'lock_time': u'2008-07-23 12:54:15',
    484                               u'lock_reason': u'',
    485                               u'labels': [u'label3', u'label4', u'plat1'],
    486                               u'invalid': False,
    487                               u'synch_id': None,
    488                               u'shard': None,
    489                               u'platform': u'plat1',
    490                               u'id': 3}])],
    491                      out_words_ok=['host1', 'Ready', 'plat1',
    492                                    'label2', 'label3', 'True',
    493                                    'host2', 'label4', 'None'],
    494                      out_words_no=['host0', 'label1', 'False'])
    495 
    496 
    497 
    498     def test_execute_list_filter_status_and_hosts(self):
    499         self.run_cmd(argv=['atest', 'host', 'list', 'host1',
    500                            '-s', 'Ready', 'host2', '--ignore_site_file'],
    501                      rpcs=[('get_hosts', {'status__in': ['Ready'],
    502                                           'hostname__in': ['host2', 'host1']},
    503                             True,
    504                             [{u'status': u'Ready',
    505                               u'hostname': u'host1',
    506                               u'locked': True,
    507                               u'locked_by': 'user0',
    508                               u'lock_time': u'2008-07-23 12:54:15',
    509                               u'lock_reason': u'',
    510                               u'labels': [u'label2', u'label3', u'plat1'],
    511                               u'invalid': False,
    512                               u'synch_id': None,
    513                               u'platform': u'plat1',
    514                               u'shard': None,
    515                               u'id': 2},
    516                              {u'status': u'Ready',
    517                               u'hostname': u'host2',
    518                               u'locked': True,
    519                               u'locked_by': 'user0',
    520                               u'lock_time': u'2008-07-23 12:54:15',
    521                               u'lock_reason': u'',
    522                               u'labels': [u'label3', u'label4', u'plat1'],
    523                               u'invalid': False,
    524                               u'synch_id': None,
    525                               u'shard': None,
    526                               u'platform': u'plat1',
    527                               u'id': 3}])],
    528                      out_words_ok=['host1', 'Ready', 'plat1',
    529                                    'label2', 'label3', 'True',
    530                                    'host2', 'label4', 'None'],
    531                      out_words_no=['host0', 'label1', 'False'])
    532 
    533 
    534     def test_execute_list_filter_status_and_hosts_none(self):
    535         self.run_cmd(argv=['atest', 'host', 'list', 'host1',
    536                            '--status', 'Repair',
    537                            'host2', '--ignore_site_file'],
    538                      rpcs=[('get_hosts', {'status__in': ['Repair'],
    539                                           'hostname__in': ['host2', 'host1']},
    540                             True,
    541                             [])],
    542                      out_words_ok=[],
    543                      out_words_no=['Hostname', 'Status'],
    544                      err_words_ok=['Unknown', 'host2'])
    545 
    546 
    547     def test_execute_list_filter_statuses_and_hosts_none(self):
    548         self.run_cmd(argv=['atest', 'host', 'list', 'host1',
    549                            '--status', 'Repair',
    550                            'host2', '--ignore_site_file'],
    551                      rpcs=[('get_hosts', {'status__in': ['Repair'],
    552                                           'hostname__in': ['host2', 'host1']},
    553                             True,
    554                             [])],
    555                      out_words_ok=[],
    556                      out_words_no=['Hostname', 'Status'],
    557                      err_words_ok=['Unknown', 'host2'])
    558 
    559 
    560     def test_execute_list_filter_locked(self):
    561         self.run_cmd(argv=['atest', 'host', 'list', 'host1',
    562                            '--locked', 'host2', '--ignore_site_file'],
    563                      rpcs=[('get_hosts', {'locked': True,
    564                                           'hostname__in': ['host2', 'host1']},
    565                             True,
    566                             [{u'status': u'Ready',
    567                               u'hostname': u'host1',
    568                               u'locked': True,
    569                               u'locked_by': 'user0',
    570                               u'lock_reason': u'',
    571                               u'lock_time': u'2008-07-23 12:54:15',
    572                               u'labels': [u'label2', u'label3', u'plat1'],
    573                               u'invalid': False,
    574                               u'synch_id': None,
    575                               u'platform': u'plat1',
    576                               u'shard': None,
    577                               u'id': 2},
    578                              {u'status': u'Ready',
    579                               u'hostname': u'host2',
    580                               u'locked': True,
    581                               u'locked_by': 'user0',
    582                               u'lock_reason': u'',
    583                               u'lock_time': u'2008-07-23 12:54:15',
    584                               u'labels': [u'label3', u'label4', u'plat1'],
    585                               u'invalid': False,
    586                               u'synch_id': None,
    587                               u'shard': None,
    588                               u'platform': u'plat1',
    589                               u'id': 3}])],
    590                      out_words_ok=['host1', 'Ready', 'plat1',
    591                                    'label2', 'label3', 'True',
    592                                    'host2', 'label4', 'None'],
    593                      out_words_no=['host0', 'label1', 'False'])
    594 
    595 
    596     def test_execute_list_filter_unlocked(self):
    597         self.run_cmd(argv=['atest', 'host', 'list',
    598                            '--unlocked', '--ignore_site_file'],
    599                      rpcs=[('get_hosts', {'locked': False},
    600                             True,
    601                             [{u'status': u'Ready',
    602                               u'hostname': u'host1',
    603                               u'locked': False,
    604                               u'locked_by': 'user0',
    605                               u'lock_time': u'2008-07-23 12:54:15',
    606                               u'lock_reason': u'',
    607                               u'labels': [u'label2', u'label3', u'plat1'],
    608                               u'invalid': False,
    609                               u'synch_id': None,
    610                               u'shard': None,
    611                               u'platform': u'plat1',
    612                               u'id': 2},
    613                              {u'status': u'Ready',
    614                               u'hostname': u'host2',
    615                               u'locked': False,
    616                               u'locked_by': 'user0',
    617                               u'lock_time': u'2008-07-23 12:54:15',
    618                               u'lock_reason': u'',
    619                               u'labels': [u'label3', u'label4', u'plat1'],
    620                               u'invalid': False,
    621                               u'shard': None,
    622                               u'synch_id': None,
    623                               u'platform': u'plat1',
    624                               u'id': 3}])],
    625                      out_words_ok=['host1', 'Ready', 'plat1',
    626                                    'label2', 'label3', 'False',
    627                                    'host2', 'label4', 'None'],
    628                      out_words_no=['host0', 'label1', 'True'])
    629 
    630 
    631 class host_stat_unittest(cli_mock.cli_unittest):
    632     def test_execute_stat_two_hosts(self):
    633         # The order of RPCs between host1 and host0 could change...
    634         self.run_cmd(argv=['atest', 'host', 'stat', 'host0', 'host1',
    635                            '--ignore_site_file'],
    636                      rpcs=[('get_hosts', {'hostname': 'host1'},
    637                             True,
    638                             [{u'status': u'Ready',
    639                               u'hostname': u'host1',
    640                               u'locked': True,
    641                               u'lock_time': u'2008-07-23 12:54:15',
    642                               u'locked_by': 'user0',
    643                               u'lock_reason': u'',
    644                               u'protection': 'No protection',
    645                               u'labels': [u'label3', u'label4', u'plat1'],
    646                               u'invalid': False,
    647                               u'synch_id': None,
    648                               u'shard': None,
    649                               u'platform': u'plat1',
    650                               u'id': 3,
    651                               u'attributes': {}}]),
    652                            ('get_hosts', {'hostname': 'host0'},
    653                             True,
    654                             [{u'status': u'Ready',
    655                               u'hostname': u'host0',
    656                               u'locked': False,
    657                               u'locked_by': 'user0',
    658                               u'lock_time': u'2008-07-23 12:54:15',
    659                               u'lock_reason': u'',
    660                               u'protection': u'No protection',
    661                               u'labels': [u'label0', u'plat0'],
    662                               u'invalid': False,
    663                               u'shard': None,
    664                               u'synch_id': None,
    665                               u'platform': u'plat0',
    666                               u'id': 2,
    667                               u'attributes': {}}]),
    668                            ('get_acl_groups', {'hosts__hostname': 'host1'},
    669                             True,
    670                             [{u'description': u'',
    671                               u'hosts': [u'host0', u'host1'],
    672                               u'id': 1,
    673                               u'name': u'Everyone',
    674                               u'users': [u'user2', u'debug_user', u'user0']}]),
    675                            ('get_labels', {'host__hostname': 'host1'},
    676                             True,
    677                             [{u'id': 2,
    678                               u'platform': 1,
    679                               u'name': u'jme',
    680                               u'invalid': False,
    681                               u'kernel_config': u''}]),
    682                            ('get_acl_groups', {'hosts__hostname': 'host0'},
    683                             True,
    684                             [{u'description': u'',
    685                               u'hosts': [u'host0', u'host1'],
    686                               u'id': 1,
    687                               u'name': u'Everyone',
    688                               u'users': [u'user0', u'debug_user']},
    689                              {u'description': u'myacl0',
    690                               u'hosts': [u'host0'],
    691                               u'id': 2,
    692                               u'name': u'acl0',
    693                               u'users': [u'user0']}]),
    694                            ('get_labels', {'host__hostname': 'host0'},
    695                             True,
    696                             [{u'id': 4,
    697                               u'platform': 0,
    698                               u'name': u'label0',
    699                               u'invalid': False,
    700                               u'kernel_config': u''},
    701                              {u'id': 5,
    702                               u'platform': 1,
    703                               u'name': u'plat0',
    704                               u'invalid': False,
    705                               u'kernel_config': u''}])],
    706                      out_words_ok=['host0', 'host1', 'plat0', 'plat1',
    707                                    'Everyone', 'acl0', 'label0'])
    708 
    709 
    710     def test_execute_stat_one_bad_host_verbose(self):
    711         self.run_cmd(argv=['atest', 'host', 'stat', 'host0',
    712                            'host1', '-v', '--ignore_site_file'],
    713                      rpcs=[('get_hosts', {'hostname': 'host1'},
    714                             True,
    715                             []),
    716                            ('get_hosts', {'hostname': 'host0'},
    717                             True,
    718                             [{u'status': u'Ready',
    719                               u'hostname': u'host0',
    720                               u'locked': False,
    721                               u'locked_by': 'user0',
    722                               u'lock_time': u'2008-07-23 12:54:15',
    723                               u'lock_reason': u'',
    724                               u'protection': u'No protection',
    725                               u'labels': [u'label0', u'plat0'],
    726                               u'invalid': False,
    727                               u'synch_id': None,
    728                               u'platform': u'plat0',
    729                               u'id': 2,
    730                               u'attributes': {}}]),
    731                            ('get_acl_groups', {'hosts__hostname': 'host0'},
    732                             True,
    733                             [{u'description': u'',
    734                               u'hosts': [u'host0', u'host1'],
    735                               u'id': 1,
    736                               u'name': u'Everyone',
    737                               u'users': [u'user0', u'debug_user']},
    738                              {u'description': u'myacl0',
    739                               u'hosts': [u'host0'],
    740                               u'id': 2,
    741                               u'name': u'acl0',
    742                               u'users': [u'user0']}]),
    743                            ('get_labels', {'host__hostname': 'host0'},
    744                             True,
    745                             [{u'id': 4,
    746                               u'platform': 0,
    747                               u'name': u'label0',
    748                               u'invalid': False,
    749                               u'kernel_config': u''},
    750                              {u'id': 5,
    751                               u'platform': 1,
    752                               u'name': u'plat0',
    753                               u'invalid': False,
    754                               u'kernel_config': u''}])],
    755                      out_words_ok=['host0', 'plat0',
    756                                    'Everyone', 'acl0', 'label0'],
    757                      out_words_no=['host1'],
    758                      err_words_ok=['host1', 'Unknown host'],
    759                      err_words_no=['host0'])
    760 
    761 
    762     def test_execute_stat_one_bad_host(self):
    763         self.run_cmd(argv=['atest', 'host', 'stat', 'host0', 'host1',
    764                            '--ignore_site_file'],
    765                      rpcs=[('get_hosts', {'hostname': 'host1'},
    766                             True,
    767                             []),
    768                            ('get_hosts', {'hostname': 'host0'},
    769                             True,
    770                             [{u'status': u'Ready',
    771                               u'hostname': u'host0',
    772                               u'locked': False,
    773                               u'locked_by': 'user0',
    774                               u'lock_time': u'2008-07-23 12:54:15',
    775                               u'lock_reason': u'',
    776                               u'protection': u'No protection',
    777                               u'labels': [u'label0', u'plat0'],
    778                               u'invalid': False,
    779                               u'synch_id': None,
    780                               u'platform': u'plat0',
    781                               u'id': 2,
    782                               u'attributes': {}}]),
    783                            ('get_acl_groups', {'hosts__hostname': 'host0'},
    784                             True,
    785                             [{u'description': u'',
    786                               u'hosts': [u'host0', u'host1'],
    787                               u'id': 1,
    788                               u'name': u'Everyone',
    789                               u'users': [u'user0', u'debug_user']},
    790                              {u'description': u'myacl0',
    791                               u'hosts': [u'host0'],
    792                               u'id': 2,
    793                               u'name': u'acl0',
    794                               u'users': [u'user0']}]),
    795                            ('get_labels', {'host__hostname': 'host0'},
    796                             True,
    797                             [{u'id': 4,
    798                               u'platform': 0,
    799                               u'name': u'label0',
    800                               u'invalid': False,
    801                               u'kernel_config': u''},
    802                              {u'id': 5,
    803                               u'platform': 1,
    804                               u'name': u'plat0',
    805                               u'invalid': False,
    806                               u'kernel_config': u''}])],
    807                      out_words_ok=['host0', 'plat0',
    808                                    'Everyone', 'acl0', 'label0'],
    809                      out_words_no=['host1'],
    810                      err_words_ok=['host1', 'Unknown host'],
    811                      err_words_no=['host0'])
    812 
    813 
    814     def test_execute_stat_wildcard(self):
    815         # The order of RPCs between host1 and host0 could change...
    816         self.run_cmd(argv=['atest', 'host', 'stat', 'ho*',
    817                            '--ignore_site_file'],
    818                      rpcs=[('get_hosts', {'hostname__startswith': 'ho'},
    819                             True,
    820                             [{u'status': u'Ready',
    821                               u'hostname': u'host1',
    822                               u'locked': True,
    823                               u'lock_time': u'2008-07-23 12:54:15',
    824                               u'locked_by': 'user0',
    825                               u'lock_reason': u'',
    826                               u'protection': 'No protection',
    827                               u'labels': [u'label3', u'label4', u'plat1'],
    828                               u'invalid': False,
    829                               u'synch_id': None,
    830                               u'platform': u'plat1',
    831                               u'id': 3,
    832                               u'attributes': {}},
    833                             {u'status': u'Ready',
    834                               u'hostname': u'host0',
    835                               u'locked': False,
    836                               u'locked_by': 'user0',
    837                               u'lock_time': u'2008-07-23 12:54:15',
    838                               u'lock_reason': u'',
    839                               u'protection': u'No protection',
    840                               u'labels': [u'label0', u'plat0'],
    841                               u'invalid': False,
    842                               u'synch_id': None,
    843                               u'platform': u'plat0',
    844                               u'id': 2,
    845                               u'attributes': {}}]),
    846                            ('get_acl_groups', {'hosts__hostname': 'host1'},
    847                             True,
    848                             [{u'description': u'',
    849                               u'hosts': [u'host0', u'host1'],
    850                               u'id': 1,
    851                               u'name': u'Everyone',
    852                               u'users': [u'user2', u'debug_user', u'user0']}]),
    853                            ('get_labels', {'host__hostname': 'host1'},
    854                             True,
    855                             [{u'id': 2,
    856                               u'platform': 1,
    857                               u'name': u'jme',
    858                               u'invalid': False,
    859                               u'kernel_config': u''}]),
    860                            ('get_acl_groups', {'hosts__hostname': 'host0'},
    861                             True,
    862                             [{u'description': u'',
    863                               u'hosts': [u'host0', u'host1'],
    864                               u'id': 1,
    865                               u'name': u'Everyone',
    866                               u'users': [u'user0', u'debug_user']},
    867                              {u'description': u'myacl0',
    868                               u'hosts': [u'host0'],
    869                               u'id': 2,
    870                               u'name': u'acl0',
    871                               u'users': [u'user0']}]),
    872                            ('get_labels', {'host__hostname': 'host0'},
    873                             True,
    874                             [{u'id': 4,
    875                               u'platform': 0,
    876                               u'name': u'label0',
    877                               u'invalid': False,
    878                               u'kernel_config': u''},
    879                              {u'id': 5,
    880                               u'platform': 1,
    881                               u'name': u'plat0',
    882                               u'invalid': False,
    883                               u'kernel_config': u''}])],
    884                      out_words_ok=['host0', 'host1', 'plat0', 'plat1',
    885                                    'Everyone', 'acl0', 'label0'])
    886 
    887 
    888     def test_execute_stat_wildcard_and_host(self):
    889         # The order of RPCs between host1 and host0 could change...
    890         self.run_cmd(argv=['atest', 'host', 'stat', 'ho*', 'newhost0',
    891                            '--ignore_site_file'],
    892                      rpcs=[('get_hosts', {'hostname': 'newhost0'},
    893                             True,
    894                             [{u'status': u'Ready',
    895                               u'hostname': u'newhost0',
    896                               u'locked': False,
    897                               u'locked_by': 'user0',
    898                               u'lock_time': u'2008-07-23 12:54:15',
    899                               u'lock_reason': u'',
    900                               u'protection': u'No protection',
    901                               u'labels': [u'label0', u'plat0'],
    902                               u'invalid': False,
    903                               u'synch_id': None,
    904                               u'platform': u'plat0',
    905                               u'id': 5,
    906                               u'attributes': {}}]),
    907                            ('get_hosts', {'hostname__startswith': 'ho'},
    908                             True,
    909                             [{u'status': u'Ready',
    910                               u'hostname': u'host1',
    911                               u'locked': True,
    912                               u'lock_time': u'2008-07-23 12:54:15',
    913                               u'locked_by': 'user0',
    914                               u'lock_reason': u'',
    915                               u'protection': 'No protection',
    916                               u'labels': [u'label3', u'label4', u'plat1'],
    917                               u'invalid': False,
    918                               u'synch_id': None,
    919                               u'platform': u'plat1',
    920                               u'id': 3,
    921                               u'attributes': {}},
    922                             {u'status': u'Ready',
    923                               u'hostname': u'host0',
    924                               u'locked': False,
    925                               u'locked_by': 'user0',
    926                               u'lock_reason': u'',
    927                               u'protection': 'No protection',
    928                               u'lock_time': u'2008-07-23 12:54:15',
    929                               u'labels': [u'label0', u'plat0'],
    930                               u'invalid': False,
    931                               u'synch_id': None,
    932                               u'platform': u'plat0',
    933                               u'id': 2,
    934                               u'attributes': {}}]),
    935                            ('get_acl_groups', {'hosts__hostname': 'newhost0'},
    936                             True,
    937                             [{u'description': u'',
    938                               u'hosts': [u'newhost0', 'host1'],
    939                               u'id': 42,
    940                               u'name': u'my_acl',
    941                               u'users': [u'user0', u'debug_user']},
    942                              {u'description': u'my favorite acl',
    943                               u'hosts': [u'newhost0'],
    944                               u'id': 2,
    945                               u'name': u'acl10',
    946                               u'users': [u'user0']}]),
    947                            ('get_labels', {'host__hostname': 'newhost0'},
    948                             True,
    949                             [{u'id': 4,
    950                               u'platform': 0,
    951                               u'name': u'label0',
    952                               u'invalid': False,
    953                               u'kernel_config': u''},
    954                              {u'id': 5,
    955                               u'platform': 1,
    956                               u'name': u'plat0',
    957                               u'invalid': False,
    958                               u'kernel_config': u''}]),
    959                            ('get_acl_groups', {'hosts__hostname': 'host1'},
    960                             True,
    961                             [{u'description': u'',
    962                               u'hosts': [u'host0', u'host1'],
    963                               u'id': 1,
    964                               u'name': u'Everyone',
    965                               u'users': [u'user2', u'debug_user', u'user0']}]),
    966                            ('get_labels', {'host__hostname': 'host1'},
    967                             True,
    968                             [{u'id': 2,
    969                               u'platform': 1,
    970                               u'name': u'jme',
    971                               u'invalid': False,
    972                               u'kernel_config': u''}]),
    973                            ('get_acl_groups', {'hosts__hostname': 'host0'},
    974                             True,
    975                             [{u'description': u'',
    976                               u'hosts': [u'host0', u'host1'],
    977                               u'id': 1,
    978                               u'name': u'Everyone',
    979                               u'users': [u'user0', u'debug_user']},
    980                              {u'description': u'myacl0',
    981                               u'hosts': [u'host0'],
    982                               u'id': 2,
    983                               u'name': u'acl0',
    984                               u'users': [u'user0']}]),
    985                            ('get_labels', {'host__hostname': 'host0'},
    986                             True,
    987                             [{u'id': 4,
    988                               u'platform': 0,
    989                               u'name': u'label0',
    990                               u'invalid': False,
    991                               u'kernel_config': u''},
    992                              {u'id': 5,
    993                               u'platform': 1,
    994                               u'name': u'plat0',
    995                               u'invalid': False,
    996                               u'kernel_config': u''}])],
    997                      out_words_ok=['host0', 'host1', 'newhost0',
    998                                    'plat0', 'plat1',
    999                                    'Everyone', 'acl10', 'label0'])
   1000 
   1001 
   1002 class host_jobs_unittest(cli_mock.cli_unittest):
   1003     def test_execute_jobs_one_host(self):
   1004         self.run_cmd(argv=['atest', 'host', 'jobs', 'host0',
   1005                            '--ignore_site_file'],
   1006                      rpcs=[('get_host_queue_entries',
   1007                             {'host__hostname': 'host0', 'query_limit': 20,
   1008                              'sort_by': ['-job__id']},
   1009                             True,
   1010                             [{u'status': u'Failed',
   1011                               u'complete': 1,
   1012                               u'host': {u'status': u'Ready',
   1013                                         u'locked': True,
   1014                                         u'locked_by': 'user0',
   1015                                         u'hostname': u'host0',
   1016                                         u'invalid': False,
   1017                                         u'id': 3232,
   1018                                         u'synch_id': None},
   1019                               u'priority': 0,
   1020                               u'meta_host': u'meta0',
   1021                               u'job': {u'control_file':
   1022                                        (u"def step_init():\n"
   1023                                         "\tjob.next_step([step_test])\n"
   1024                                         "\ttestkernel = job.kernel("
   1025                                         "'kernel-smp-2.6.xyz.x86_64.rpm')\n"
   1026                                         "\ttestkernel.install()\n"
   1027                                         "\ttestkernel.boot()\n\n"
   1028                                         "def step_test():\n"
   1029                                         "\tjob.run_test('kernbench')\n\n"),
   1030                                        u'name': u'kernel-smp-2.6.xyz.x86_64',
   1031                                        u'control_type': CLIENT,
   1032                                        u'synchronizing': None,
   1033                                        u'priority': u'Low',
   1034                                        u'owner': u'user0',
   1035                                        u'created_on': u'2008-01-09 10:45:12',
   1036                                        u'synch_count': None,
   1037                                        u'synch_type': u'Asynchronous',
   1038                                        u'id': 216},
   1039                                        u'active': 0,
   1040                                        u'id': 2981},
   1041                               {u'status': u'Aborted',
   1042                                u'complete': 1,
   1043                                u'host': {u'status': u'Ready',
   1044                                          u'locked': True,
   1045                                          u'locked_by': 'user0',
   1046                                          u'hostname': u'host0',
   1047                                          u'invalid': False,
   1048                                          u'id': 3232,
   1049                                          u'synch_id': None},
   1050                                u'priority': 0,
   1051                                u'meta_host': None,
   1052                                u'job': {u'control_file':
   1053                                         u"job.run_test('sleeptest')\n\n",
   1054                                         u'name': u'testjob',
   1055                                         u'control_type': CLIENT,
   1056                                         u'synchronizing': 0,
   1057                                         u'priority': u'Low',
   1058                                         u'owner': u'user1',
   1059                                         u'created_on': u'2008-01-17 15:04:53',
   1060                                         u'synch_count': None,
   1061                                         u'synch_type': u'Asynchronous',
   1062                                         u'id': 289},
   1063                                u'active': 0,
   1064                                u'id': 3167}])],
   1065                      out_words_ok=['216', 'user0', 'Failed',
   1066                                    'kernel-smp-2.6.xyz.x86_64', 'Aborted',
   1067                                    '289', 'user1', 'Aborted',
   1068                                    'testjob'])
   1069 
   1070 
   1071     def test_execute_jobs_wildcard(self):
   1072         self.run_cmd(argv=['atest', 'host', 'jobs', 'ho*',
   1073                            '--ignore_site_file'],
   1074                      rpcs=[('get_hosts', {'hostname__startswith': 'ho'},
   1075                             True,
   1076                             [{u'status': u'Ready',
   1077                               u'hostname': u'host1',
   1078                               u'locked': True,
   1079                               u'lock_time': u'2008-07-23 12:54:15',
   1080                               u'locked_by': 'user0',
   1081                               u'labels': [u'label3', u'label4', u'plat1'],
   1082                               u'invalid': False,
   1083                               u'synch_id': None,
   1084                               u'platform': u'plat1',
   1085                               u'id': 3},
   1086                             {u'status': u'Ready',
   1087                               u'hostname': u'host0',
   1088                               u'locked': False,
   1089                               u'locked_by': 'user0',
   1090                               u'lock_time': u'2008-07-23 12:54:15',
   1091                               u'labels': [u'label0', u'plat0'],
   1092                               u'invalid': False,
   1093                               u'synch_id': None,
   1094                               u'platform': u'plat0',
   1095                               u'id': 2}]),
   1096                            ('get_host_queue_entries',
   1097                             {'host__hostname': 'host1', 'query_limit': 20,
   1098                              'sort_by': ['-job__id']},
   1099                             True,
   1100                             [{u'status': u'Failed',
   1101                               u'complete': 1,
   1102                               u'host': {u'status': u'Ready',
   1103                                         u'locked': True,
   1104                                         u'locked_by': 'user0',
   1105                                         u'hostname': u'host1',
   1106                                         u'invalid': False,
   1107                                         u'id': 3232,
   1108                                         u'synch_id': None},
   1109                               u'priority': 0,
   1110                               u'meta_host': u'meta0',
   1111                               u'job': {u'control_file':
   1112                                        (u"def step_init():\n"
   1113                                         "\tjob.next_step([step_test])\n"
   1114                                         "\ttestkernel = job.kernel("
   1115                                         "'kernel-smp-2.6.xyz.x86_64.rpm')\n"
   1116                                         "\ttestkernel.install()\n"
   1117                                         "\ttestkernel.boot()\n\n"
   1118                                         "def step_test():\n"
   1119                                         "\tjob.run_test('kernbench')\n\n"),
   1120                                        u'name': u'kernel-smp-2.6.xyz.x86_64',
   1121                                        u'control_type': CLIENT,
   1122                                        u'synchronizing': None,
   1123                                        u'priority': u'Low',
   1124                                        u'owner': u'user0',
   1125                                        u'created_on': u'2008-01-09 10:45:12',
   1126                                        u'synch_count': None,
   1127                                        u'synch_type': u'Asynchronous',
   1128                                        u'id': 216},
   1129                                        u'active': 0,
   1130                                        u'id': 2981},
   1131                               {u'status': u'Aborted',
   1132                                u'complete': 1,
   1133                                u'host': {u'status': u'Ready',
   1134                                          u'locked': True,
   1135                                          u'locked_by': 'user0',
   1136                                          u'hostname': u'host1',
   1137                                          u'invalid': False,
   1138                                          u'id': 3232,
   1139                                          u'synch_id': None},
   1140                                u'priority': 0,
   1141                                u'meta_host': None,
   1142                                u'job': {u'control_file':
   1143                                         u"job.run_test('sleeptest')\n\n",
   1144                                         u'name': u'testjob',
   1145                                         u'control_type': CLIENT,
   1146                                         u'synchronizing': 0,
   1147                                         u'priority': u'Low',
   1148                                         u'owner': u'user1',
   1149                                         u'created_on': u'2008-01-17 15:04:53',
   1150                                         u'synch_count': None,
   1151                                         u'synch_type': u'Asynchronous',
   1152                                         u'id': 289},
   1153                                u'active': 0,
   1154                                u'id': 3167}]),
   1155                            ('get_host_queue_entries',
   1156                             {'host__hostname': 'host0', 'query_limit': 20,
   1157                              'sort_by': ['-job__id']},
   1158                             True,
   1159                             [{u'status': u'Failed',
   1160                               u'complete': 1,
   1161                               u'host': {u'status': u'Ready',
   1162                                         u'locked': True,
   1163                                         u'locked_by': 'user0',
   1164                                         u'hostname': u'host0',
   1165                                         u'invalid': False,
   1166                                         u'id': 3232,
   1167                                         u'synch_id': None},
   1168                               u'priority': 0,
   1169                               u'meta_host': u'meta0',
   1170                               u'job': {u'control_file':
   1171                                        (u"def step_init():\n"
   1172                                         "\tjob.next_step([step_test])\n"
   1173                                         "\ttestkernel = job.kernel("
   1174                                         "'kernel-smp-2.6.xyz.x86_64.rpm')\n"
   1175                                         "\ttestkernel.install()\n"
   1176                                         "\ttestkernel.boot()\n\n"
   1177                                         "def step_test():\n"
   1178                                         "\tjob.run_test('kernbench')\n\n"),
   1179                                        u'name': u'kernel-smp-2.6.xyz.x86_64',
   1180                                        u'control_type': CLIENT,
   1181                                        u'synchronizing': None,
   1182                                        u'priority': u'Low',
   1183                                        u'owner': u'user0',
   1184                                        u'created_on': u'2008-01-09 10:45:12',
   1185                                        u'synch_count': None,
   1186                                        u'synch_type': u'Asynchronous',
   1187                                        u'id': 216},
   1188                                        u'active': 0,
   1189                                        u'id': 2981},
   1190                               {u'status': u'Aborted',
   1191                                u'complete': 1,
   1192                                u'host': {u'status': u'Ready',
   1193                                          u'locked': True,
   1194                                          u'locked_by': 'user0',
   1195                                          u'hostname': u'host0',
   1196                                          u'invalid': False,
   1197                                          u'id': 3232,
   1198                                          u'synch_id': None},
   1199                                u'priority': 0,
   1200                                u'meta_host': None,
   1201                                u'job': {u'control_file':
   1202                                         u"job.run_test('sleeptest')\n\n",
   1203                                         u'name': u'testjob',
   1204                                         u'control_type': CLIENT,
   1205                                         u'synchronizing': 0,
   1206                                         u'priority': u'Low',
   1207                                         u'owner': u'user1',
   1208                                         u'created_on': u'2008-01-17 15:04:53',
   1209                                         u'synch_count': None,
   1210                                         u'synch_type': u'Asynchronous',
   1211                                         u'id': 289},
   1212                                u'active': 0,
   1213                                u'id': 3167}])],
   1214                      out_words_ok=['216', 'user0', 'Failed',
   1215                                    'kernel-smp-2.6.xyz.x86_64', 'Aborted',
   1216                                    '289', 'user1', 'Aborted',
   1217                                    'testjob'])
   1218 
   1219 
   1220     def test_execute_jobs_one_host_limit(self):
   1221         self.run_cmd(argv=['atest', 'host', 'jobs', 'host0',
   1222                            '--ignore_site_file', '-q', '10'],
   1223                      rpcs=[('get_host_queue_entries',
   1224                             {'host__hostname': 'host0', 'query_limit': 10,
   1225                              'sort_by': ['-job__id']},
   1226                             True,
   1227                             [{u'status': u'Failed',
   1228                               u'complete': 1,
   1229                               u'host': {u'status': u'Ready',
   1230                                         u'locked': True,
   1231                                         u'locked_by': 'user0',
   1232                                         u'hostname': u'host0',
   1233                                         u'invalid': False,
   1234                                         u'id': 3232,
   1235                                         u'synch_id': None},
   1236                               u'priority': 0,
   1237                               u'meta_host': u'meta0',
   1238                               u'job': {u'control_file':
   1239                                        (u"def step_init():\n"
   1240                                         "\tjob.next_step([step_test])\n"
   1241                                         "\ttestkernel = job.kernel("
   1242                                         "'kernel-smp-2.6.xyz.x86_64.rpm')\n"
   1243                                         "\ttestkernel.install()\n"
   1244                                         "\ttestkernel.boot()\n\n"
   1245                                         "def step_test():\n"
   1246                                         "\tjob.run_test('kernbench')\n\n"),
   1247                                        u'name': u'kernel-smp-2.6.xyz.x86_64',
   1248                                        u'control_type': CLIENT,
   1249                                        u'synchronizing': None,
   1250                                        u'priority': u'Low',
   1251                                        u'owner': u'user0',
   1252                                        u'created_on': u'2008-01-09 10:45:12',
   1253                                        u'synch_count': None,
   1254                                        u'synch_type': u'Asynchronous',
   1255                                        u'id': 216},
   1256                                        u'active': 0,
   1257                                        u'id': 2981},
   1258                               {u'status': u'Aborted',
   1259                                u'complete': 1,
   1260                                u'host': {u'status': u'Ready',
   1261                                          u'locked': True,
   1262                                          u'locked_by': 'user0',
   1263                                          u'hostname': u'host0',
   1264                                          u'invalid': False,
   1265                                          u'id': 3232,
   1266                                          u'synch_id': None},
   1267                                u'priority': 0,
   1268                                u'meta_host': None,
   1269                                u'job': {u'control_file':
   1270                                         u"job.run_test('sleeptest')\n\n",
   1271                                         u'name': u'testjob',
   1272                                         u'control_type': CLIENT,
   1273                                         u'synchronizing': 0,
   1274                                         u'priority': u'Low',
   1275                                         u'owner': u'user1',
   1276                                         u'created_on': u'2008-01-17 15:04:53',
   1277                                         u'synch_count': None,
   1278                                         u'synch_type': u'Asynchronous',
   1279                                         u'id': 289},
   1280                                u'active': 0,
   1281                                u'id': 3167}])],
   1282                      out_words_ok=['216', 'user0', 'Failed',
   1283                                    'kernel-smp-2.6.xyz.x86_64', 'Aborted',
   1284                                    '289', 'user1', 'Aborted',
   1285                                    'testjob'])
   1286 
   1287 
   1288 class host_mod_unittest(cli_mock.cli_unittest):
   1289     def test_execute_lock_one_host(self):
   1290         self.run_cmd(argv=['atest', 'host', 'mod',
   1291                            '--lock', 'host0', '--ignore_site_file'],
   1292                      rpcs=[('modify_host', {'id': 'host0', 'locked': True},
   1293                             True, None)],
   1294                      out_words_ok=['Locked', 'host0'])
   1295 
   1296 
   1297     def test_execute_unlock_two_hosts(self):
   1298         self.run_cmd(argv=['atest', 'host', 'mod',
   1299                            '-u', 'host0,host1', '--ignore_site_file'],
   1300                      rpcs=[('modify_host', {'id': 'host1', 'locked': False,
   1301                                             'lock_reason': ''},
   1302                             True, None),
   1303                            ('modify_host', {'id': 'host0', 'locked': False,
   1304                                             'lock_reason': ''},
   1305                             True, None)],
   1306                      out_words_ok=['Unlocked', 'host0', 'host1'])
   1307 
   1308 
   1309     def test_execute_force_lock_one_host(self):
   1310         self.run_cmd(argv=['atest', 'host', 'mod',
   1311                            '--lock', '--force_modify_locking', 'host0',
   1312                            '--ignore_site_file'],
   1313                      rpcs=[('modify_host',
   1314                             {'id': 'host0', 'locked': True,
   1315                              'force_modify_locking': True},
   1316                             True, None)],
   1317                      out_words_ok=['Locked', 'host0'])
   1318 
   1319 
   1320     def test_execute_force_unlock_one_host(self):
   1321         self.run_cmd(argv=['atest', 'host', 'mod',
   1322                            '--unlock', '--force_modify_locking', 'host0',
   1323                            '--ignore_site_file'],
   1324                      rpcs=[('modify_host',
   1325                             {'id': 'host0', 'locked': False,
   1326                              'force_modify_locking': True,
   1327                              'lock_reason': ''},
   1328                             True, None)],
   1329                      out_words_ok=['Unlocked', 'host0'])
   1330 
   1331 
   1332     def test_execute_lock_unknown_hosts(self):
   1333         self.run_cmd(argv=['atest', 'host', 'mod',
   1334                            '-l', 'host0,host1', 'host2', '--ignore_site_file'],
   1335                      rpcs=[('modify_host', {'id': 'host2', 'locked': True},
   1336                             True, None),
   1337                            ('modify_host', {'id': 'host1', 'locked': True},
   1338                             False, 'DoesNotExist: Host matching '
   1339                             'query does not exist.'),
   1340                            ('modify_host', {'id': 'host0', 'locked': True},
   1341                             True, None)],
   1342                      out_words_ok=['Locked', 'host0', 'host2'],
   1343                      err_words_ok=['Host', 'matching', 'query', 'host1'])
   1344 
   1345 
   1346     def test_execute_protection_hosts(self):
   1347         mfile = cli_mock.create_file('host0\nhost1,host2\nhost3 host4')
   1348         self.run_cmd(argv=['atest', 'host', 'mod', '--protection',
   1349                            'Do not repair',
   1350                            'host5' ,'--mlist', mfile.name, 'host1', 'host6',
   1351                            '--ignore_site_file'],
   1352                      rpcs=[('modify_host', {'id': 'host6',
   1353                                             'protection': 'Do not repair'},
   1354                             True, None),
   1355                            ('modify_host', {'id': 'host5',
   1356                                             'protection': 'Do not repair'},
   1357                             True, None),
   1358                            ('modify_host', {'id': 'host4',
   1359                                             'protection': 'Do not repair'},
   1360                             True, None),
   1361                            ('modify_host', {'id': 'host3',
   1362                                             'protection': 'Do not repair'},
   1363                             True, None),
   1364                            ('modify_host', {'id': 'host2',
   1365                                             'protection': 'Do not repair'},
   1366                             True, None),
   1367                            ('modify_host', {'id': 'host1',
   1368                                             'protection': 'Do not repair'},
   1369                             True, None),
   1370                            ('modify_host', {'id': 'host0',
   1371                                             'protection': 'Do not repair'},
   1372                             True, None)],
   1373                      out_words_ok=['Do not repair', 'host0', 'host1', 'host2',
   1374                                    'host3', 'host4', 'host5', 'host6'])
   1375         mfile.clean()
   1376 
   1377 
   1378 
   1379 class host_create_unittest(cli_mock.cli_unittest):
   1380     def test_execute_create_muliple_hosts_all_options(self):
   1381         self.run_cmd(argv=['atest', 'host', 'create', '--lock',
   1382                            '-b', 'label0', '--acls', 'acl0', 'host0', 'host1',
   1383                            '--ignore_site_file'],
   1384                      rpcs=[('get_labels', {'name': 'label0'},
   1385                             True,
   1386                             [{u'id': 4,
   1387                               u'platform': 0,
   1388                               u'name': u'label0',
   1389                               u'invalid': False,
   1390                               u'kernel_config': u''}]),
   1391                            ('get_acl_groups', {'name': 'acl0'},
   1392                             True, []),
   1393                            ('add_acl_group', {'name': 'acl0'},
   1394                             True, 5),
   1395                            ('add_host', {'hostname': 'host1',
   1396                                          'status': 'Ready',
   1397                                          'locked': True},
   1398                             True, 42),
   1399                            ('host_add_labels', {'id': 'host1',
   1400                                                 'labels': ['label0']},
   1401                             True, None),
   1402                            ('add_host', {'hostname': 'host0',
   1403                                          'status': 'Ready',
   1404                                          'locked': True},
   1405                             True, 42),
   1406                            ('host_add_labels', {'id': 'host0',
   1407                                                 'labels': ['label0']},
   1408                             True, None),
   1409                            ('acl_group_add_hosts',
   1410                             {'id': 'acl0', 'hosts': ['host1', 'host0']},
   1411                             True, None)],
   1412                      out_words_ok=['host0', 'host1'])
   1413 
   1414 
   1415     def test_execute_create_muliple_hosts_unlocked(self):
   1416         self.run_cmd(argv=['atest', 'host', 'create',
   1417                            '-b', 'label0', '--acls', 'acl0', 'host0', 'host1',
   1418                            '--ignore_site_file'],
   1419                      rpcs=[('get_labels', {'name': 'label0'},
   1420                             True,
   1421                             [{u'id': 4,
   1422                               u'platform': 0,
   1423                               u'name': u'label0',
   1424                               u'invalid': False,
   1425                               u'kernel_config': u''}]),
   1426                            ('get_acl_groups', {'name': 'acl0'},
   1427                             True, []),
   1428                            ('add_acl_group', {'name': 'acl0'},
   1429                             True, 5),
   1430                            ('add_host', {'hostname': 'host1',
   1431                                          'status': 'Ready',
   1432                                          'locked': True,
   1433                                          'lock_reason': 'Forced lock on device creation'},
   1434                             True, 42),
   1435                            ('host_add_labels', {'id': 'host1',
   1436                                                 'labels': ['label0']},
   1437                             True, None),
   1438                            ('add_host', {'hostname': 'host0',
   1439                                          'status': 'Ready',
   1440                                          'locked': True,
   1441                                          'lock_reason': 'Forced lock on device creation'},
   1442                             True, 42),
   1443                            ('host_add_labels', {'id': 'host0',
   1444                                                 'labels': ['label0']},
   1445                             True, None),
   1446                            ('acl_group_add_hosts',
   1447                             {'id': 'acl0', 'hosts': ['host1', 'host0']},
   1448                             True, None),
   1449                            ('modify_host', {'id': 'host1', 'locked': False,
   1450                                             'lock_reason': ''},
   1451                             True, None),
   1452                            ('modify_host', {'id': 'host0', 'locked': False,
   1453                                             'lock_reason': ''},
   1454                             True, None)],
   1455                      out_words_ok=['host0', 'host1'])
   1456 
   1457 
   1458     def test_execute_create_muliple_hosts_label_escaped_quotes(self):
   1459         self.run_cmd(argv=['atest', 'host', 'create',
   1460                            '-b', 'label0,label\\,1,label\\,2',
   1461                            '--acls', 'acl0', 'host0', 'host1',
   1462                            '--ignore_site_file'],
   1463                      rpcs=[('get_labels', {'name': 'label0'},
   1464                             True,
   1465                             [{u'id': 4,
   1466                               u'platform': 0,
   1467                               u'name': u'label0',
   1468                               u'invalid': False,
   1469                               u'kernel_config': u''}]),
   1470                            ('get_labels', {'name': 'label,1'},
   1471                             True,
   1472                             [{u'id': 4,
   1473                               u'platform': 0,
   1474                               u'name': u'label,1',
   1475                               u'invalid': False,
   1476                               u'kernel_config': u''}]),
   1477                            ('get_labels', {'name': 'label,2'},
   1478                             True,
   1479                             [{u'id': 4,
   1480                               u'platform': 0,
   1481                               u'name': u'label,2',
   1482                               u'invalid': False,
   1483                               u'kernel_config': u''}]),
   1484                            ('get_acl_groups', {'name': 'acl0'},
   1485                             True, []),
   1486                            ('add_acl_group', {'name': 'acl0'},
   1487                             True, 5),
   1488                            ('add_host', {'hostname': 'host1',
   1489                                          'status': 'Ready',
   1490                                          'locked': True,
   1491                                          'lock_reason': 'Forced lock on device creation'},
   1492                             True, 42),
   1493                            ('host_add_labels', {'id': 'host1',
   1494                                                 'labels': ['label0', 'label,1',
   1495                                                            'label,2']},
   1496                             True, None),
   1497                            ('add_host', {'hostname': 'host0',
   1498                                          'status': 'Ready',
   1499                                          'locked': True,
   1500                                          'lock_reason': 'Forced lock on device creation'},
   1501                             True, 42),
   1502                            ('host_add_labels', {'id': 'host0',
   1503                                                 'labels': ['label0', 'label,1',
   1504                                                            'label,2']},
   1505                             True, None),
   1506                            ('acl_group_add_hosts',
   1507                             {'id': 'acl0', 'hosts': ['host1', 'host0']},
   1508                             True, None),
   1509                            ('modify_host', {'id': 'host1', 'locked': False,
   1510                                             'lock_reason': ''},
   1511                             True, None),
   1512                            ('modify_host', {'id': 'host0', 'locked': False,
   1513                                             'lock_reason': ''},
   1514                             True, None)],
   1515                      out_words_ok=['host0', 'host1'])
   1516 
   1517 
   1518 if __name__ == '__main__':
   1519     unittest.main()
   1520