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
This commit is contained in:
Saravanan KR 2017-06-30 17:30:37 +05:30
parent 82b501b322
commit 8f1e68d0ab
5 changed files with 122 additions and 3 deletions

View File

@ -0,0 +1,4 @@
---
features:
- Added a warning log with the list of deprecated parameters in the plan.

View File

@ -411,6 +411,8 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
clients.tripleoclient.object_store.put_object.assert_called() clients.tripleoclient.object_store.put_object.assert_called()
self.assertTrue(mock_invoke_plan_env_wf.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.utils.get_overcloud_endpoint', autospec=True)
@mock.patch('tripleoclient.v1.overcloud_deploy.DeployOvercloud.' @mock.patch('tripleoclient.v1.overcloud_deploy.DeployOvercloud.'
'_deploy_postconfig', autospec=True) '_deploy_postconfig', autospec=True)
@ -445,7 +447,8 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
mock_create_tempest_deployer_input, mock_create_tempest_deployer_input,
mock_create_parameters_env, mock_validate_args, mock_create_parameters_env, mock_validate_args,
mock_breakpoints_cleanup, mock_tarball, 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'] arglist = ['--templates', '--skip-deploy-identifier']
verifylist = [ verifylist = [
@ -1286,6 +1289,8 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
mock_validate_args.assert_called_once_with(parsed_args) 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', @mock.patch('tripleoclient.workflows.deployment.deploy_and_wait',
autospec=True) autospec=True)
@mock.patch('tripleoclient.v1.overcloud_deploy.DeployOvercloud.' @mock.patch('tripleoclient.v1.overcloud_deploy.DeployOvercloud.'
@ -1302,7 +1307,8 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
mock_get_template_contents, mock_get_template_contents,
mock_upload_missing_files, mock_upload_missing_files,
mock_process_and_upload_env, mock_process_and_upload_env,
mock_deploy_and_wait): mock_deploy_and_wait,
mock_deprecated_params):
clients = self.app.client_manager clients = self.app.client_manager
orchestration_client = clients.orchestration orchestration_client = clients.orchestration
mock_stack = fakes.create_tht_stack() mock_stack = fakes.create_tht_stack()
@ -1324,6 +1330,8 @@ class TestDeployOvercloud(fakes.TestDeployOvercloud):
mock_get_template_contents.return_value = [{}, {}] mock_get_template_contents.return_value = [{}, {}]
self.cmd.clients = {}
self.cmd._heat_deploy(mock_stack, 'mock_stack', '/tmp', {}, self.cmd._heat_deploy(mock_stack, 'mock_stack', '/tmp', {},
{}, 1, '/tmp', {}, True, False, False, None) {}, 1, '/tmp', {}, True, False, False, None)

View File

@ -21,6 +21,17 @@ from tripleoclient import exceptions
from tripleoclient.workflows import parameters 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): class TestParameterWorkflows(utils.TestCommand):
def setUp(self): def setUp(self):
@ -149,3 +160,63 @@ class TestParameterWorkflows(utils.TestCommand):
'the-plan-environment.yaml') 'the-plan-environment.yaml')
self.workflow.executions.create.assert_not_called() 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)

View File

@ -225,6 +225,9 @@ class DeployOvercloud(command.Command):
workflow_params.invoke_plan_env_workflows(self.clients, workflow_params.invoke_plan_env_workflows(self.clients,
stack_name, stack_name,
plan_env_file) plan_env_file)
workflow_params.check_deprecated_parameters(self.clients, stack_name)
if not update_plan_only: if not update_plan_only:
print("Deploying templates in the directory {0}".format( print("Deploying templates in the directory {0}".format(
os.path.abspath(tht_root))) os.path.abspath(tht_root)))

View File

@ -9,7 +9,6 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import uuid import uuid
import yaml import yaml
@ -100,3 +99,37 @@ def invoke_plan_env_workflows(clients, stack_name, plan_env_file):
message = payload.get('message', '') message = payload.get('message', '')
msg = ('Workflow execution is failed: %s' % (message)) msg = ('Workflow execution is failed: %s' % (message))
raise exceptions.PlanEnvWorkflowError(msg) 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]))