From 8f1e68d0ab80afc6baa5778e4274b917b45ab049 Mon Sep 17 00:00:00 2001 From: Saravanan KR Date: Fri, 30 Jun 2017 17:30:37 +0530 Subject: [PATCH] Added a warning log to list the deprecated parameters in the plan Execute a workflow to get the list of deprecated parameters in the plan. Add a warning log to the user just before the deployment to alert the user that a list of parameters are deprecated. And should be removed soon. Change-Id: If496795e44c5b36cb58fcc0221d99d94e098415c --- ...rn-deprecated-params-29197c5de2feb172.yaml | 4 ++ .../overcloud_deploy/test_overcloud_deploy.py | 12 +++- .../tests/workflows/test_parameters.py | 71 +++++++++++++++++++ tripleoclient/v1/overcloud_deploy.py | 3 + tripleoclient/workflows/parameters.py | 35 ++++++++- 5 files changed, 122 insertions(+), 3 deletions(-) create mode 100644 releasenotes/notes/warn-deprecated-params-29197c5de2feb172.yaml diff --git a/releasenotes/notes/warn-deprecated-params-29197c5de2feb172.yaml b/releasenotes/notes/warn-deprecated-params-29197c5de2feb172.yaml new file mode 100644 index 000000000..007da8a4d --- /dev/null +++ b/releasenotes/notes/warn-deprecated-params-29197c5de2feb172.yaml @@ -0,0 +1,4 @@ +--- +features: + - Added a warning log with the list of deprecated parameters in the plan. + diff --git a/tripleoclient/tests/v1/overcloud_deploy/test_overcloud_deploy.py b/tripleoclient/tests/v1/overcloud_deploy/test_overcloud_deploy.py index ec7066816..359a9dd45 100644 --- a/tripleoclient/tests/v1/overcloud_deploy/test_overcloud_deploy.py +++ b/tripleoclient/tests/v1/overcloud_deploy/test_overcloud_deploy.py @@ -411,6 +411,8 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud): clients.tripleoclient.object_store.put_object.assert_called() self.assertTrue(mock_invoke_plan_env_wf.called) + @mock.patch('tripleoclient.workflows.parameters.' + 'check_deprecated_parameters', autospec=True) @mock.patch('tripleoclient.utils.get_overcloud_endpoint', autospec=True) @mock.patch('tripleoclient.v1.overcloud_deploy.DeployOvercloud.' '_deploy_postconfig', autospec=True) @@ -445,7 +447,8 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud): mock_create_tempest_deployer_input, mock_create_parameters_env, mock_validate_args, mock_breakpoints_cleanup, mock_tarball, - mock_postconfig, mock_get_overcloud_endpoint): + mock_postconfig, mock_get_overcloud_endpoint, + mock_deprecated_params): arglist = ['--templates', '--skip-deploy-identifier'] verifylist = [ @@ -1286,6 +1289,8 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud): mock_validate_args.assert_called_once_with(parsed_args) + @mock.patch('tripleoclient.workflows.parameters.' + 'check_deprecated_parameters', autospec=True) @mock.patch('tripleoclient.workflows.deployment.deploy_and_wait', autospec=True) @mock.patch('tripleoclient.v1.overcloud_deploy.DeployOvercloud.' @@ -1302,7 +1307,8 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud): mock_get_template_contents, mock_upload_missing_files, mock_process_and_upload_env, - mock_deploy_and_wait): + mock_deploy_and_wait, + mock_deprecated_params): clients = self.app.client_manager orchestration_client = clients.orchestration mock_stack = fakes.create_tht_stack() @@ -1324,6 +1330,8 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud): mock_get_template_contents.return_value = [{}, {}] + self.cmd.clients = {} + self.cmd._heat_deploy(mock_stack, 'mock_stack', '/tmp', {}, {}, 1, '/tmp', {}, True, False, False, None) diff --git a/tripleoclient/tests/workflows/test_parameters.py b/tripleoclient/tests/workflows/test_parameters.py index 0d2984e44..224b7f3dc 100644 --- a/tripleoclient/tests/workflows/test_parameters.py +++ b/tripleoclient/tests/workflows/test_parameters.py @@ -21,6 +21,17 @@ from tripleoclient import exceptions from tripleoclient.workflows import parameters +class TestStringCapture(object): + def __init__(self): + self.capture_string = '' + + def write(self, msg): + self.capture_string = self.capture_string + msg + + def getvalue(self): + return self.capture_string + + class TestParameterWorkflows(utils.TestCommand): def setUp(self): @@ -149,3 +160,63 @@ class TestParameterWorkflows(utils.TestCommand): 'the-plan-environment.yaml') self.workflow.executions.create.assert_not_called() + + def test_check_deprecated_params_no_output(self): + self.websocket.wait_for_messages.return_value = iter([{ + "execution": {"id": "IDID"}, + "status": "SUCCESS", + }]) + + parameters.check_deprecated_parameters( + self.app.client_manager, + container='container-name') + + self.workflow.executions.create.assert_called_once_with( + 'tripleo.plan_management.v1.get_deprecated_parameters', + workflow_input={'queue_name': 'UUID4', + 'container': 'container-name'}) + + @mock.patch("sys.stdout", new_callable=TestStringCapture) + def test_check_deprecated_params_user_defined(self, mock_print): + deprecated_params = [{'parameter': 'TestParameter1', + 'deprecated': True, + 'user_defined': True}] + self.websocket.wait_for_messages.return_value = iter([{ + "execution": {"id": "IDID"}, + "status": "SUCCESS", + "deprecated": deprecated_params + }]) + + parameters.check_deprecated_parameters( + self.app.client_manager, + container='container-name') + + self.workflow.executions.create.assert_called_once_with( + 'tripleo.plan_management.v1.get_deprecated_parameters', + workflow_input={'queue_name': 'UUID4', + 'container': 'container-name'}) + + std_output = mock_print.getvalue() + self.assertIn('TestParameter1', std_output) + + @mock.patch("sys.stdout", new_callable=TestStringCapture) + def test_check_deprecated_params_user_not_defined(self, mock_print): + deprecated_params = [{'parameter': 'TestParameter1', + 'deprecated': True}] + self.websocket.wait_for_messages.return_value = iter([{ + "execution": {"id": "IDID"}, + "status": "SUCCESS", + "deprecated": deprecated_params + }]) + + parameters.check_deprecated_parameters( + self.app.client_manager, + container='container-name') + + self.workflow.executions.create.assert_called_once_with( + 'tripleo.plan_management.v1.get_deprecated_parameters', + workflow_input={'queue_name': 'UUID4', + 'container': 'container-name'}) + + std_output = mock_print.getvalue() + self.assertNotIn('TestParameter1', std_output) diff --git a/tripleoclient/v1/overcloud_deploy.py b/tripleoclient/v1/overcloud_deploy.py index 61ac72fa0..a4080f1d8 100644 --- a/tripleoclient/v1/overcloud_deploy.py +++ b/tripleoclient/v1/overcloud_deploy.py @@ -225,6 +225,9 @@ class DeployOvercloud(command.Command): workflow_params.invoke_plan_env_workflows(self.clients, stack_name, plan_env_file) + + workflow_params.check_deprecated_parameters(self.clients, stack_name) + if not update_plan_only: print("Deploying templates in the directory {0}".format( os.path.abspath(tht_root))) diff --git a/tripleoclient/workflows/parameters.py b/tripleoclient/workflows/parameters.py index 364f67048..ff0d8fbe0 100644 --- a/tripleoclient/workflows/parameters.py +++ b/tripleoclient/workflows/parameters.py @@ -9,7 +9,6 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. - import uuid import yaml @@ -100,3 +99,37 @@ def invoke_plan_env_workflows(clients, stack_name, plan_env_file): message = payload.get('message', '') msg = ('Workflow execution is failed: %s' % (message)) raise exceptions.PlanEnvWorkflowError(msg) + + +def check_deprecated_parameters(clients, container): + """Checks for deprecated parameters in plan and adds warning if present""" + + workflow_client = clients.workflow_engine + tripleoclients = clients.tripleoclient + queue_name = str(uuid.uuid4()) + workflow_input = { + 'container': container, + 'queue_name': queue_name + } + + with tripleoclients.messaging_websocket(queue_name) as ws: + execution = base.start_workflow( + workflow_client, + 'tripleo.plan_management.v1.get_deprecated_parameters', + workflow_input=workflow_input + ) + + messages = base.wait_for_messages(workflow_client, ws, execution, 60) + + deprecated_params = [] + for message in messages: + if message['status'] == 'SUCCESS': + for param in message.get('deprecated', []): + if param.get('user_defined'): + deprecated_params.append(param['parameter']) + + if deprecated_params: + print('WARNING: Following parameters are deprecated and still ' + 'defined. Deprecated parameters will be removed soon!') + print('\n'.join([' {}'.format(param) + for param in deprecated_params]))