From c1c21d7cddca2f307e93f42b4758e64fcdf0a630 Mon Sep 17 00:00:00 2001 From: Oleg Ovcharuk Date: Tue, 12 Feb 2019 01:43:09 +0300 Subject: [PATCH] Disable key sorting in workflow definition Update to PyYAML 5.1 to be able to turn off key sorting in workflow definitions. We should not change user's data until user asks to. Change-Id: I888008ac8f9c12bd92a9bd72bd7c276a11827847 Closes-Bug: #1815515 Signed-off-by: Oleg Ovcharuk --- lower-constraints.txt | 2 +- mistral/services/workflows.py | 2 +- .../unit/services/test_workflow_service.py | 34 +++++++++++++++++++ requirements.txt | 2 +- 4 files changed, 37 insertions(+), 3 deletions(-) diff --git a/lower-constraints.txt b/lower-constraints.txt index bf90e5460..e59c71a33 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -135,7 +135,7 @@ python-zaqarclient==1.0.0 python-zunclient==3.4.0 python-qinlingclient==1.0.0 pytz==2013.6 -PyYAML==3.12 +PyYAML==5.1 reno==2.5.0 repoze.lru==0.7 requests-mock==1.2.0 diff --git a/mistral/services/workflows.py b/mistral/services/workflows.py index 1e00f6cdd..657a58dcd 100644 --- a/mistral/services/workflows.py +++ b/mistral/services/workflows.py @@ -208,4 +208,4 @@ def _cut_wf_definition_from_all(wfs_yaml, wf_name): return safe_yaml.dump({ 'version': wfs_yaml['version'], wf_name: wfs_yaml[wf_name] - }) + }, sort_keys=False) diff --git a/mistral/tests/unit/services/test_workflow_service.py b/mistral/tests/unit/services/test_workflow_service.py index e12dda941..ee63d12fc 100644 --- a/mistral/tests/unit/services/test_workflow_service.py +++ b/mistral/tests/unit/services/test_workflow_service.py @@ -144,6 +144,23 @@ test_workflow: """ +WORKFLOWS_WITH_KEY_ORDER = """ +--- +version: '2.0' + +wf1: + tasks: + task1: + publish: + we: 1 + dont_want: 2 + to_be_sorted: 3 +wf2: + tasks: + task1: + action: std.noop +""" + class WorkflowServiceTest(base.DbTestCase): def test_create_workflows(self): @@ -166,6 +183,23 @@ class WorkflowServiceTest(base.DbTestCase): self.assertEqual('wf2', wf2_spec.get_name()) self.assertEqual('direct', wf2_spec.get_type()) + def test_preserve_key_ordering_in_workflow_definition(self): + db_wfs = wf_service.create_workflows(WORKFLOWS_WITH_KEY_ORDER) + + self.assertEqual(2, len(db_wfs)) + + wf1_db = self._assert_single_item(db_wfs, name='wf1') + wf1_def = wf1_db.definition + published_values = wf1_def.splitlines()[-3:] + wf1_publish = [ + item.strip() + for item in published_values + ] + self.assertEqual( + ['we: 1', 'dont_want: 2', 'to_be_sorted: 3'], + wf1_publish + ) + def test_engine_commands_are_valid_task_names(self): for name in workflows.ENGINE_COMMANDS: wf_text = WORKFLOW_WITH_VAR_TASK_NAME.format(task_name=name) diff --git a/requirements.txt b/requirements.txt index 7cf24d0be..674472dfc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -57,7 +57,7 @@ python-vitrageclient>=2.0.0 # Apache-2.0 python-zunclient>=3.4.0 # Apache-2.0 python-qinlingclient>=1.0.0 # Apache-2.0 PyJWT>=1.5 # MIT -PyYAML>=3.12 # MIT +PyYAML>=5.1 # MIT requests>=2.14.2 # Apache-2.0 tenacity>=5.0.1 # Apache-2.0 six>=1.10.0 # MIT