Warn when looking up grandparent resource name
When running config-download if the deployment name property was not set on a deployment resource from a ResourceGroup, it will trigger the code path to lookup the grandparent resource name. This codepath can be very slow depending on the number of nodes in the stack. This patch adds a warning when this is happening so that it's clear that the name property needs to be set on the deployment resource. Change-Id: I2cf7acef0999e1c36d4baa8c793bdaa78bd441ad
This commit is contained in:
parent
8ced750355
commit
8532a397de
@ -517,6 +517,40 @@ class TestConfig(base.TestCase):
|
|||||||
self.config.download_config, stack, self.tmp_dir)
|
self.config.download_config, stack, self.tmp_dir)
|
||||||
mock_git_init.assert_called_once_with(self.tmp_dir)
|
mock_git_init.assert_called_once_with(self.tmp_dir)
|
||||||
|
|
||||||
|
@patch.object(ooo_config.Config, 'initialize_git_repo')
|
||||||
|
@patch('tripleo_common.utils.config.Config.get_deployment_resource_id')
|
||||||
|
@patch('tripleo_common.utils.config.Config.get_deployment_data')
|
||||||
|
def test_config_download_warn_grandparent_resource_name(
|
||||||
|
self, mock_deployment_data, mock_deployment_resource_id,
|
||||||
|
mock_git_init):
|
||||||
|
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
|
||||||
|
mock_deployment_resource_id.side_effect = self._get_deployment_id
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
mock_git_init.assert_called_once_with(self.tmp_dir)
|
||||||
|
|
||||||
@patch.object(ooo_config.Config, 'initialize_git_repo')
|
@patch.object(ooo_config.Config, 'initialize_git_repo')
|
||||||
@patch('tripleo_common.utils.config.Config.get_deployment_resource_id')
|
@patch('tripleo_common.utils.config.Config.get_deployment_resource_id')
|
||||||
@patch('tripleo_common.utils.config.Config.get_config_dict')
|
@patch('tripleo_common.utils.config.Config.get_config_dict')
|
||||||
|
@ -342,6 +342,11 @@ class Config(object):
|
|||||||
# We can't have an integer here, let's figure out the
|
# We can't have an integer here, let's figure out the
|
||||||
# grandparent resource name
|
# grandparent resource name
|
||||||
deployment_ref = deployment.attributes['value']['deployment']
|
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:
|
if '/' in deployment_ref:
|
||||||
deployment_stack_id = deployment_ref.split('/')[-1]
|
deployment_stack_id = deployment_ref.split('/')[-1]
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user