1# pylint: disable-msg=C0111 2#!/usr/bin/python 3# 4# Copyright 2008 Google Inc. All Rights Reserved. 5 6"""Tests for shard.""" 7 8import unittest 9 10import common 11from autotest_lib.cli import cli_mock 12 13 14class shard_list_unittest(cli_mock.cli_unittest): 15 values = [{'hostname': u'shard1', u'id': 1, 'labels': ['board:lumpy']}, 16 {'hostname': u'shard2', u'id': 3, 'labels': ['board:daisy']}, 17 {'hostname': u'shard3', u'id': 5, 'labels': ['board:stumpy']}, 18 {'hostname': u'shard4', u'id': 6, 'labels': ['board:link']}] 19 20 21 def test_shard_list(self): 22 self.run_cmd(argv=['atest', 'shard', 'list'], 23 rpcs=[('get_shards', {}, True, self.values)], 24 out_words_ok=['shard1', 'shard2', 'shard3', 'shard4'], 25 out_words_no=['plat0', 'plat1']) 26 27 28class shard_create_unittest(cli_mock.cli_unittest): 29 def test_execute_create_two_shards(self): 30 self.run_cmd(argv=['atest', 'shard', 'create', 31 '-l', 'board:lumpy', 'shard0'], 32 rpcs=[('add_shard', 33 {'hostname': 'shard0', 'labels': 'board:lumpy'}, 34 True, 42)], 35 out_words_ok=['Created', 'shard0']) 36 37 38 def test_execute_create_two_shards_bad(self): 39 self.run_cmd(argv=['atest', 'shard', 'create', 40 '-l', 'board:lumpy', 'shard0'], 41 rpcs=[('add_shard', 42 {'hostname': 'shard0', 'labels': 'board:lumpy'}, 43 False, 44 '''ValidationError: {'name': 45 'This value must be unique (shard1)'}''')], 46 out_words_no=['shard0'], 47 err_words_ok=['shard0', 'ValidationError']) 48 49 50class shard_delete_unittest(cli_mock.cli_unittest): 51 def test_execute_delete_shards(self): 52 self.run_cmd(argv=['atest', 'shard', 'delete', 53 'shard0', 'shard1', '--no-confirmation'], 54 rpcs=[('delete_shard', {'hostname': 'shard0'}, True, None), 55 ('delete_shard', {'hostname': 'shard1'}, True, None) 56 ], 57 out_words_ok=['Deleted', 'shard0', 'shard1']) 58 59 60if __name__ == '__main__': 61 unittest.main() 62