diff --git a/saharaclient/osc/v1/jobs.py b/saharaclient/osc/v1/jobs.py index 4c50e52d..d52ce70d 100644 --- a/saharaclient/osc/v1/jobs.py +++ b/saharaclient/osc/v1/jobs.py @@ -174,11 +174,16 @@ class ExecuteJob(command.ShowOne): client.jobs, parsed_args.job_template) cluster_id = utils.get_resource_id( client.clusters, parsed_args.cluster) - - input_id = utils.get_resource_id( - client.data_sources, parsed_args.input) - output_id = utils.get_resource_id( - client.data_sources, parsed_args.output) + if parsed_args.input not in [None, "", "None"]: + input_id = utils.get_resource_id( + client.data_sources, parsed_args.input) + else: + input_id = None + if parsed_args.output not in [None, "", "None"]: + output_id = utils.get_resource_id( + client.data_sources, parsed_args.output) + else: + output_id = None data = client.job_executions.create( job_id=jt_id, cluster_id=cluster_id, input_id=input_id, diff --git a/saharaclient/tests/unit/osc/v1/test_jobs.py b/saharaclient/tests/unit/osc/v1/test_jobs.py index edbead9e..6beaa155 100644 --- a/saharaclient/tests/unit/osc/v1/test_jobs.py +++ b/saharaclient/tests/unit/osc/v1/test_jobs.py @@ -88,11 +88,54 @@ class TestExecuteJob(TestJobs): self.cmd.take_action(parsed_args) # Check that correct arguments were passed + self.je_mock.create.assert_called_once_with( + cluster_id='cluster_id', configs={}, input_id=None, + interface=None, is_protected=False, is_public=False, + job_id='job_id', output_id=None) + + def test_job_execute_with_input_output_option(self): + arglist = ['--job-template', 'job-template', '--cluster', 'cluster', + '--input', 'input', '--output', 'output'] + verifylist = [('job_template', 'job-template'), ('cluster', 'cluster'), + ('input', 'input'), ('output', 'output')] + + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + self.cmd.take_action(parsed_args) + self.je_mock.create.assert_called_once_with( cluster_id='cluster_id', configs={}, input_id='ds_id', interface=None, is_protected=False, is_public=False, job_id='job_id', output_id='ds_id') + # without option --output + arglist = ['--job-template', 'job-template', '--cluster', 'cluster', + '--input', 'input'] + verifylist = [('job_template', 'job-template'), ('cluster', 'cluster'), + ('input', 'input')] + + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + self.cmd.take_action(parsed_args) + + self.je_mock.create.assert_called_with( + cluster_id='cluster_id', configs={}, input_id='ds_id', + interface=None, is_protected=False, is_public=False, + job_id='job_id', output_id=None) + + # without options --output and --input + arglist = ['--job-template', 'job-template', '--cluster', 'cluster'] + verifylist = [('job_template', 'job-template'), ('cluster', 'cluster')] + + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + self.cmd.take_action(parsed_args) + + self.je_mock.create.assert_called_with( + cluster_id='cluster_id', configs={}, input_id=None, + interface=None, is_protected=False, is_public=False, + job_id='job_id', output_id=None) + def test_job_execute_all_options(self): arglist = ['--job-template', 'job-template', '--cluster', 'cluster', '--input', 'input', '--output', 'output', '--params',