From 04701a275f9712865bc5b7ea458bb7123f3a34d7 Mon Sep 17 00:00:00 2001 From: Steven Dake Date: Wed, 12 Sep 2012 15:12:50 -0700 Subject: [PATCH] Make physical resource names unique based upon stack name Some templates use the same resource name when registering with nova. Nova will not allow mulitple resource names to register with the same name in all cases, and in those it does, it often becomes confused (in the case of EIP). This patch creates a dot notation For the LB test, an example of the resources would be: teststack.LoadBalancer.LB_instance teststack.DatabaseServer.MySqlDatabaseServer teststack.WikiServerOne Fixes Issue #160 Fixes Issue #136 Thanks to asalkeld@redhat.com for helping sort out the unit test cases. Change-Id: I14f4551feb41c7f98caa30dd98f997da6d00c467 Signed-off-by: Steven Dake --- heat/engine/instance.py | 3 ++- heat/engine/resources.py | 3 +++ heat/engine/s3.py | 2 +- heat/engine/security_group.py | 3 ++- heat/engine/stack.py | 2 +- heat/engine/user.py | 3 ++- heat/engine/volume.py | 4 ++-- heat/tests/functional/test_WordPress_With_LB.py | 5 +++-- heat/tests/functional/util.py | 4 ++-- heat/tests/test_engine_manager.py | 2 +- heat/tests/test_instance.py | 2 +- 11 files changed, 20 insertions(+), 13 deletions(-) diff --git a/heat/engine/instance.py b/heat/engine/instance.py index 74f05e3c..9b456e6c 100644 --- a/heat/engine/instance.py +++ b/heat/engine/instance.py @@ -230,7 +230,8 @@ class Instance(resources.Resource): scheduler_hints = None server_userdata = self._build_userdata(userdata) - server = self.nova().servers.create(name=self.name, image=image_id, + server = self.nova().servers.create(name=self.physical_resource_name(), + image=image_id, flavor=flavor_id, key_name=key_name, security_groups=security_groups, diff --git a/heat/engine/resources.py b/heat/engine/resources.py index 46717af3..0caa20ab 100644 --- a/heat/engine/resources.py +++ b/heat/engine/resources.py @@ -310,6 +310,9 @@ class Resource(object): self.state_set(self.UPDATE_COMPLETE) return result + def physical_resource_name(self): + return '%s.%s' % (self.stack.name, self.name) + def validate(self): logger.info('Validating %s' % str(self)) diff --git a/heat/engine/s3.py b/heat/engine/s3.py index f266f93d..5b8c5c71 100644 --- a/heat/engine/s3.py +++ b/heat/engine/s3.py @@ -61,7 +61,7 @@ class S3Bucket(Resource): def handle_create(self): """Create a bucket.""" - container = 'heat-%s-%s' % (self.name, + container = 'heat-%s-%s' % (self.resource_physical_name(), binascii.hexlify(os.urandom(10))) headers = {} logger.debug('S3Bucket create container %s with headers %s' % diff --git a/heat/engine/security_group.py b/heat/engine/security_group.py index 91301a63..b9986cdc 100644 --- a/heat/engine/security_group.py +++ b/heat/engine/security_group.py @@ -45,7 +45,8 @@ class SecurityGroup(Resource): break if not sec: - sec = self.nova().security_groups.create(self.name, + sec = self.nova().security_groups.create( + self.physical_resource_name(), self.properties['GroupDescription']) self.instance_id_set(sec.id) diff --git a/heat/engine/stack.py b/heat/engine/stack.py index 4642b94e..a3af810c 100644 --- a/heat/engine/stack.py +++ b/heat/engine/stack.py @@ -63,7 +63,7 @@ class Stack(Resource): params = parser.Parameters(self.name, template, self._params()) self._nested = parser.Stack(self.context, - self.name, + self.physical_resource_name(), template, params) diff --git a/heat/engine/user.py b/heat/engine/user.py index e735fbe9..13abd9e6 100644 --- a/heat/engine/user.py +++ b/heat/engine/user.py @@ -49,7 +49,8 @@ class User(Resource): passwd = self.properties['LoginProfile']['Password'] tenant_id = self.context.tenant_id - user = self.keystone().users.create(self.name, passwd, + user = self.keystone().users.create(self.physical_resource_name(), + passwd, '%s@heat-api.org' % self.name, tenant_id=tenant_id, enabled=True) diff --git a/heat/engine/volume.py b/heat/engine/volume.py index 8330fff8..7b075994 100644 --- a/heat/engine/volume.py +++ b/heat/engine/volume.py @@ -35,8 +35,8 @@ class Volume(Resource): def handle_create(self): vol = self.nova('volume').volumes.create(self.properties['Size'], - display_name=self.name, - display_description=self.name) + display_name=self.physical_resource_name(), + display_description=self.physical_resource_name()) while vol.status == 'creating': eventlet.sleep(1) diff --git a/heat/tests/functional/test_WordPress_With_LB.py b/heat/tests/functional/test_WordPress_With_LB.py index 7f11fa13..7c4af4a4 100644 --- a/heat/tests/functional/test_WordPress_With_LB.py +++ b/heat/tests/functional/test_WordPress_With_LB.py @@ -34,8 +34,9 @@ class WordPressWithLBFunctionalTest(unittest.TestCase): stack_paramstr) self.WikiServerOne = util.Instance('WikiServerOne') - self.LBInstance = util.Instance('LB_instance') - self.MySqlDatabaseServer = util.Instance('MySqlDatabaseServer') + self.LBInstance = util.Instance('LoadBalancer.LB_instance') + self.MySqlDatabaseServer = util.Instance( + 'DatabaseServer.MySqlDatabaseServer') self.WikiServerOne.check_cfntools() self.LBInstance.check_cfntools() diff --git a/heat/tests/functional/util.py b/heat/tests/functional/util.py index c98e9d8c..b296ff10 100644 --- a/heat/tests/functional/util.py +++ b/heat/tests/functional/util.py @@ -42,7 +42,7 @@ from keystoneclient.v2_0 import client class Instance(object): def __init__(self, instance_name): - self.name = instance_name + self.name = 'teststack.%s' % instance_name # during nose test execution this file will be imported even if # the unit tag was specified @@ -80,7 +80,7 @@ class Instance(object): while ip is None: servers = self.novaclient.servers.list() for server in servers: - if server.name == instance_name: + if server.name == self.name: address = server.addresses if address: ip = address.items()[0][1][0]['addr'] diff --git a/heat/tests/test_engine_manager.py b/heat/tests/test_engine_manager.py index 6e2b13d8..ed637906 100644 --- a/heat/tests/test_engine_manager.py +++ b/heat/tests/test_engine_manager.py @@ -77,7 +77,7 @@ def setup_mocks(mocks, stack): server_userdata = instance._build_userdata(instance.properties['UserData']) mocks.StubOutWithMock(fc.servers, 'create') fc.servers.create(image=744, flavor=3, key_name='test', - name='WebServer', security_groups=None, + name='%s.WebServer' % stack.name, security_groups=None, userdata=server_userdata, scheduler_hints=None, meta=None).AndReturn(fc.servers.list()[-1]) diff --git a/heat/tests/test_instance.py b/heat/tests/test_instance.py index 6afde1f1..b9ad04fd 100644 --- a/heat/tests/test_instance.py +++ b/heat/tests/test_instance.py @@ -75,7 +75,7 @@ class instancesTest(unittest.TestCase): instance.t['Properties']['UserData']) self.m.StubOutWithMock(self.fc.servers, 'create') self.fc.servers.create(image=1, flavor=1, key_name='test', - name='test_resource_name', security_groups=None, + name='test_stack.test_resource_name', security_groups=None, userdata=server_userdata, scheduler_hints=None, meta=None).AndReturn(self.fc.servers.list()[1]) self.m.ReplayAll() -- 2.45.2