Add show_resource function to Trove resources (7)

AWS resources will not be changed as they do not support additional
attributes. So 'show' attribute will be presented in their schemas, but
will return always None.

This patch adds show_resource method for heat (trove) resources:
 - database
 - cluster

Change-Id: Ib87464dbb78c369c0f81659c36043fb658fa4fe6
This commit is contained in:
Oleksii Chuprykov 2015-07-31 14:43:17 +03:00
parent 02275f8901
commit 3fdaed1779
4 changed files with 20 additions and 0 deletions

View File

@ -276,6 +276,8 @@ class OSDBInstance(resource.Resource):
default_client_name = 'trove' default_client_name = 'trove'
entity = 'instances'
def __init__(self, name, json_snippet, stack): def __init__(self, name, json_snippet, stack):
super(OSDBInstance, self).__init__(name, json_snippet, stack) super(OSDBInstance, self).__init__(name, json_snippet, stack)
self._href = None self._href = None

View File

@ -131,6 +131,8 @@ class TroveCluster(resource.Resource):
default_client_name = 'trove' default_client_name = 'trove'
entity = 'clusters'
def _cluster_name(self): def _cluster_name(self):
return self.properties[self.NAME] or self.physical_resource_name() return self.properties[self.NAME] or self.physical_resource_name()

View File

@ -80,6 +80,7 @@ class FakeDBInstance(object):
"rel": "self"}] "rel": "self"}]
self.resource_id = 12345 self.resource_id = 12345
self.status = 'ACTIVE' self.status = 'ACTIVE'
self.to_dict = lambda: {'attr': 'val'}
def delete(self): def delete(self):
pass pass
@ -738,3 +739,16 @@ class OSDBInstanceTest(common.HeatTestCase):
scheduler.TaskRunner(instance.create)() scheduler.TaskRunner(instance.create)()
self.assertEqual((instance.CREATE, instance.COMPLETE), instance.state) self.assertEqual((instance.CREATE, instance.COMPLETE), instance.state)
self.m.VerifyAll() self.m.VerifyAll()
def test_show_resource(self):
fake_dbinstance = FakeDBInstance()
t = template_format.parse(db_template)
instance = self._setup_test_clouddbinstance('dbinstance_test', t)
instance.resource_id = 12345
trove.TroveClientPlugin._create().AndReturn(self.fc)
self.m.StubOutWithMock(self.fc, 'instances')
self.m.StubOutWithMock(self.fc.instances, 'get')
self.fc.instances.get(12345).AndReturn(fake_dbinstance)
self.m.ReplayAll()
self.assertEqual({'attr': 'val'}, instance.FnGetAtt('show'))
self.m.VerifyAll()

View File

@ -53,6 +53,7 @@ class FakeTroveCluster(object):
{'id': '416b0b16-ba55-4302-bbd3-ff566032e1c1', 'status': status}, {'id': '416b0b16-ba55-4302-bbd3-ff566032e1c1', 'status': status},
{'id': '965ef811-7c1d-47fc-89f2-a89dfdd23ef2', 'status': status}, {'id': '965ef811-7c1d-47fc-89f2-a89dfdd23ef2', 'status': status},
{'id': '3642f41c-e8ad-4164-a089-3891bf7f2d2b', 'status': status}] {'id': '3642f41c-e8ad-4164-a089-3891bf7f2d2b', 'status': status}]
self.to_dict = lambda: {'attr': 'val'}
def delete(self): def delete(self):
pass pass
@ -129,6 +130,7 @@ class TroveClusterTest(common.HeatTestCase):
'965ef811-7c1d-47fc-89f2-a89dfdd23ef2', '965ef811-7c1d-47fc-89f2-a89dfdd23ef2',
'3642f41c-e8ad-4164-a089-3891bf7f2d2b'], '3642f41c-e8ad-4164-a089-3891bf7f2d2b'],
tc.FnGetAtt('instances')) tc.FnGetAtt('instances'))
self.assertEqual({'attr': 'val'}, tc.FnGetAtt('show'))
def test_delete(self): def test_delete(self):
tc = self._create_resource('cluster', self.rsrc_defn, self.stack) tc = self._create_resource('cluster', self.rsrc_defn, self.stack)