Merge "Lower log level of missing output"

This commit is contained in:
Zuul 2020-06-20 05:16:52 +00:00 committed by Gerrit Code Review
commit 82d92d08a3
6 changed files with 23 additions and 14 deletions

View File

@ -49,7 +49,7 @@ class ScaleManager(object):
cluster = self.new_cluster
stack = self.osclient.heat().stacks.get(cluster.stack_id)
hosts = hosts_output.get_output_value(stack)
hosts = hosts_output.get_output_value(stack, cluster)
if hosts is None:
raise exception.MagnumException(_(
"Output key '%(output_key)s' is missing from stack "

View File

@ -35,7 +35,7 @@ class K8sApiAddressOutputMapping(template_def.OutputMapping):
if self.cluster_attr is None:
return
output_value = self.get_output_value(stack)
output_value = self.get_output_value(stack, cluster)
if output_value is not None:
# TODO(yuanying): port number is hardcoded, this will be fix
protocol = 'https'

View File

@ -24,7 +24,7 @@ class SwarmApiAddressOutputMapping(template_def.OutputMapping):
if self.cluster_attr is None:
return
output_value = self.get_output_value(stack)
output_value = self.get_output_value(stack, cluster)
if output_value is not None:
# Note(rocha): protocol should always be tcp as the docker
# command client does not handle https (see bug #1604812).

View File

@ -26,7 +26,7 @@ class SwarmModeApiAddressOutputMapping(template_def.OutputMapping):
if self.cluster_attr is None:
return
output_value = self.get_output_value(stack)
output_value = self.get_output_value(stack, cluster)
if output_value is not None:
# Note(rocha): protocol should always be tcp as the docker
# command client does not handle https (see bug #1604812).

View File

@ -114,7 +114,7 @@ class OutputMapping(object):
if self.cluster_attr is None:
return
output_value = self.get_output_value(stack)
output_value = self.get_output_value(stack, cluster)
if output_value is None:
return
setattr(cluster, self.cluster_attr, output_value)
@ -122,12 +122,19 @@ class OutputMapping(object):
def matched(self, output_key):
return self.heat_output == output_key
def get_output_value(self, stack):
def get_output_value(self, stack, cluster):
for output in stack.to_dict().get('outputs', []):
if output['output_key'] == self.heat_output:
return output['output_value']
LOG.warning('stack does not have output_key %s', self.heat_output)
LOG.debug('cluster %(cluster_uuid)s, status %(cluster_status)s, '
'stack %(stack_id)s does not have output_key '
'%(heat_output)s',
{'cluster_uuid': cluster.uuid,
'cluster_status': cluster.status,
'stack_id': stack.id,
'heat_output': self.heat_output}
)
return None
@ -150,7 +157,7 @@ class NodeGroupOutputMapping(OutputMapping):
if self.nodegroup_attr is None:
return
output_value = self.get_output_value(stack)
output_value = self.get_output_value(stack, cluster)
if output_value is None:
return
@ -166,9 +173,10 @@ class NodeGroupOutputMapping(OutputMapping):
setattr(ng, self.nodegroup_attr, output_value)
ng.save()
def get_output_value(self, stack):
def get_output_value(self, stack, cluster):
if not self.is_stack_param:
return super(NodeGroupOutputMapping, self).get_output_value(stack)
return super(NodeGroupOutputMapping, self).get_output_value(
stack, cluster)
return self.get_param_value(stack)
def get_param_value(self, stack):

View File

@ -150,24 +150,25 @@ class TemplateDefinitionTestCase(base.TestCase):
]
mock_stack = mock.MagicMock()
mock_cluster = mock.MagicMock()
mock_stack.to_dict.return_value = {'outputs': heat_outputs}
output = cmn_tdef.OutputMapping('key1')
value = output.get_output_value(mock_stack)
value = output.get_output_value(mock_stack, mock_cluster)
self.assertEqual('value1', value)
output = cmn_tdef.OutputMapping('key2')
value = output.get_output_value(mock_stack)
value = output.get_output_value(mock_stack, mock_cluster)
self.assertEqual(["value2", "value3"], value)
output = cmn_tdef.OutputMapping('key3')
value = output.get_output_value(mock_stack)
value = output.get_output_value(mock_stack, mock_cluster)
self.assertIsNone(value)
# verify stack with no 'outputs' attribute
mock_stack.to_dict.return_value = {}
output = cmn_tdef.OutputMapping('key1')
value = output.get_output_value(mock_stack)
value = output.get_output_value(mock_stack, mock_cluster)
self.assertIsNone(value)
def test_add_output_with_mapping_type(self):