Merge "Raise an error if deployment_name cannot be determined" into stable/queens

This commit is contained in:
Zuul 2019-09-23 05:08:01 +00:00 committed by Gerrit Code Review
commit 59bcf2b426
2 changed files with 26 additions and 1 deletions

View File

@ -449,3 +449,22 @@ class TestConfig(base.TestCase):
with warnings.catch_warnings(record=True) as w:
self.config.download_config(stack, self.tmp_dir)
assert "Skipping deployment" in str(w[-1].message)
@patch('tripleo_common.utils.config.Config.get_deployment_data')
def test_config_download_no_deployment_name(self, mock_deployment_data):
heat = mock.MagicMock()
self.config = ooo_config.Config(heat)
stack = mock.MagicMock()
heat.stacks.get.return_value = stack
deployment_data, _ = self._get_config_data('config_data.yaml')
# Delete the name of the first deployment and his parent.
del deployment_data[0].attributes['value']['name']
deployment_data[0].parent_resource = None
mock_deployment_data.return_value = deployment_data
self.tmp_dir = self.useFixture(fixtures.TempDir()).path
self.assertRaises(ValueError,
self.config.download_config, stack, self.tmp_dir)

View File

@ -207,7 +207,7 @@ class Config(object):
server_names = self.get_server_names()
server_ids = dict([(v, k) for (k, v) in server_names.items()])
# role_deployment_names is a dict of role names to deployment names for
# that role. The deployment names are futher separated in their own
# that role. The deployment names are further separated in their own
# dict with keys of pre_deployment/post_deployment.
role_deployment_names = {}
# server_roles is a dict of server name to server role for easier
@ -238,6 +238,11 @@ class Config(object):
# or empty string, default to the name of the parent_resource.
deployment_name = deployment.attributes['value'].get(
'name') or deployment.parent_resource
if not deployment_name:
message = "The deployment name cannot be determined. It " \
"should be set via the name property on the " \
"Deployment resources in the templates."
raise ValueError(message)
try:
int(deployment_name)
@ -269,6 +274,7 @@ class Config(object):
"not be determined."
raise ValueError(message)
deployment_name = resources[0].resource_name
config_dict['deployment_name'] = deployment_name
# reset deploy_server_id to the actual server_id since we have to