]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Add an identify_stack RPC call
authorZane Bitter <zbitter@redhat.com>
Wed, 5 Sep 2012 19:51:25 +0000 (21:51 +0200)
committerZane Bitter <zbitter@redhat.com>
Wed, 5 Sep 2012 19:53:10 +0000 (21:53 +0200)
This call converts a stack name into a fully-qualified stack identifier.

This allows us to, e.g., add support for keeping deleted stacks around in
the database while still allowing stack names to be reused, since the
deleted stacks can be referenced using this ID.

Change-Id: Ide19841a92a25d2f6172f19c2627d24ab6d2fd63
Signed-off-by: Zane Bitter <zbitter@redhat.com>
heat/engine/manager.py
heat/engine/rpcapi.py
heat/tests/test_engine_manager.py

index a69564a1a55c0c8eff8d7e7a8190b89298708bf6..65a0d85ed7c80b8a2eac93ffd856b6cb368e6bbc 100644 (file)
@@ -61,6 +61,22 @@ class EngineManager(manager.Manager):
         """Load configuration options and connect to the hypervisor."""
         pass
 
+    def identify_stack(self, context, stack_name):
+        """
+        The identify_stack method returns the full stack identifier for a
+        single, live stack given the stack name.
+        arg1 -> RPC context.
+        arg2 -> Name of the stack to look up.
+        """
+        auth.authenticate(context)
+
+        s = db_api.stack_get_by_name(context, stack_name)
+        if s:
+            stack = parser.Stack.load(context, s.id)
+            return stack.identifier()
+        else:
+            raise AttributeError('Unknown stack name')
+
     def show_stack(self, context, stack_name, params):
         """
         The show_stack method returns the attributes of one stack.
index 3586b9c55d73dd3e83a0022962c90f40e327d4ed..b731e7b0141fefc922f44e9e4155583c4e6ab2f3 100644 (file)
@@ -57,6 +57,21 @@ class EngineAPI(heat.openstack.common.rpc.proxy.RpcProxy):
                 topic=FLAGS.engine_topic,
                 default_version=self.BASE_RPC_API_VERSION)
 
+    def identify_stack(self, ctxt, stack_name):
+        """
+        The identify_stack method returns the full stack identifier for a
+        single, live stack given the stack name.
+
+        :param ctxt: RPC context.
+        :param stack_name: Name of the stack you want to see,
+                           or None to see all
+        """
+        return self.call(ctxt, self.make_msg('identify_stack',
+                                             stack_name=stack_name,
+                                             topic=_engine_topic(self.topic,
+                                                                 ctxt,
+                                                                 None)))
+
     def show_stack(self, ctxt, stack_name, params):
         """
         The show_stack method returns the attributes of one stack.
index e853f1a0aab5ea8363cfd5d1e7825a83999ff2ce..59e827916a1659dccb37f9e1376c251f08821704 100644 (file)
@@ -142,6 +142,7 @@ class stackManagerTest(unittest.TestCase):
         stack.store()
         stack.create()
         cls.stack = stack
+        cls.stack_identity = stack.identifier()
 
         m.UnsetStubs()
 
@@ -169,6 +170,14 @@ class stackManagerTest(unittest.TestCase):
     def tearDown(self):
         self.m.UnsetStubs()
 
+    def test_stack_identify(self):
+        identity = self.man.identify_stack(self.ctx, self.stack_name)
+        self.assertEqual(identity, self.stack_identity)
+
+    def test_stack_identify_nonexist(self):
+        self.assertRaises(AttributeError, self.man.identify_stack,
+                          self.ctx, 'wibble')
+
     def test_stack_event_list(self):
         el = self.man.list_events(self.ctx, self.stack_name, {})