From 3d173834b18fb84213a6ed91f96c086f1262e9fe Mon Sep 17 00:00:00 2001 From: Kanagaraj Manickam Date: Tue, 17 May 2016 12:41:29 +0530 Subject: [PATCH] Migrate nova_instance to physical_resource_id migrate to physical_resource_id from nova_instance at application layer, while the db schema still holds nova_instance label. This is the first phase of migration. Next patch will take care of db schema. Change-Id: I6ebbe3d71d5fb9a7dd3c68ff13777982eb5bbbef Partial-bug: #1346742 --- heat/db/sqlalchemy/api.py | 2 +- heat/db/sqlalchemy/models.py | 3 ++- heat/engine/resource.py | 10 ++++++---- heat/objects/resource.py | 2 +- heat/tests/convergence/framework/testutils.py | 2 +- heat/tests/db/test_sqlalchemy_api.py | 6 +++--- heat/tests/test_resource.py | 2 +- 7 files changed, 15 insertions(+), 12 deletions(-) diff --git a/heat/db/sqlalchemy/api.py b/heat/db/sqlalchemy/api.py index 2ae1bf67a3..e0176c0eab 100644 --- a/heat/db/sqlalchemy/api.py +++ b/heat/db/sqlalchemy/api.py @@ -158,7 +158,7 @@ def resource_get_by_name_and_stack(context, resource_name, stack_id): def resource_get_by_physical_resource_id(context, physical_resource_id): results = (model_query(context, models.Resource) - .filter_by(nova_instance=physical_resource_id) + .filter_by(physical_resource_id=physical_resource_id) .all()) for result in results: diff --git a/heat/db/sqlalchemy/models.py b/heat/db/sqlalchemy/models.py index 76e41d1d4f..8700f51232 100644 --- a/heat/db/sqlalchemy/models.py +++ b/heat/db/sqlalchemy/models.py @@ -280,7 +280,8 @@ class Resource(BASE, HeatBase, StateAware): default=lambda: str(uuid.uuid4()), unique=True) name = sqlalchemy.Column('name', sqlalchemy.String(255)) - nova_instance = sqlalchemy.Column('nova_instance', sqlalchemy.String(255)) + physical_resource_id = sqlalchemy.Column('nova_instance', + sqlalchemy.String(255)) # odd name as "metadata" is reserved rsrc_metadata = sqlalchemy.Column('rsrc_metadata', types.Json) diff --git a/heat/engine/resource.py b/heat/engine/resource.py index e6c89fcfe6..a9f74d4315 100644 --- a/heat/engine/resource.py +++ b/heat/engine/resource.py @@ -246,7 +246,7 @@ class Resource(object): def _load_data(self, resource): """Load the resource state from its DB representation.""" - self.resource_id = resource.nova_instance + self.resource_id = resource.physical_resource_id self.action = resource.action self.status = resource.status self.status_reason = resource.status_reason @@ -1499,7 +1499,9 @@ class Resource(object): if self.id is not None: try: resource_objects.Resource.update_by_id( - self.context, self.id, {'nova_instance': self.resource_id}) + self.context, + self.id, + {'physical_resource_id': self.resource_id}) except Exception as ex: LOG.warning(_LW('db error %s'), ex) @@ -1516,7 +1518,7 @@ class Resource(object): 'status': self.status, 'status_reason': self.status_reason, 'stack_id': self.stack.id, - 'nova_instance': self.resource_id, + 'physical_resource_id': self.resource_id, 'name': self.name, 'rsrc_metadata': metadata, 'properties_data': properties_data, @@ -1568,7 +1570,7 @@ class Resource(object): 'replaces': self.replaces, 'replaced_by': self.replaced_by, 'current_template_id': self.current_template_id, - 'nova_instance': self.resource_id, + 'physical_resource_id': self.resource_id, 'root_stack_id': self.root_stack_id } if prev_action == self.INIT: diff --git a/heat/objects/resource.py b/heat/objects/resource.py index f32633c40a..526450e3e9 100644 --- a/heat/objects/resource.py +++ b/heat/objects/resource.py @@ -53,7 +53,7 @@ class Resource( 'stack_id': fields.StringField(), 'created_at': fields.DateTimeField(read_only=True), 'updated_at': fields.DateTimeField(nullable=True), - 'nova_instance': fields.StringField(nullable=True), + 'physical_resource_id': fields.StringField(nullable=True), 'name': fields.StringField(nullable=True), 'status': fields.StringField(nullable=True), 'status_reason': fields.StringField(nullable=True), diff --git a/heat/tests/convergence/framework/testutils.py b/heat/tests/convergence/framework/testutils.py index 90a6aa9047..2d4520c8bb 100644 --- a/heat/tests/convergence/framework/testutils.py +++ b/heat/tests/convergence/framework/testutils.py @@ -39,7 +39,7 @@ def verify(test, reality, tmpl): elif isinstance(prop_def, scenario_template.GetRes): targs = reality.resources_by_logical_name(prop_def.target_name) - test.assertEqual(targs[0].nova_instance, real_value) + test.assertEqual(targs[0].physical_resource_id, real_value) else: test.assertEqual(prop_def, real_value) diff --git a/heat/tests/db/test_sqlalchemy_api.py b/heat/tests/db/test_sqlalchemy_api.py index 4e03108932..fa2e5c8106 100644 --- a/heat/tests/db/test_sqlalchemy_api.py +++ b/heat/tests/db/test_sqlalchemy_api.py @@ -1413,7 +1413,7 @@ def create_stack(ctx, template, user_creds, **kwargs): def create_resource(ctx, stack, **kwargs): values = { 'name': 'test_resource_name', - 'nova_instance': UUID1, + 'physical_resource_id': UUID1, 'action': 'create', 'status': 'complete', 'status_reason': 'create_complete', @@ -2113,7 +2113,7 @@ class DBAPIResourceTest(common.HeatTestCase): ret_res = db_api.resource_get(self.ctx, res.id) self.assertIsNotNone(ret_res) self.assertEqual('test_resource_name', ret_res.name) - self.assertEqual(UUID1, ret_res.nova_instance) + self.assertEqual(UUID1, ret_res.physical_resource_id) self.assertEqual('create', ret_res.action) self.assertEqual('complete', ret_res.status) self.assertEqual('create_complete', ret_res.status_reason) @@ -2148,7 +2148,7 @@ class DBAPIResourceTest(common.HeatTestCase): ret_res = db_api.resource_get_by_physical_resource_id(self.ctx, UUID1) self.assertIsNotNone(ret_res) - self.assertEqual(UUID1, ret_res.nova_instance) + self.assertEqual(UUID1, ret_res.physical_resource_id) self.assertIsNone(db_api.resource_get_by_physical_resource_id(self.ctx, UUID2)) diff --git a/heat/tests/test_resource.py b/heat/tests/test_resource.py index 5959e87587..e3570ddc3e 100644 --- a/heat/tests/test_resource.py +++ b/heat/tests/test_resource.py @@ -537,7 +537,7 @@ class ResourceTest(common.HeatTestCase): self.assertEqual(new_id, res.replaced_by) self.assertEqual(res.id, new_res.replaces) - self.assertIsNone(new_res.nova_instance) + self.assertIsNone(new_res.physical_resource_id) self.assertEqual(new_tmpl_id, new_res.current_template_id) def test_parsed_template(self):