From 9e928d1f44e00fbc606cae6dd0908a8de6c84c99 Mon Sep 17 00:00:00 2001 From: "Jesse Pretorius (odyssey4me)" Date: Mon, 3 Feb 2020 12:25:11 +0000 Subject: [PATCH] tests: Get RoleData correctly In Ie543782569de14d56bc41740611f7512e8357a22 a new entry was added into the fake stack, but the indexes for any test accessing the FAKE_STACK were not changed, effectively breaking several tests silently. This patch removes the direct referencing of indexes in FAKE_STACK and uses the config utilities to get the data correctly. It also corrects the reference to the constant UPGRADE_STEPS_MAX which no longer exists thanks to Ie03084bb599b7b06aeeb321d2a7938a908487788 We also add mock_assert_called to several of the tests to ensure that if the fake_role list is empty, the test will fail. Backport note: In this backport, we have to change DEFAULT_STEPS_MAX to be UPGRADE_STEPS_MAX to maintain a functional result until Ie03084bb599b7b06aeeb321d2a7938a908487788 merges. Change-Id: I08757ab389f35de52814fba48722e9325e50ab21 (cherry picked from commit 813ffef308fbed231e04a679d5114f5bc3606bab) --- tripleo_common/tests/utils/test_config.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/tripleo_common/tests/utils/test_config.py b/tripleo_common/tests/utils/test_config.py index 069cba404..908abcf71 100644 --- a/tripleo_common/tests/utils/test_config.py +++ b/tripleo_common/tests/utils/test_config.py @@ -51,17 +51,18 @@ class TestConfig(base.TestCase): 'service_names', 'upgrade_batch_tasks', 'upgrade_tasks', 'external_deploy_tasks'] - fake_role = [role for role in - fakes.FAKE_STACK['outputs'][1]['output_value']] heat = mock.MagicMock() heat.stacks.get.return_value = fakes.create_tht_stack() self.config = ooo_config.Config(heat) + self.config.fetch_config('overcloud') + fake_role = list(self.config.stack_outputs.get('RoleData')) self.config.download_config('overcloud', '/tmp/tht', config_type_list) mock_git_init.assert_called_once_with('/tmp/tht') expected_mkdir_calls = [call('/tmp/tht/%s' % r) for r in fake_role] mock_mkdir.assert_has_calls(expected_mkdir_calls, any_order=True) + mock_mkdir.assert_called() expected_calls = [] for config in config_type_list: for role in fake_role: @@ -88,12 +89,12 @@ class TestConfig(base.TestCase): mock_git_init): expected_config_type = 'config_settings' - fake_role = [role for role in - fakes.FAKE_STACK['outputs'][1]['output_value']] heat = mock.MagicMock() heat.stacks.get.return_value = fakes.create_tht_stack() self.config = ooo_config.Config(heat) + self.config.fetch_config('overcloud') + fake_role = list(self.config.stack_outputs.get('RoleData')) self.config.download_config('overcloud', '/tmp/tht', ['config_settings']) expected_mkdir_calls = [call('/tmp/tht/%s' % r) for r in fake_role] @@ -101,6 +102,7 @@ class TestConfig(base.TestCase): % (r, expected_config_type)) for r in fake_role] mock_mkdir.assert_has_calls(expected_mkdir_calls, any_order=True) + mock_mkdir.assert_called() mock_open.assert_has_calls(expected_calls, any_order=True) mock_git_init.assert_called_once_with('/tmp/tht') @@ -125,9 +127,9 @@ class TestConfig(base.TestCase): heat = mock.MagicMock() heat.stacks.get.return_value = fakes.create_tht_stack() self.config = ooo_config.Config(heat) + self.config.fetch_config('overcloud') self.tmp_dir = self.useFixture(fixtures.TempDir()).path - fake_role = [role for role in - fakes.FAKE_STACK['outputs'][1]['output_value']] + fake_role = list(self.config.stack_outputs.get('RoleData')) expected_tasks = {'FakeController': {0: [], 1: [{'name': 'Stop fake service', 'service': 'name=fake ' @@ -165,7 +167,7 @@ class TestConfig(base.TestCase): filepath = os.path.join(filedir, "upgrade_tasks_step%s.yaml" % step) playbook_tasks = self.config._write_tasks_per_step( - fakes.FAKE_STACK['outputs'][1]['output_value'][role] + self.config.stack_outputs.get('RoleData')[role] ['upgrade_tasks'], role, filepath, step) self.assertTrue(os.path.isfile(filepath)) self.assertEqual(expected_tasks[role][step], playbook_tasks) @@ -618,13 +620,13 @@ class TestConfig(base.TestCase): 'service_names', 'upgrade_batch_tasks', 'upgrade_tasks', 'external_deploy_tasks'] - fake_role = [role for role in - fakes.FAKE_STACK['outputs'][1]['output_value']] mock_os_path_exists.get.return_value = True heat = mock.MagicMock() heat.stacks.get.return_value = fakes.create_tht_stack() self.config = ooo_config.Config(heat) + self.config.fetch_config('overcloud') + fake_role = list(self.config.stack_outputs.get('RoleData')) self.config.download_config('overcloud', '/tmp/tht', config_type_list, False) @@ -634,6 +636,7 @@ class TestConfig(base.TestCase): expected_mkdir_calls = [call('/tmp/tht/%s' % r) for r in fake_role] mock_mkdir.assert_has_calls(expected_mkdir_calls, any_order=True) + mock_mkdir.assert_called() expected_calls = [] for config in config_type_list: for role in fake_role: