Stack instance identifier property

The identifier property formats the stack name and ID for
REST API request paths.

This has the following consequences for each action method:
- get, same behaviour but using the identifier property
- delete, using the full identifier avoids one http redirect
- update, this method was non-functional before this change, and is
  now fixed

Change-Id: Ib2b12826243e25772acccb8ca56039e54d3857d5
This commit is contained in:
Steve Baker
2013-09-04 11:33:29 +12:00
parent a5d71080ef
commit 3146d22b70
2 changed files with 23 additions and 7 deletions

View File

@@ -63,13 +63,20 @@ class StackStatusActionTest(testtools.TestCase):
self.assertEqual(self.status, stack.status)
class StackIdentifierTest(testtools.TestCase):
def test_stack_identifier(self):
stack = mock_stack(None, 'the_stack', 'abcd1234')
self.assertEqual('the_stack/abcd1234', stack.identifier)
class StackOperationsTest(testtools.TestCase):
def test_delete_stack(self):
manager = MagicMock()
stack = mock_stack(manager, None, 'abcd1234')
stack = mock_stack(manager, 'the_stack', 'abcd1234')
stack.delete()
manager.delete.assert_called_once_with('abcd1234')
manager.delete.assert_called_once_with('the_stack/abcd1234')
def test_get_stack(self):
manager = MagicMock()
@@ -77,6 +84,12 @@ class StackOperationsTest(testtools.TestCase):
stack.get()
manager.get.assert_called_once_with('the_stack/abcd1234')
def test_update_stack(self):
manager = MagicMock()
stack = mock_stack(manager, 'the_stack', 'abcd1234')
stack.update()
manager.update.assert_called_once_with('the_stack/abcd1234')
class StackManagerNoPaginationTest(testtools.TestCase):

View File

@@ -23,10 +23,10 @@ class Stack(base.Resource):
return "<Stack %s>" % self._info
def update(self, **fields):
self.manager.update(self, **fields)
self.manager.update(self.identifier, **fields)
def delete(self):
return self.manager.delete(self.id)
return self.manager.delete(self.identifier)
def get(self):
# set_loaded() first ... so if we have to bail, we know we tried.
@@ -34,7 +34,7 @@ class Stack(base.Resource):
if not hasattr(self.manager, 'get'):
return
new = self.manager.get('%s/%s' % (self.stack_name, self.id))
new = self.manager.get(self.identifier)
if new:
self._add_details(new._info)
@@ -50,6 +50,10 @@ class Stack(base.Resource):
# Return everything after the first underscore
return s[s.index('_') + 1:]
@property
def identifier(self):
return '%s/%s' % (self.stack_name, self.id)
class StackManager(base.Manager):
resource_class = Stack
@@ -105,9 +109,8 @@ class StackManager(base.Manager):
resp, body = self.api.json_request('POST', '/stacks',
body=kwargs, headers=headers)
def update(self, **kwargs):
def update(self, stack_id, **kwargs):
"""Update a stack."""
stack_id = kwargs.pop('stack_id')
headers = self.api.credentials_headers()
resp, body = self.api.json_request('PUT', '/stacks/%s' % stack_id,
body=kwargs, headers=headers)