Added --hostless option to job create + few checks for parameters
incosistency (hostless implies no hosts, synch count labels etc)
and some unit tests.
---
 cli/job.py          |   29 ++++++++++++++++++++++-------
 cli/job_unittest.py |   28 ++++++++++++++++++++++++++++
 2 files changed, 50 insertions(+), 7 deletions(-)

diff --git a/cli/job.py b/cli/job.py
index 1702805..ad18525 100644
--- a/cli/job.py
+++ b/cli/job.py
@@ -445,6 +445,9 @@ class job_create(job_create_or_clone):
                                metavar='TIMEOUT')
         self.parser.add_option('--max_runtime',
                                help='Job maximum runtime in hours')
+        self.parser.add_option('--hostless',
+                               help='Specify a hostless job',
+                               action='store_true', default=False)
 
 
     def _get_kernel_data(self, kernel_list, cmdline, config_list=None):
@@ -498,11 +501,20 @@ class job_create(job_create_or_clone):
         options, leftover = super(job_create, self).parse(
                 parse_info=[deps_info])
 
-        if (len(self.hosts) == 0 and not self.one_time_hosts
-            and not options.labels and not options.atomic_group):
-            self.invalid_syntax('Must specify at least one machine '
-                                'or an atomic group '
-                                '(-m, -M, -b, -G or --one-time-hosts).')
+        if options.hostless:
+            if (self.hosts or self.one_time_hosts
+                or options.labels or options.atomic_group
+                or options.synch_count):
+                self.invalid_syntax('If hostless is specified cannot specify'
+                                    ' machine, atomic group or synch count'
+                                    ' (-m, -M, -b, -G, --synch_count')
+        else:
+            if (len(self.hosts) == 0 and not self.one_time_hosts
+                and not options.labels and not options.atomic_group):
+                self.invalid_syntax('Must specify at least one machine, '
+                                'atomic group or hostless'
+                                '(-m, -M, -b, -G, --one-time-hosts '
+                                'or hostless).')
         if not options.control_file and not options.test:
             self.invalid_syntax('Must specify either --test or --control-file'
                                 ' to create a job.')
@@ -565,6 +577,9 @@ class job_create(job_create_or_clone):
         else:
             self.data['control_type'] = 'Client'
 
+        if options.hostless:
+            self.data['hostless'] = True
+
         return options, leftover
 
 
@@ -599,9 +614,9 @@ class job_create(job_create_or_clone):
             deps = sorted(deps.union(cf_info['dependencies']))
             self.data['dependencies'] = list(deps)
 
-        if 'synch_count' not in self.data:
+        if 'synch_count' not in self.data and 'hostless' not in self.data:
             self.data['synch_count'] = 1
-
+                    
         return self.create_job()
 
 
diff --git a/cli/job_unittest.py b/cli/job_unittest.py
index 5981c6f..982effd 100755
--- a/cli/job_unittest.py
+++ b/cli/job_unittest.py
@@ -1370,6 +1370,34 @@ class job_create_unittest(cli_mock.cli_unittest):
         self.assertEqual(testjob.failed['Failed to find labels'],
                          {'No labels matching <XYZ>': set(['label*'])})
 
+    def test_execute_create_job_hostless(self):
+        data = self.data.copy()
+        data['hostless'] = True
+        data['hosts'] = []
+        data['control_type'] = 'Server'
+        del data['synch_count']
+        file_temp = cli_mock.create_file(self.ctrl_file)
+        self.run_cmd(argv=['atest', 'job', 'create', '-s', '-f', 
file_temp.name,
+                           '--hostless', 'test_job0'],
+                     rpcs=[('create_job', data, True, 42)],
+                     out_words_ok=['test_job0', 'Created'],)
+        file_temp.clean()
+
+    def test_execute_create_job_hostless_bad_args_hosts(self):
+        testjob = job.job_create()
+        file_temp = cli_mock.create_file(self.ctrl_file)
+        sys.argv = ['atest', 'job', 'create', '--hostless', 
+                    '-s', '-f', file_temp.name,
+                    '-m', 'myhost', 
+                    'test_hosteless_job0']
+        self.god.mock_io()
+        (sys.exit.expect_call(mock.anything_comparator())
+         .and_raises(cli_mock.ExitException))
+        self.assertRaises(cli_mock.ExitException, testjob.parse)
+        self.god.unmock_io()
+        self.god.check_playback()
+        file_temp.clean()
+
 
 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',
-- 
1.7.7.6

_______________________________________________
Autotest-kernel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/autotest-kernel

Reply via email to