diff options
author | mbligh <mbligh@592f7852-d20e-0410-864c-8624ca9c26a4> | 2008-10-27 20:55:13 +0000 |
---|---|---|
committer | mbligh <mbligh@592f7852-d20e-0410-864c-8624ca9c26a4> | 2008-10-27 20:55:13 +0000 |
commit | ccf480a681d45cb24d6aaae5db0c906b2300688c (patch) | |
tree | a05771ccf929deb63e73da452def9461f204615d /cli | |
parent | fc83ef41b529daeeba68411844bd197adc6449ad (diff) |
Add the filtering on multiple labels.
Signed-off-by: Jean-Marc Eurin <jmeurin@google.com>
git-svn-id: svn://test.kernel.org/autotest/trunk@2345 592f7852-d20e-0410-864c-8624ca9c26a4
Diffstat (limited to 'cli')
-rwxr-xr-x | cli/host.py | 30 | ||||
-rwxr-xr-x | cli/host_unittest.py | 97 |
2 files changed, 115 insertions, 12 deletions
diff --git a/cli/host.py b/cli/host.py index a9483e1c..a3bc5793 100755 --- a/cli/host.py +++ b/cli/host.py @@ -106,19 +106,25 @@ class host_list(action_common.atest_list, host): super(host_list, self).__init__() self.parser.add_option('-b', '--label', - help='Only list hosts with this label') + default='', + help='Only list hosts with all these labels ' + '(comma separated)') self.parser.add_option('-s', '--status', - help='Only list hosts with this status') + default='', + help='Only list hosts with any of these ' + 'statuses (comma separated)') self.parser.add_option('-a', '--acl', + default='', help='Only list hosts within this ACL') self.parser.add_option('-u', '--user', + default='', help='Only list hosts available to this user') def parse(self): """Consume the specific options""" (options, leftover) = super(host_list, self).parse(req_items=None) - self.label = options.label + self.labels = options.label self.status = options.status self.acl = options.acl self.user = options.user @@ -131,12 +137,22 @@ class host_list(action_common.atest_list, host): if self.hosts: filters['hostname__in'] = self.hosts check_results['hostname__in'] = 'hostname' - if self.label: - filters['labels__name'] = self.label - check_results['labels__name'] = None + + if self.labels: + labels = self.labels.split(',') + labels = [label.strip() for label in labels if label.strip()] + + filters['multiple_labels'] = labels + check_results['multiple_labels'] = None + if self.status: - filters['status__in'] = self.status.split(',') + statuses = self.status.split(',') + statuses = [status.strip() for status in statuses + if status.strip()] + + filters['status__in'] = statuses check_results['status__in'] = None + if self.acl: filters['acl_group__name'] = self.acl check_results['acl_group__name'] = None diff --git a/cli/host_unittest.py b/cli/host_unittest.py index e06bbd50..5af8bece 100755 --- a/cli/host_unittest.py +++ b/cli/host_unittest.py @@ -69,7 +69,15 @@ class host_list_unittest(cli_mock.cli_unittest): hl = host.host_list() sys.argv = ['atest', '--label', 'label0'] (options, leftover) = hl.parse() - self.assertEqual('label0', hl.label) + self.assertEqual('label0', hl.labels) + self.assertEqual(leftover, []) + + + def test_parse_with_multi_labels(self): + hl = host.host_list() + sys.argv = ['atest', '--label', 'label0,label2'] + (options, leftover) = hl.parse() + self.assertEqual('label0,label2', hl.labels) self.assertEqual(leftover, []) @@ -81,7 +89,7 @@ class host_list_unittest(cli_mock.cli_unittest): (options, leftover) = hl.parse() self.assertEqualNoOrder(['host0', 'host1','host3', 'host4'], hl.hosts) - self.assertEqual('label0', hl.label) + self.assertEqual('label0', hl.labels) self.assertEqual(leftover, []) @@ -234,7 +242,7 @@ class host_list_unittest(cli_mock.cli_unittest): def test_execute_list_filter_label(self): self.run_cmd(argv=['atest', 'host', 'list', '-b', 'label3', '--ignore_site_file'], - rpcs=[('get_hosts', {'labels__name': 'label3'}, + rpcs=[('get_hosts', {'multiple_labels': ['label3']}, True, [{u'status': u'Ready', u'hostname': u'host1', @@ -262,11 +270,77 @@ class host_list_unittest(cli_mock.cli_unittest): out_words_no=['host0', 'label1', 'False']) + def test_execute_list_filter_multi_labels(self): + self.run_cmd(argv=['atest', 'host', 'list', + '-b', 'label3,label2', '--ignore_site_file'], + rpcs=[('get_hosts', {'multiple_labels': ['label3', + 'label2']}, + True, + [{u'status': u'Ready', + u'hostname': u'host1', + u'locked': 1, + u'locked_by': 'user0', + u'lock_time': u'2008-07-23 12:54:15', + u'labels': [u'label2', u'label3', u'plat0'], + u'invalid': 0, + u'synch_id': None, + u'platform': u'plat0', + u'id': 2}, + {u'status': u'Ready', + u'hostname': u'host3', + u'locked': 1, + u'locked_by': 'user0', + u'lock_time': u'2008-07-23 12:54:15', + u'labels': [u'label3', u'label2', u'plat2'], + u'invalid': 0, + u'synch_id': None, + u'platform': u'plat2', + u'id': 4}])], + out_words_ok=['host1', 'host3', 'Ready', 'plat0', + 'label2', 'label3', 'plat2'], + out_words_no=['host2', 'label4', 'False', 'plat1']) + + + def test_execute_list_filter_three_labels(self): + self.run_cmd(argv=['atest', 'host', 'list', + '-b', 'label3,label2, label4', + '--ignore_site_file'], + rpcs=[('get_hosts', {'multiple_labels': ['label3', + 'label2', + 'label4']}, + True, + [{u'status': u'Ready', + u'hostname': u'host2', + u'locked': 1, + u'locked_by': 'user0', + u'lock_time': u'2008-07-23 12:54:15', + u'labels': [u'label3', u'label2', u'label4', + u'plat1'], + u'invalid': 0, + u'synch_id': None, + u'platform': u'plat1', + u'id': 3}])], + out_words_ok=['host2', 'plat1', + 'label2', 'label3', 'label4'], + out_words_no=['host1', 'host3']) + + + def test_execute_list_filter_multi_labels_no_results(self): + self.run_cmd(argv=['atest', 'host', 'list', + '-b', 'label3,label2, ', '--ignore_site_file'], + rpcs=[('get_hosts', {'multiple_labels': ['label3', + 'label2']}, + True, + [])], + out_words_ok=[], + out_words_no=['host1', 'host2', 'host3', + 'label2', 'label3', 'label4']) + def test_execute_list_filter_label_and_hosts(self): self.run_cmd(argv=['atest', 'host', 'list', 'host1', '-b', 'label3', 'host2', '--ignore_site_file'], - rpcs=[('get_hosts', {'labels__name': 'label3', + rpcs=[('get_hosts', {'multiple_labels': ['label3'], 'hostname__in': ['host2', 'host1']}, True, [{u'status': u'Ready', @@ -298,7 +372,7 @@ class host_list_unittest(cli_mock.cli_unittest): def test_execute_list_filter_label_and_hosts_none(self): self.run_cmd(argv=['atest', 'host', 'list', 'host1', '-b', 'label3', 'host2', '--ignore_site_file'], - rpcs=[('get_hosts', {'labels__name': 'label3', + rpcs=[('get_hosts', {'multiple_labels': ['label3'], 'hostname__in': ['host2', 'host1']}, True, [])], @@ -384,6 +458,19 @@ class host_list_unittest(cli_mock.cli_unittest): err_words_ok=['Unknown', 'host2']) + def test_execute_list_filter_statuses_and_hosts_none(self): + self.run_cmd(argv=['atest', 'host', 'list', 'host1', + '--status', 'Repair, Dead', + 'host2', '--ignore_site_file'], + rpcs=[('get_hosts', {'status__in': ['Repair', 'Dead'], + 'hostname__in': ['host2', 'host1']}, + True, + [])], + out_words_ok=['No', 'results'], + out_words_no=['Hostname', 'Status'], + err_words_ok=['Unknown', 'host2']) + + class host_stat_unittest(cli_mock.cli_unittest): def test_execute_stat_two_hosts(self): # The order of RPCs between host1 and host0 could change... |