Merge "Add validate for external resources."
This commit is contained in:
commit
9f69b3feef
|
@ -858,6 +858,23 @@ class Resource(object):
|
||||||
runner = scheduler.TaskRunner(self.adopt, **adopt_data)
|
runner = scheduler.TaskRunner(self.adopt, **adopt_data)
|
||||||
runner(timeout=timeout)
|
runner(timeout=timeout)
|
||||||
|
|
||||||
|
def _validate_external_resource(self, external_id):
|
||||||
|
if self.entity:
|
||||||
|
try:
|
||||||
|
self.resource_id = external_id
|
||||||
|
self._show_resource()
|
||||||
|
except Exception as ex:
|
||||||
|
LOG.debug("%s", 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': external_id,
|
||||||
|
'entity': self.entity}
|
||||||
|
raise exception.StackValidationFailed(
|
||||||
|
message="%s" % error_message)
|
||||||
|
raise
|
||||||
|
|
||||||
@scheduler.wrappertask
|
@scheduler.wrappertask
|
||||||
def create(self):
|
def create(self):
|
||||||
"""Create the resource.
|
"""Create the resource.
|
||||||
|
@ -867,6 +884,8 @@ class Resource(object):
|
||||||
"""
|
"""
|
||||||
external = self.t.external_id()
|
external = self.t.external_id()
|
||||||
if external is not None:
|
if external is not None:
|
||||||
|
self._validate_external_resource(external_id=external)
|
||||||
|
|
||||||
yield self._do_action(self.ADOPT,
|
yield self._do_action(self.ADOPT,
|
||||||
resource_data={'resource_id': external})
|
resource_data={'resource_id': external})
|
||||||
self.check()
|
self.check()
|
||||||
|
|
|
@ -344,6 +344,26 @@ class ResourceTest(common.HeatTestCase):
|
||||||
self.assertEqual((res.CHECK, res.COMPLETE), res.state)
|
self.assertEqual((res.CHECK, res.COMPLETE), res.state)
|
||||||
self.assertEqual('f00d', res.resource_id)
|
self.assertEqual('f00d', res.resource_id)
|
||||||
|
|
||||||
|
def test_create_from_external_not_found(self):
|
||||||
|
external_id = 'f00d'
|
||||||
|
tmpl = rsrc_defn.ResourceDefinition(
|
||||||
|
'test_resource', 'GenericResourceType',
|
||||||
|
external_id=external_id)
|
||||||
|
res = generic_rsrc.GenericResource('test_resource', tmpl, self.stack)
|
||||||
|
res.entity = 'test'
|
||||||
|
res.client = mock.Mock()
|
||||||
|
res.client_plugin = mock.Mock()
|
||||||
|
test_obj = mock.Mock()
|
||||||
|
res.client().test = test_obj
|
||||||
|
test_obj.get.side_effect = exception.EntityNotFound
|
||||||
|
|
||||||
|
e = self.assertRaises(exception.StackValidationFailed,
|
||||||
|
scheduler.TaskRunner(res.create))
|
||||||
|
message = ("Invalid external resource: Resource %(external_id)s not "
|
||||||
|
"found in %(entity)s.") % {'external_id': external_id,
|
||||||
|
'entity': res.entity}
|
||||||
|
self.assertEqual(message, six.text_type(e))
|
||||||
|
|
||||||
def test_updated_from_external(self):
|
def test_updated_from_external(self):
|
||||||
tmpl = rsrc_defn.ResourceDefinition('test_resource',
|
tmpl = rsrc_defn.ResourceDefinition('test_resource',
|
||||||
'GenericResourceType')
|
'GenericResourceType')
|
||||||
|
|
Loading…
Reference in New Issue