When user specifies "job create ... -m 2*group* ..." it will expand to scheduling job with all maching labels (e.g. group1, group2, group3); This is applicable to all labels (not just platform)
Signed-off-by: Julius Gawlas <[email protected]> --- cli/job.py | 21 ++++++++++++++++++--- cli/job_unittest.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/cli/job.py b/cli/job.py index d8fa6ad..1702805 100644 --- a/cli/job.py +++ b/cli/job.py @@ -275,6 +275,21 @@ class job_create_or_clone(action_common.atest_create, job): 'email addresses to notify of job completion', default='') + def _parse_meta_host_labels(self, label): + """Parse the label part of the meta_host definition + if it has a wild card it gets expanded into a list + of all matching labels, e.g.: 2*label* becomes + 2*label1 2*label2 2*label3 + """ + if label.endswith('*'): + labels = self.execute_rpc('get_labels', + name__startswith=label.rstrip('*')) + if len(labels) == 0: + self.failure('No labels matching %s' % label, item=label, + what_failed='Failed to find labels') + return [l['name'] for l in labels] + else: + return [label] def _parse_hosts(self, args): """ Parses the arguments to generate a list of hosts and meta_hosts @@ -289,16 +304,16 @@ class job_create_or_clone(action_common.atest_create, job): for host in arg.split(','): if re.match('^[0-9]+[*]', host): num, host = host.split('*', 1) - meta_hosts += int(num) * [host] + meta_hosts += int(num) * self._parse_meta_host_labels(host) elif re.match('^[*](\w*)', host): - meta_hosts += [re.match('^[*](\w*)', host).group(1)] + meta_hosts += self._parse_meta_host_labels( + re.match('^[*](\w*)', host).group(1)) elif host != '' and host not in hosts: # Real hostname and not a duplicate hosts.append(host) return (hosts, meta_hosts) - def parse(self, parse_info=[]): host_info = topic_common.item_parse_info(attribute_name='hosts', inline_option='machine', diff --git a/cli/job_unittest.py b/cli/job_unittest.py index d08be16..462ba0f 100755 --- a/cli/job_unittest.py +++ b/cli/job_unittest.py @@ -1342,6 +1342,35 @@ class job_create_unittest(cli_mock.cli_unittest): ['meta0']*5 + ['meta1']*2 + ['meta2']) + def test_parse_hosts_metas_labels_wildcards(self): + values = [{u'id': 180, + u'platform': False, + u'name': u'label0', + u'invalid': False, + u'kernel_config': u''}, + {u'id': 338, + u'platform': False, + u'name': u'label1', + u'invalid': False, + u'kernel_config': u''}] + testjob = job.job_create_or_clone() + testjob.afe = rpc.afe_comm() + self.mock_rpcs([('get_labels', {'name__startswith': 'label'}, + True, values)]) + (unused_hosts, meta_hosts) = testjob._parse_hosts(['3*label*']) + self.assertEqualNoOrder(meta_hosts, ['label0'] * 3 + ['label1'] * 3) + + + def test_parse_hosts_metas_labels_wildcards_not_found(self): + testjob = job.job_create_or_clone() + testjob.afe = rpc.afe_comm() + self.mock_rpcs([('get_labels', {'name__startswith': 'label'}, + True, [])]) + testjob._parse_hosts(['3*label*']) + self.assertEqual(testjob.failed['Failed to find labels'], + {'No labels matching <XYZ>': set(['label*'])}) + + class job_clone_unittest(cli_mock.cli_unittest): job_data = {'control_file': u'NAME = \'Server Sleeptest\'\nAUTHOR = \'[email protected] (Martin Bligh)\'\nTIME = \'SHORT\'\nTEST_CLASS = \'Software\'\nTEST_CATEGORY = \'Functional\'\nTEST_TYPE = \'server\'\nEXPERIMENTAL = \'False\'\n\nDOC = """\nruns sleep for one second on the list of machines.\n"""\n\ndef run(machine):\n host = hosts.create_host(machine)\n job.run_test(\'sleeptest\')\n\njob.parallel_simple(run, machines)\n', 'control_type': u'Server', -- 1.7.7.6 _______________________________________________ Autotest-kernel mailing list [email protected] https://www.redhat.com/mailman/listinfo/autotest-kernel
