From 1ef744273439809ca28c00e6c528c01ae046ac73 Mon Sep 17 00:00:00 2001 From: Vitalii Myhal Date: Thu, 4 Feb 2016 15:05:19 -0600 Subject: [PATCH] Introduced command 'redeploy-changes' The command 'redeploy-changes' allows to apply the changes to the cluster which is in the operational state. This allows you to deploy the changes without the reprovisioning procedure. Example: `fuel redeploy-changes --env ` Partial-Bug: 1540558 Change-Id: Ida0c24075a3deeb1635f579ec00728434bc7a6d6 Depends-On: Ibc89fdbfbd0a36a890412cd8e861d35bcf930690 --- fuelclient/cli/actions/__init__.py | 2 + fuelclient/cli/actions/deploy.py | 55 +++++++++++++------ fuelclient/objects/environment.py | 7 +++ fuelclient/tests/functional/v1/test_client.py | 27 +++++++-- 4 files changed, 68 insertions(+), 23 deletions(-) diff --git a/fuelclient/cli/actions/__init__.py b/fuelclient/cli/actions/__init__.py index edc3bb5..016b054 100644 --- a/fuelclient/cli/actions/__init__.py +++ b/fuelclient/cli/actions/__init__.py @@ -17,6 +17,7 @@ which implement command line interface logic All action classes must be added to action_tuple to be used by parser """ from fuelclient.cli.actions.deploy import DeployChangesAction +from fuelclient.cli.actions.deploy import RedeployChangesAction from fuelclient.cli.actions.environment import EnvironmentAction from fuelclient.cli.actions.fact import DeploymentAction from fuelclient.cli.actions.fact import ProvisioningAction @@ -61,6 +62,7 @@ actions_tuple = ( OpenstackConfigAction, PluginAction, ProvisioningAction, + RedeployChangesAction, ReleaseAction, ResetAction, RoleAction, diff --git a/fuelclient/cli/actions/deploy.py b/fuelclient/cli/actions/deploy.py index 0debbae..866a86e 100644 --- a/fuelclient/cli/actions/deploy.py +++ b/fuelclient/cli/actions/deploy.py @@ -16,31 +16,50 @@ from fuelclient.cli.actions.base import Action import fuelclient.cli.arguments as Args from fuelclient.cli.formatting import print_deploy_progress +from fuelclient.objects.environment import Environment -class DeployChangesAction(Action): +class ChangesAction(Action): + + action_name = None + actions_func_map = {} + + def __init__(self): + super(ChangesAction, self).__init__() + self.args = ( + Args.get_env_arg(required=True), + ) + self.flag_func_map = ( + (None, self.deploy_changes), + ) + + def deploy_changes(self, params): + """To apply all changes to some environment: + fuel --env 1 {action_name} + """ + env = Environment(params.env) + deploy_task = getattr(env, self.actions_func_map[self.action_name])() + self.serializer.print_to_output( + deploy_task.data, + deploy_task, + print_method=print_deploy_progress) + + +class DeployChangesAction(ChangesAction): """Deploy changes to environments """ action_name = "deploy-changes" def __init__(self): super(DeployChangesAction, self).__init__() - self.args = ( - Args.get_env_arg(required=True), - ) + self.actions_func_map[self.action_name] = 'deploy_changes' - self.flag_func_map = ( - (None, self.deploy_changes), - ) - def deploy_changes(self, params): - """To deploy all applied changes to some environment: - fuel --env 1 deploy-changes - """ - from fuelclient.objects.environment import Environment - env = Environment(params.env) - deploy_task = env.deploy_changes() - self.serializer.print_to_output( - deploy_task.data, - deploy_task, - print_method=print_deploy_progress) +class RedeployChangesAction(ChangesAction): + """Redeploy changes to environment which is in the operational state + """ + action_name = "redeploy-changes" + + def __init__(self): + super(RedeployChangesAction, self).__init__() + self.actions_func_map[self.action_name] = 'redeploy_changes' diff --git a/fuelclient/objects/environment.py b/fuelclient/objects/environment.py index d1584ad..1fbf737 100644 --- a/fuelclient/objects/environment.py +++ b/fuelclient/objects/environment.py @@ -100,6 +100,13 @@ class Environment(BaseObject): ) return DeployTask.init_with_data(deploy_data) + def redeploy_changes(self): + deploy_data = self.connection.put_request( + "clusters/{0}/changes/redeploy".format(self.id), + {} + ) + return DeployTask.init_with_data(deploy_data) + def get_network_data_path(self, directory=os.curdir): return os.path.join( os.path.abspath(directory), diff --git a/fuelclient/tests/functional/v1/test_client.py b/fuelclient/tests/functional/v1/test_client.py index 46073b2..8d15002 100644 --- a/fuelclient/tests/functional/v1/test_client.py +++ b/fuelclient/tests/functional/v1/test_client.py @@ -417,13 +417,30 @@ class TestDownloadUploadNodeAttributes(base.BaseTestCase): class TestDeployChanges(base.BaseTestCase): - def test_deploy_changes_no_failure(self): + create_env = "env create --name=test --release={0}" + add_node = "--env-id=1 node set --node 1 --role=controller" + deploy_changes = "deploy-changes --env 1" + redeploy_changes = "redeploy-changes --env 1" + + def setUp(self): + super(TestDeployChanges, self).setUp() self.load_data_to_nailgun_server() release_id = self.get_first_deployable_release_id() - env_create = "env create --name=test --release={0}".format(release_id) - add_node = "--env-id=1 node set --node 1 --role=controller" - deploy_changes = "deploy-changes --env 1" - self.run_cli_commands((env_create, add_node, deploy_changes)) + self.create_env = self.create_env.format(release_id) + self.run_cli_commands((self.create_env, self.add_node)) + + def test_deploy_changes(self): + self.run_cli_commands((self.deploy_changes,)) + + def test_no_changes_to_deploy(self): + self.run_cli_commands((self.deploy_changes,)) + self.check_for_stderr(self.deploy_changes, + "(No changes to deploy)\n", + check_errors=False) + + def test_redeploy_changes(self): + self.run_cli_commands((self.deploy_changes, + self.redeploy_changes)) class TestDirectoryDoesntExistErrorMessages(base.BaseTestCase):