diff --git a/heat/db/api.py b/heat/db/api.py index 70aab59a83..3f81ac60f7 100644 --- a/heat/db/api.py +++ b/heat/db/api.py @@ -1582,7 +1582,7 @@ def snapshot_delete(context, snapshot_id): @context_manager.reader -def snapshot_get_all(context, stack_id): +def snapshot_get_all_by_stack(context, stack_id): return context.session.query(models.Snapshot).filter_by( stack_id=stack_id, tenant=context.tenant_id) diff --git a/heat/engine/service.py b/heat/engine/service.py index 9019ddbea1..34f9544717 100644 --- a/heat/engine/service.py +++ b/heat/engine/service.py @@ -2198,7 +2198,7 @@ class EngineService(service.ServiceBase): @context.request_context def stack_list_snapshots(self, cnxt, stack_identity): s = self._get_stack(cnxt, stack_identity) - data = snapshot_object.Snapshot.get_all(cnxt, s.id) + data = snapshot_object.Snapshot.get_all_by_stack(cnxt, s.id) return [api.format_snapshot(snapshot) for snapshot in data] @context.request_context diff --git a/heat/engine/stack.py b/heat/engine/stack.py index 912b3c1ac4..caad7978e9 100644 --- a/heat/engine/stack.py +++ b/heat/engine/stack.py @@ -2132,7 +2132,8 @@ class Stack(collections.abc.Mapping): def delete_all_snapshots(self): """Remove all snapshots for this stack.""" - snapshots = snapshot_object.Snapshot.get_all(self.context, self.id) + snapshots = snapshot_object.Snapshot.get_all_by_stack( + self.context, self.id) for snapshot in snapshots: self.delete_snapshot(snapshot) snapshot_object.Snapshot.delete(self.context, snapshot.id) diff --git a/heat/objects/snapshot.py b/heat/objects/snapshot.py index 23d569a400..7e90def413 100644 --- a/heat/objects/snapshot.py +++ b/heat/objects/snapshot.py @@ -70,6 +70,7 @@ class Snapshot( db_api.snapshot_delete(context, snapshot_id) @classmethod - def get_all(cls, context, stack_id): + def get_all_by_stack(cls, context, stack_id): return [cls._from_db_object(context, cls(), db_snapshot) - for db_snapshot in db_api.snapshot_get_all(context, stack_id)] + for db_snapshot + in db_api.snapshot_get_all_by_stack(context, stack_id)] diff --git a/heat/tests/db/test_sqlalchemy_api.py b/heat/tests/db/test_sqlalchemy_api.py index 5689f2e5e4..337190cfbd 100644 --- a/heat/tests/db/test_sqlalchemy_api.py +++ b/heat/tests/db/test_sqlalchemy_api.py @@ -1421,7 +1421,7 @@ class SqlAlchemyTest(common.HeatTestCase): self.assertIn(snapshot_id, str(err)) - def test_snapshot_get_all(self): + def test_snapshot_get_all_by_stack(self): template = create_raw_template(self.ctx) user_creds = create_user_creds(self.ctx) stack = create_stack(self.ctx, template, user_creds) @@ -1429,7 +1429,7 @@ class SqlAlchemyTest(common.HeatTestCase): 'stack_id': stack.id} snapshot = db_api.snapshot_create(self.ctx, values) self.assertIsNotNone(snapshot) - [snapshot] = db_api.snapshot_get_all(self.ctx, stack.id) + [snapshot] = db_api.snapshot_get_all_by_stack(self.ctx, stack.id) self.assertIsNotNone(snapshot) self.assertEqual(values['tenant'], snapshot.tenant) self.assertEqual(values['status'], snapshot.status) diff --git a/heat/tests/test_convg_stack.py b/heat/tests/test_convg_stack.py index c001af1e06..722da9a3ac 100644 --- a/heat/tests/test_convg_stack.py +++ b/heat/tests/test_convg_stack.py @@ -549,14 +549,14 @@ class StackConvergenceCreateUpdateDeleteTest(common.HeatTestCase): # Ensure that snapshot is not deleted on stack update stack.converge_stack(template=stack.t, action=stack.UPDATE) - db_snapshot_obj = snapshot_objects.Snapshot.get_all( + db_snapshot_obj = snapshot_objects.Snapshot.get_all_by_stack( stack.context, stack.id) self.assertEqual('fake_snapshot', db_snapshot_obj[0].name) self.assertEqual(stack.id, db_snapshot_obj[0].stack_id) # Ensure that snapshot is deleted on stack delete stack.converge_stack(template=stack.t, action=stack.DELETE) - self.assertEqual([], snapshot_objects.Snapshot.get_all( + self.assertEqual([], snapshot_objects.Snapshot.get_all_by_stack( stack.context, stack.id)) self.assertTrue(mock_cr.called) diff --git a/heat/tests/test_stack_delete.py b/heat/tests/test_stack_delete.py index 51fb26a0ce..d509ed2bb3 100644 --- a/heat/tests/test_stack_delete.py +++ b/heat/tests/test_stack_delete.py @@ -73,7 +73,7 @@ class StackTest(common.HeatTestCase): } snapshot_object.Snapshot.create(self.ctx, snapshot_fake) - self.assertIsNotNone(snapshot_object.Snapshot.get_all( + self.assertIsNotNone(snapshot_object.Snapshot.get_all_by_stack( self.ctx, stack_id)) self.stack.delete() @@ -81,7 +81,7 @@ class StackTest(common.HeatTestCase): self.assertIsNone(db_s) self.assertEqual((stack.Stack.DELETE, stack.Stack.COMPLETE), self.stack.state) - self.assertEqual([], snapshot_object.Snapshot.get_all( + self.assertEqual([], snapshot_object.Snapshot.get_all_by_stack( self.ctx, stack_id)) def test_delete_with_snapshot_after_stack_add_resource(self): @@ -104,7 +104,7 @@ class StackTest(common.HeatTestCase): } snapshot_object.Snapshot.create(self.ctx, snapshot_fake) - self.assertIsNotNone(snapshot_object.Snapshot.get_all( + self.assertIsNotNone(snapshot_object.Snapshot.get_all_by_stack( self.ctx, stack_id)) new_tmpl = {'heat_template_version': 'queens', @@ -121,7 +121,7 @@ class StackTest(common.HeatTestCase): self.assertIsNone(db_s) self.assertEqual((stack.Stack.DELETE, stack.Stack.COMPLETE), self.stack.state) - self.assertEqual([], snapshot_object.Snapshot.get_all( + self.assertEqual([], snapshot_object.Snapshot.get_all_by_stack( self.ctx, stack_id)) def test_delete_user_creds(self):