Merge "Fix validate_external()"

This commit is contained in:
Jenkins 2017-01-15 06:27:57 +00:00 committed by Gerrit Code Review
commit 379639ec93
2 changed files with 10 additions and 10 deletions

View File

@ -886,17 +886,17 @@ class Resource(object):
runner(timeout=timeout, progress_callback=progress_callback)
def validate_external(self):
if self.external_id is not None and self.entity:
if self.external_id is not None:
try:
self.resource_id = self.external_id
self._show_resource()
except Exception as ex:
if self.client_plugin().is_not_found(ex):
error_message = _("Invalid external resource: Resource "
"%(external_id)s not found in "
"%(entity)s.") % {
'external_id': self.external_id,
'entity': self.entity}
error_message = (_("Invalid external resource: Resource "
"%(external_id)s (%(type)s) can not "
"be found.") %
{'external_id': self.external_id,
'type': self.type()})
raise exception.StackValidationFailed(
message="%s" % error_message)
raise

View File

@ -352,16 +352,16 @@ class ResourceTest(common.HeatTestCase):
'test_resource', 'GenericResourceType',
external_id=external_id)
res = generic_rsrc.GenericResource('test_resource', tmpl, self.stack)
res.entity = 'test'
res.client_plugin = mock.Mock()
self.patchobject(res.client_plugin, 'is_not_found',
return_value=True)
self.patchobject(res, '_show_resource', side_effect=Exception())
e = self.assertRaises(exception.StackValidationFailed,
res.validate_external)
message = ("Invalid external resource: Resource %(external_id)s not "
"found in %(entity)s.") % {'external_id': external_id,
'entity': res.entity}
message = (("Invalid external resource: Resource %(external_id)s "
"(%(type)s) can not be found.") %
{'external_id': external_id,
'type': res.type()})
self.assertEqual(message, six.text_type(e))
def test_updated_from_external(self):