Do not resolve neutron resource attributes when resource_id is None
Also, fix the test to correctly account for NotFound as well as this new case. Closes-Bug: 1440189 Change-Id: I31004c11af71e32a4388fd44cd8b98df8afbd1a5
This commit is contained in:
parent
56f1905279
commit
c0f3f851c3
|
@ -119,15 +119,16 @@ class NeutronResource(resource.Resource):
|
|||
result=_('Resource is not built'))
|
||||
|
||||
def _resolve_attribute(self, name):
|
||||
try:
|
||||
attributes = self._show_resource()
|
||||
except Exception as ex:
|
||||
self.client_plugin().ignore_not_found(ex)
|
||||
return None
|
||||
if name == 'show':
|
||||
return attributes
|
||||
if self.resource_id:
|
||||
try:
|
||||
attributes = self._show_resource()
|
||||
except Exception as ex:
|
||||
self.client_plugin().ignore_not_found(ex)
|
||||
return None
|
||||
if name == 'show':
|
||||
return attributes
|
||||
|
||||
return attributes[name]
|
||||
return attributes[name]
|
||||
|
||||
def FnGetRefId(self):
|
||||
return six.text_type(self.resource_id)
|
||||
|
|
|
@ -17,6 +17,7 @@ from neutronclient.v2_0 import client as neutronclient
|
|||
import six
|
||||
|
||||
from heat.common import exception
|
||||
from heat.engine.clients.os import neutron
|
||||
from heat.engine.hot import functions
|
||||
from heat.engine import properties
|
||||
from heat.engine import resource
|
||||
|
@ -114,14 +115,19 @@ class NeutronTest(common.HeatTestCase):
|
|||
mock_show_resource.side_effect = [{'attr1': 'val1', 'attr2': 'val2'},
|
||||
{'attr1': 'val1', 'attr2': 'val2'},
|
||||
{'attr1': 'val1', 'attr2': 'val2'},
|
||||
qe.NotFound,
|
||||
qe.NeutronClientException]
|
||||
res._show_resource = mock_show_resource
|
||||
nclientplugin = neutron.NeutronClientPlugin(mock.MagicMock())
|
||||
res.client_plugin = mock.Mock(return_value=nclientplugin)
|
||||
|
||||
self.assertEqual({'attr1': 'val1', 'attr2': 'val2'},
|
||||
res._resolve_attribute('show'))
|
||||
self.assertEqual('val2', res._resolve_attribute('attr2'))
|
||||
self.assertRaises(KeyError, res._resolve_attribute, 'attr3')
|
||||
self.assertIsNone(res._resolve_attribute('attr2'))
|
||||
res.resource_id = None
|
||||
self.assertIsNone(res._resolve_attribute('show'))
|
||||
|
||||
|
||||
class GetSecGroupUuidTest(common.HeatTestCase):
|
||||
|
|
Loading…
Reference in New Issue