Merge "Add preview_stack for orchestration"

This commit is contained in:
Jenkins
2016-01-15 16:05:53 +00:00
committed by Gerrit Code Review
4 changed files with 41 additions and 2 deletions

View File

@@ -18,9 +18,13 @@ from openstack import proxy
class Proxy(proxy.BaseProxy):
def create_stack(self, **attrs):
def create_stack(self, preview=False, **attrs):
"""Create a new stack from attributes
:param bool perview: When ``True``, returns
:class:`~openstack.orchestration.v1.stack.StackPreview` objects,
otherwise :class:`~openstack.orchestration.v1.stack.Stack`.
*Default: ``False``*
:param dict attrs: Keyword arguments which will be used to create
a :class:`~openstack.orchestration.v1.stack.Stack`,
comprised of the properties on the Stack class.
@@ -28,7 +32,8 @@ class Proxy(proxy.BaseProxy):
:returns: The results of stack creation
:rtype: :class:`~openstack.orchestration.v1.stack.Stack`
"""
return self._create(_stack.Stack, **attrs)
stk = _stack.StackPreview if preview else _stack.Stack
return self._create(stk, **attrs)
def find_stack(self, name_or_id, ignore_missing=True):
"""Find a single stack

View File

@@ -107,3 +107,13 @@ class Stack(resource.Resource):
raise exceptions.ResourceNotFound(
"No stack found for %s" % name_or_id)
return stk
class StackPreview(Stack):
base_path = '/stacks/preview'
allow_create = True
allow_list = False
allow_retrieve = False
allow_update = False
allow_delete = False

View File

@@ -28,6 +28,11 @@ class TestOrchestrationProxy(test_proxy_base.TestProxyBase):
def test_stack_create_attrs(self):
self.verify_create(self.proxy.create_stack, stack.Stack)
def test_stack_preview_attrs(self):
method_kwargs = {"preview": True, "x": 1, "y": 2, "z": 3}
self.verify_create(self.proxy.create_stack, stack.StackPreview,
method_kwargs=method_kwargs)
def test_stack_find(self):
self.verify_find(self.proxy.find_stack, stack.Stack)

View File

@@ -103,6 +103,25 @@ class TestStack(testtools.TestCase):
self.assertEqual(FAKE_ID, sot.id)
self.assertEqual(FAKE_NAME, sot.name)
def test_preview(self):
resp = mock.Mock()
resp.json = mock.Mock(return_value=FAKE_CREATE_RESPONSE)
sess = mock.Mock()
sess.post = mock.Mock(return_value=resp)
attrs = FAKE.copy()
sot = stack.StackPreview(attrs)
sot.create(sess)
url = '/stacks/preview'
body = sot._attrs.copy()
body.pop('id', None)
body.pop('name', None)
sess.post.assert_called_with(url, endpoint_filter=sot.service,
json=body)
self.assertEqual(FAKE_ID, sot.id)
self.assertEqual(FAKE_NAME, sot.name)
def test_update(self):
# heat responds to update request with an 202 status code
resp_update = mock.Mock()