Merge "Warn when looking up grandparent resource name" into stable/queens

This commit is contained in:
Zuul 2019-10-09 22:43:41 +00:00 committed by Gerrit Code Review
commit c9b6ca5dc6
2 changed files with 33 additions and 0 deletions

View File

@ -397,6 +397,34 @@ class TestConfig(base.TestCase):
assert issubclass(w[-1].category, DeprecationWarning)
assert "group:os-apply-config is deprecated" in str(w[-1].message)
@patch('tripleo_common.utils.config.Config.get_deployment_data')
def test_config_download_warn_grandparent_resource_name(
self, mock_deployment_data):
heat = mock.MagicMock()
self.config = ooo_config.Config(heat)
stack = mock.MagicMock()
heat.stacks.get.return_value = stack
heat.resources.get.return_value = mock.MagicMock()
deployment_data, _ = self._get_config_data('config_data.yaml')
# Set the name of the deployment to an integer to trigger looking up
# the grandparent resource name
deployment_data[0].attributes['value']['name'] = 1
self.deployments = deployment_data
mock_deployment_data.return_value = deployment_data
self.tmp_dir = self.useFixture(fixtures.TempDir()).path
with warnings.catch_warnings(record=True) as w:
self.assertRaises(ValueError,
self.config.download_config, stack, self.tmp_dir)
self.assertGreaterEqual(len(w), 1)
self.assertGreaterEqual(len([x for x in w
if "grandparent"
in str(x.message)]),
1)
@patch('tripleo_common.utils.config.Config.get_config_dict')
@patch('tripleo_common.utils.config.Config.get_deployment_data')
def test_config_download_no_deployment_uuid(self, mock_deployment_data,

View File

@ -252,6 +252,11 @@ class Config(object):
# We can't have an integer here, let's figure out the
# grandparent resource name
deployment_ref = deployment.attributes['value']['deployment']
warnings.warn('Determining grandparent resource name for '
'deployment %s. Ensure the name property is '
'set on the deployment resource in the '
'templates.' % deployment_ref)
if '/' in deployment_ref:
deployment_stack_id = deployment_ref.split('/')[-1]
else: