From: Vijendar Komalla Date: Mon, 29 Jul 2013 22:19:50 +0000 (-0500) Subject: Rackspace database resource output is null X-Git-Tag: 2014.1~307 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=2ffb44e0aaffe876deaabed408c2a823151c8641;p=openstack-build%2Fheat-build.git Rackspace database resource output is null current implementation of rackspace database resource _resolve_attribute method assumes that clouddatabase object's hostname and href are set to correct values and just returns them, but that assumption is not correct. With this change, hostname/href is retrived if it was not set already. Fixes Bug #1204601 Change-Id: Ifca44237e20210b5ff1fc1b28f1f8408f5672ae4 --- diff --git a/heat/engine/resources/rackspace/clouddatabase.py b/heat/engine/resources/rackspace/clouddatabase.py index 2c7e42bd..c01f4fa3 100644 --- a/heat/engine/resources/rackspace/clouddatabase.py +++ b/heat/engine/resources/rackspace/clouddatabase.py @@ -215,11 +215,35 @@ class CloudDBInstance(rackspace_resource.RackspaceResource): 'databases.' % missing_db} return + def _hostname(self): + if self.hostname is None and self.resource_id is not None: + dbinstance = self.cloud_db().get(self.resource_id) + self.hostname = dbinstance.hostname + + return self.hostname + + def _href(self): + if self.href is None and self.resource_id is not None: + dbinstance = self.cloud_db().get(self.resource_id) + self.href = self._gethref(dbinstance) + + return self.href + + def _gethref(self, dbinstance): + if dbinstance is None or dbinstance.links is None: + return None + + for link in dbinstance.links: + if link['rel'] == 'self': + return dbinstance.links[0]['href'] + def _resolve_attribute(self, name): if name == 'hostname': - return self.hostname + return self._hostname() elif name == 'href': - return self.href + return self._href() + else: + return None # pyrax module is required to work with Rackspace cloud database provider. diff --git a/heat/tests/test_clouddatabase.py b/heat/tests/test_clouddatabase.py index 4d7fbbb4..8db5bf57 100644 --- a/heat/tests/test_clouddatabase.py +++ b/heat/tests/test_clouddatabase.py @@ -146,6 +146,19 @@ class CloudDBInstanceTest(HeatTestCase): self.assertRaises(exception.ResourceNotFound, instance.handle_delete) self.m.VerifyAll() + def test_attribute_not_found(self): + instance = self._setup_test_clouddbinstance('dbinstance_create') + fake_client = self.m.CreateMockAnything() + instance.cloud_db().AndReturn(fake_client) + fakedbinstance = FakeDBInstance() + fake_client.create('Test', + flavor='1GB', + volume='30').AndReturn(fakedbinstance) + self.m.ReplayAll() + instance.handle_create() + self.assertEqual(instance._resolve_attribute('invalid-attrib'), None) + self.m.VerifyAll() + def test_clouddbinstance_delete(self): instance = self._setup_test_clouddbinstance('dbinstance_delete') fake_client = self.m.CreateMockAnything()