Add --noop to the command: fuel node

Related-Bug: #1617993
Change-Id: Ib514888614f40fa91cc2525995371135ed7501e7
(cherry picked from commit d50113a78e)
This commit is contained in:
Anastasiia Guzikova 2016-09-05 20:43:18 +03:00 committed by Ivan Berezovskiy
parent 7b9c422223
commit b544c5a410
3 changed files with 21 additions and 4 deletions

View File

@ -65,6 +65,7 @@ class NodeAction(Action):
"Select directory to which download node attributes"),
Args.get_node_arg("Node id."),
Args.get_force_arg("Bypassing parameter validation."),
Args.get_noop_run_deployment_arg(),
Args.get_all_arg("Select all nodes."),
Args.get_role_arg("Role to assign for node."),
group(
@ -268,6 +269,7 @@ class NodeAction(Action):
tasks = params.tasks or None
force = params.force or None
noop_run = params.noop_run or None
if params.skip or params.end or params.start:
tasks = env.get_tasks(
@ -281,7 +283,8 @@ class NodeAction(Action):
return
task = env.execute_tasks(
node_collection.collection, tasks=tasks, force=force)
node_collection.collection, tasks=tasks, force=force,
noop_run=noop_run)
self.serializer.print_to_output(
task.data,

View File

@ -466,7 +466,7 @@ class Environment(BaseObject):
)
)
def _get_method_url(self, method_type, nodes, force=False):
def _get_method_url(self, method_type, nodes, force=False, noop_run=False):
endpoint = "clusters/{0}/{1}/?nodes={2}".format(
self.id,
method_type,
@ -474,6 +474,8 @@ class Environment(BaseObject):
if force:
endpoint += '&force=1'
if noop_run:
endpoint += '&noop_run=1'
return endpoint
@ -485,10 +487,11 @@ class Environment(BaseObject):
)
)
def execute_tasks(self, nodes, tasks, force):
def execute_tasks(self, nodes, tasks, force, noop_run):
return Task.init_with_data(
self.connection.put_request(
self._get_method_url('deploy_tasks', nodes=nodes, force=force),
self._get_method_url('deploy_tasks', nodes=nodes, force=force,
noop_run=noop_run),
tasks
)
)

View File

@ -52,6 +52,17 @@ class TestNodeExecuteTasksAction(base.UnitTestCase):
'&force=1')
self.assertEqual(put.last_request.json(), self.tasks)
def test_execute_provided_list_of_tasks_noop_run(self):
put = self.m_request.put(rm.ANY, json={'id': 43})
self.execute((['fuel', 'node', '--node', '1,2', '--tasks']
+ self.tasks + ['--noop']))
self.assertEqual(
put.last_request.url,
'http://127.0.0.1:8000/api/v1/clusters/1/deploy_tasks/?nodes=1,2'
'&noop_run=1')
self.assertEqual(put.last_request.json(), self.tasks)
@patch('fuelclient.objects.environment.Environment.get_deployment_tasks')
def test_skipped_tasks(self, get_tasks):
get_tasks.return_value = [{'id': t} for t in self.tasks]