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.
Change-Id: I08757ab389f35de52814fba48722e9325e50ab21
(cherry picked from commit 813ffef308
)
This commit is contained in:
parent
98a54fabf6
commit
7de9415e95
|
@ -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:
|
||||
|
@ -91,12 +92,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]
|
||||
|
@ -104,6 +105,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')
|
||||
|
||||
|
@ -128,9 +130,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 '
|
||||
|
@ -164,11 +166,11 @@ class TestConfig(base.TestCase):
|
|||
for role in fake_role:
|
||||
filedir = os.path.join(self.tmp_dir, role)
|
||||
os.makedirs(filedir)
|
||||
for step in range(constants.UPGRADE_STEPS_MAX):
|
||||
for step in range(constants.DEFAULT_STEPS_MAX):
|
||||
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)
|
||||
|
@ -640,13 +642,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)
|
||||
|
||||
|
@ -656,6 +658,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:
|
||||
|
|
Loading…
Reference in New Issue