Fix a bug in jobs.py

When I used command "dataprocessing job execute", the option
--input and --output must be defined otherwise I can't excute job.
Because it alwalys return error_code 404. Acutually, we can use
option --args to appoint input_url and output_url.So I think
--input and --output should be optional.
add:
    test_job_execute_with_input_output_option()
Closes-Bug: #1670227

Change-Id: Ia2d3a19658ad78f7c07f444131dddf836bb8018e
This commit is contained in:
jiasen.lin 2017-03-19 21:22:43 +08:00
parent fb803225f3
commit 378490d44d
2 changed files with 53 additions and 5 deletions

View File

@ -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,

View File

@ -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',