From ea0e957978632b55ea48864f216e1b0b7181c6f7 Mon Sep 17 00:00:00 2001 From: Steve Baker Date: Mon, 5 Aug 2013 09:02:40 +1200 Subject: [PATCH] Custom Stack get method to avoid lookup redirects Change-Id: I15dd4e9168cba6fd05371fed097d52cbf33cb15d --- heatclient/tests/test_stacks.py | 6 ++++++ heatclient/v1/stacks.py | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/heatclient/tests/test_stacks.py b/heatclient/tests/test_stacks.py index 722a9eb8..f2a4b961 100644 --- a/heatclient/tests/test_stacks.py +++ b/heatclient/tests/test_stacks.py @@ -53,3 +53,9 @@ class StackOperationsTest(testtools.TestCase): stack = Stack(manager, {'id': 'abcd1234'}) stack.delete() manager.delete.assert_called_once_with('abcd1234') + + def test_get_stack(self): + manager = MagicMock() + stack = Stack(manager, {'id': 'abcd1234', 'stack_name': 'the_stack'}) + stack.get() + manager.get.assert_called_once_with('the_stack/abcd1234') diff --git a/heatclient/v1/stacks.py b/heatclient/v1/stacks.py index dabe8dd2..b9e76fc4 100644 --- a/heatclient/v1/stacks.py +++ b/heatclient/v1/stacks.py @@ -33,6 +33,16 @@ class Stack(base.Resource): def data(self, **kwargs): return self.manager.data(self, **kwargs) + def get(self): + # set_loaded() first ... so if we have to bail, we know we tried. + self.set_loaded(True) + if not hasattr(self.manager, 'get'): + return + + new = self.manager.get('%s/%s' % (self.stack_name, self.id)) + if new: + self._add_details(new._info) + @property def action(self): s = self.stack_status