Noop run support

Specify any set of tasks, nodes or cluster where to run Noop with
--noop option.

Implements blueprint: puppet-noop-run

Depends-on: 8f7fbaee723974dff3d5313ccd486d2dc8475781

Change-Id: I6c1ad22cdabfd3ff8028e5fa2788f30a1063c041
This commit is contained in:
Anastasiia Guzikova 2016-08-19 14:35:07 +03:00
parent 8c6c386133
commit c6a6c1f961
11 changed files with 137 additions and 20 deletions

View File

@ -266,6 +266,15 @@ def get_dry_run_deployment_arg():
"to dump the deployment graph to a dot file.")
def get_noop_run_deployment_arg():
return get_boolean_arg(
"noop",
dest='noop_run',
help="Specifies noop-run deployment configuring tasks executor to run "
"puppet and shell tasks in noop mode and skip all other. "
"Stores noop-run result summary in nailgun database")
def get_file_pattern_arg():
return get_str_arg(
"filepattern",

View File

@ -408,16 +408,24 @@ class EnvDeploy(EnvMixIn, base.BaseCommand):
'Store cluster settings and serialized ' \
'data in the db and ask the task executor ' \
'to dump the resulting graph into a dot file'
noop_run_help_string = 'Specifies noop-run deployment ' \
'configuring tasks executor to run ' \
'puppet and shell tasks in noop mode and ' \
'skip all other. Stores noop-run result ' \
'summary in nailgun database'
parser.add_argument(
'-d', '--dry-run', dest="dry_run",
action='store_true', help=dry_run_help_string)
parser.add_argument(
'-n', '--noop', dest="noop_run",
action='store_true', help=noop_run_help_string)
return parser
def take_action(self, parsed_args):
task_id = self.client.deploy_changes(parsed_args.id,
dry_run=parsed_args.dry_run)
dry_run=parsed_args.dry_run,
noop_run=parsed_args.noop_run)
msg = 'Deployment task with id {t} for the environment {e} '\
'has been started.\n'.format(t=task_id, e=parsed_args.id)
@ -430,7 +438,8 @@ class EnvRedeploy(EnvDeploy):
def take_action(self, parsed_args):
task_id = self.client.redeploy_changes(parsed_args.id,
dry_run=parsed_args.dry_run)
dry_run=parsed_args.dry_run,
noop_run=parsed_args.noop_run)
msg = 'Deployment task with id {t} for the environment {e} '\
'has been started.\n'.format(t=task_id, e=parsed_args.id)

View File

@ -198,6 +198,14 @@ class GraphExecute(base.BaseCommand):
default=False,
help='Force run all deployment tasks without '
'skipping.')
parser.add_argument('--noop',
action="store_true",
required=False,
default=False,
help='Specifies noop-run deployment configuring '
'tasks executor to run puppet and shell tasks in '
'noop mode and skip all other. Stores noop-run '
'result summary in nailgun database.')
return parser
def take_action(self, args):
@ -207,6 +215,7 @@ class GraphExecute(base.BaseCommand):
nodes=args.nodes,
task_names=args.task_names,
dry_run=args.dry_run,
noop_run=args.noop,
force=args.force
)
self.app.stdout.write(

View File

@ -93,17 +93,17 @@ class Environment(BaseObject):
[{"id": n.id} for n in nodes]
)
def deploy_changes(self, dry_run=False):
def deploy_changes(self, dry_run=False, noop_run=False):
deploy_data = self.connection.put_request(
"clusters/{0}/changes".format(self.id),
{}, dry_run=int(dry_run)
{}, dry_run=int(dry_run), noop_run=int(noop_run)
)
return DeployTask.init_with_data(deploy_data)
def redeploy_changes(self, dry_run=False):
def redeploy_changes(self, dry_run=False, noop_run=False):
deploy_data = self.connection.put_request(
"clusters/{0}/changes/redeploy".format(self.id),
{}, dry_run=int(dry_run)
{}, dry_run=int(dry_run), noop_run=int(noop_run)
)
return DeployTask.init_with_data(deploy_data)

View File

@ -62,9 +62,10 @@ class TestEnvironment(base.UnitTestCase):
@mock.patch('fuelclient.objects.task.DeployTask.init_with_data')
def test_deploy_changes(self, task_data):
dry_run = False
noop_run = False
mdeploy = self.m_request.put('/api/v1/clusters/1/changes'
'?dry_run={0}'.format(
int(dry_run)), json={})
'?dry_run={0}&noop_run={1}'.format(
int(dry_run), int(noop_run)), json={})
cmd = ['fuel', 'deploy-changes', '--env', '1']
self.execute(cmd)
@ -108,9 +109,9 @@ class TestEnvironment(base.UnitTestCase):
self.execute(cmd)
self.check_deploy_redeploy_changes(dry_run, mdeploy)
def check_deploy_redeploy_changes(self, dry_run, mdeploy):
self.assertEqual(mdeploy.last_request.qs['dry_run'][0],
str(int(dry_run)))
def check_deploy_redeploy_changes(self, res, mdeploy, mode='dry_run'):
self.assertEqual(mdeploy.last_request.qs[mode][0],
str(int(res)))
class TestEnvironmentOstf(base.UnitTestCase):

View File

@ -157,6 +157,7 @@ class TestGraphActions(test_engine.BaseCLITest):
nodes=[1, 2, 3],
task_names=None,
dry_run=False,
noop_run=False,
force=False
)
)
@ -172,6 +173,23 @@ class TestGraphActions(test_engine.BaseCLITest):
nodes=[1, 2, 3],
task_names=None,
dry_run=True,
noop_run=False,
force=False
)
)
def test_execute_w_noop_run(self):
self._test_cmd(
'execute',
'--env 1 --type custom_graph another_custom_graph '
'--nodes 1 2 3 --noop',
dict(
env_id=1,
graph_types=['custom_graph', 'another_custom_graph'],
nodes=[1, 2, 3],
task_names=None,
dry_run=False,
noop_run=True,
force=False
)
)
@ -186,6 +204,7 @@ class TestGraphActions(test_engine.BaseCLITest):
nodes=None,
task_names=None,
dry_run=False,
noop_run=False,
force=True
)
)
@ -200,6 +219,7 @@ class TestGraphActions(test_engine.BaseCLITest):
nodes=None,
task_names=['task1', 'task2'],
dry_run=False,
noop_run=False,
force=False
)
)

View File

@ -94,6 +94,7 @@ class TestEnvCommand(test_engine.BaseCLITest):
def test_env_deploy(self):
dry_run = False
noop_run = False
args = 'env deploy'
args += ' 42'
@ -102,6 +103,7 @@ class TestEnvCommand(test_engine.BaseCLITest):
calls = list()
calls.append(mock.call.deploy_changes(42,
noop_run=noop_run,
dry_run=dry_run))
self.m_get_client.assert_called_with('environment', mock.ANY)
@ -109,6 +111,7 @@ class TestEnvCommand(test_engine.BaseCLITest):
def test_env_deploy_dry_run(self):
dry_run = True
noop_run = False
args = 'env deploy -d'
args += ' 42'
@ -117,6 +120,24 @@ class TestEnvCommand(test_engine.BaseCLITest):
calls = list()
calls.append(mock.call.deploy_changes(42,
noop_run=noop_run,
dry_run=dry_run))
self.m_get_client.assert_called_with('environment', mock.ANY)
self.m_client.assert_has_calls(calls)
def test_env_deploy_noop_run(self):
dry_run = False
noop_run = True
args = 'env deploy -n'
args += ' 42'
self.exec_command(args)
calls = list()
calls.append(mock.call.deploy_changes(42,
noop_run=noop_run,
dry_run=dry_run))
self.m_get_client.assert_called_with('environment', mock.ANY)
@ -124,6 +145,7 @@ class TestEnvCommand(test_engine.BaseCLITest):
def test_env_redeploy(self):
dry_run = False
noop_run = False
args = 'env redeploy'
args += ' 42'
@ -132,6 +154,7 @@ class TestEnvCommand(test_engine.BaseCLITest):
calls = list()
calls.append(mock.call.redeploy_changes(42,
noop_run=noop_run,
dry_run=dry_run))
self.m_get_client.assert_called_with('environment', mock.ANY)
@ -139,6 +162,7 @@ class TestEnvCommand(test_engine.BaseCLITest):
def test_env_redeploy_dry_run(self):
dry_run = True
noop_run = False
args = 'env redeploy -d'
args += ' 42'
@ -147,6 +171,24 @@ class TestEnvCommand(test_engine.BaseCLITest):
calls = list()
calls.append(mock.call.redeploy_changes(42,
noop_run=noop_run,
dry_run=dry_run))
self.m_get_client.assert_called_with('environment', mock.ANY)
self.m_client.assert_has_calls(calls)
def test_env_redeploy_noop_run(self):
dry_run = False
noop_run = True
args = 'env redeploy -n'
args += ' 42'
self.exec_command(args)
calls = list()
calls.append(mock.call.redeploy_changes(42,
noop_run=noop_run,
dry_run=dry_run))
self.m_get_client.assert_called_with('environment', mock.ANY)

View File

@ -133,12 +133,14 @@ class TestDeploymentGraphFacade(test_api.BaseLibTest):
graph_types=["custom_graph", "another_custom_graph"],
task_names=["rsync_core_puppet"],
dry_run=True,
noop_run=True,
force=True
)
self.assertEqual(
{
'cluster': 1,
'dry_run': True,
'noop_run': True,
'graphs': [
{'nodes': [1, 2, 3], 'type': 'custom_graph',
'tasks': ['rsync_core_puppet']},

View File

@ -124,10 +124,9 @@ class TestEnvFacade(test_api.BaseLibTest):
self.client.deploy_changes(env_id, dry_run=dry_run)
self.check_deploy_redeploy_changes(dry_run, matcher)
def check_deploy_redeploy_changes(self, dry_run, matcher):
def check_deploy_redeploy_changes(self, res, matcher, mode='dry_run'):
self.assertTrue(matcher.called)
self.assertEqual(matcher.last_request.qs['dry_run'][0],
str(int(dry_run)))
self.assertEqual(matcher.last_request.qs[mode][0], str(int(res)))
@mock.patch.object(task_object.DeployTask, 'init_with_data')
def test_env_deploy_dry_run(self, m_init):
@ -140,6 +139,17 @@ class TestEnvFacade(test_api.BaseLibTest):
self.client.deploy_changes(env_id, dry_run=dry_run)
self.check_deploy_redeploy_changes(dry_run, matcher)
@mock.patch.object(task_object.DeployTask, 'init_with_data')
def test_env_deploy_noop_run(self, m_init):
env_id = 42
expected_uri = self.get_object_uri(self.res_uri, env_id, '/changes')
matcher = self.m_request.put(expected_uri, json={})
noop_run = True
self.client.deploy_changes(env_id, noop_run=noop_run)
self.check_deploy_redeploy_changes(noop_run, matcher, mode='noop_run')
@mock.patch.object(task_object.DeployTask, 'init_with_data')
def test_env_redeploy(self, m_init):
env_id = 42
@ -163,6 +173,18 @@ class TestEnvFacade(test_api.BaseLibTest):
self.client.redeploy_changes(env_id, dry_run=dry_run)
self.check_deploy_redeploy_changes(dry_run, matcher)
@mock.patch.object(task_object.DeployTask, 'init_with_data')
def test_env_redeploy_noop_run(self, m_init):
env_id = 42
expected_uri = self.get_object_uri(self.res_uri, env_id,
'/changes/redeploy')
matcher = self.m_request.put(expected_uri, json={})
noop_run = True
self.client.redeploy_changes(env_id, noop_run=noop_run)
self.check_deploy_redeploy_changes(noop_run, matcher, mode='noop_run')
@mock.patch.object(base_object.BaseObject, 'init_with_data')
def test_env_update(self, m_init):
env_id = 42

View File

@ -82,10 +82,10 @@ class EnvironmentClient(base_v1.BaseV1Client):
else:
env.unassign_all()
def deploy_changes(self, environment_id, dry_run=False):
def deploy_changes(self, environment_id, dry_run=False, noop_run=False):
env = self._entity_wrapper(obj_id=environment_id)
deploy_task = env.deploy_changes(dry_run=dry_run)
deploy_task = env.deploy_changes(dry_run=dry_run, noop_run=noop_run)
return deploy_task.id
def provision_nodes(self, environment_id, node_ids):
@ -104,10 +104,11 @@ class EnvironmentClient(base_v1.BaseV1Client):
nodes=nodes)
return self.connection.put_request(uri, {})
def redeploy_changes(self, environment_id, dry_run=False):
def redeploy_changes(self, environment_id, dry_run=False, noop_run=False):
env = self._entity_wrapper(obj_id=environment_id)
redeploy_task = env.redeploy_changes(dry_run=dry_run)
redeploy_task = env.redeploy_changes(dry_run=dry_run,
noop_run=noop_run)
return redeploy_task.id
def spawn_vms(self, environment_id):

View File

@ -86,7 +86,7 @@ class GraphClient(base_v1.BaseV1Client):
method(data, related_model, related_id, graph_type)
def execute(self, env_id, nodes=None, graph_types=None, task_names=None,
dry_run=False, force=False):
dry_run=False, noop_run=False, force=False):
request_data = {'cluster': env_id}
def map_args_to_graph_types(graph):
@ -105,6 +105,8 @@ class GraphClient(base_v1.BaseV1Client):
if dry_run:
request_data['dry_run'] = True
if noop_run:
request_data['noop_run'] = True
if force:
request_data['force'] = True