Skip to content

Commit e4d550e

Browse files
committed
StackTemplate resource for orchestration
This adds the StackTemplate resource for orchestration service (heat) v1. Change-Id: Ic4ea1c58b8c43b2e4217b4a96195b338a3f4310b
1 parent 23edc31 commit e4d550e

4 files changed

Lines changed: 149 additions & 0 deletions

File tree

openstack/orchestration/v1/_proxy.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from openstack.orchestration.v1 import software_config as _sc
1616
from openstack.orchestration.v1 import software_deployment as _sd
1717
from openstack.orchestration.v1 import stack as _stack
18+
from openstack.orchestration.v1 import stack_template as _stack_template
1819
from openstack.orchestration.v1 import template as _template
1920
from openstack import proxy2
2021

@@ -124,6 +125,24 @@ def check_stack(self, stack):
124125

125126
stk_obj.check(self._session)
126127

128+
def get_stack_template(self, stack):
129+
"""Get a single stack
130+
131+
:param stack: The value can be the ID of a stack or a
132+
:class:`~openstack.orchestration.v1.stack.Stack` instance.
133+
134+
:returns: One :class:`~openstack.orchestration.v1.stack.Stack`
135+
:raises: :class:`~openstack.exceptions.ResourceNotFound`
136+
when no resource can be found.
137+
"""
138+
if isinstance(stack, _stack.Stack):
139+
obj = stack
140+
else:
141+
obj = self._find(_stack.Stack, stack, ignore_missing=False)
142+
143+
return self._get(_stack_template.StackTemplate, requires_id=False,
144+
stack_name=obj.name, stack_id=obj.id)
145+
127146
def resources(self, stack, **query):
128147
"""Return a generator of resources
129148
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
2+
# not use this file except in compliance with the License. You may obtain
3+
# a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10+
# License for the specific language governing permissions and limitations
11+
# under the License.
12+
13+
from openstack.orchestration import orchestration_service
14+
from openstack import resource2 as resource
15+
16+
17+
class StackTemplate(resource.Resource):
18+
19+
service = orchestration_service.OrchestrationService()
20+
base_path = "/stacks/%(stack_name)s/%(stack_id)s/template"
21+
22+
# capabilities
23+
allow_create = False
24+
allow_list = False
25+
allow_get = True
26+
allow_delete = False
27+
allow_update = False
28+
29+
# Properties
30+
#: Name of the stack where the template is referenced.
31+
stack_name = resource.URI('stack_name')
32+
#: ID of the stack where the template is referenced.
33+
stack_id = resource.URI('stack_id')
34+
#: The description specified in the template
35+
description = resource.Body('Description')
36+
#: The version of the orchestration HOT template.
37+
heat_template_version = resource.Body('heat_template_version')
38+
#: Key and value that contain output data.
39+
outputs = resource.Body('outputs', type=dict)
40+
#: Key and value pairs that contain template parameters
41+
parameters = resource.Body('parameters', type=dict)
42+
#: Key and value pairs that contain definition of resources in the
43+
#: template
44+
resources = resource.Body('resources', type=dict)

openstack/tests/unit/orchestration/v1/test_proxy.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from openstack.orchestration.v1 import software_config as sc
2020
from openstack.orchestration.v1 import software_deployment as sd
2121
from openstack.orchestration.v1 import stack
22+
from openstack.orchestration.v1 import stack_template
2223
from openstack.orchestration.v1 import template
2324
from openstack.tests.unit import test_proxy_base2
2425

@@ -74,6 +75,36 @@ def test_check_stack_with_stack_ID(self, mock_stack):
7475
mock_stack.assert_called_once_with(id='FAKE_ID')
7576
stk.check.assert_called_once_with(self.proxy._session)
7677

78+
@mock.patch.object(stack.Stack, 'find')
79+
def test_get_stack_template_with_stack_identity(self, mock_find):
80+
stack_id = '1234'
81+
stack_name = 'test_stack'
82+
stk = stack.Stack(id=stack_id, name=stack_name)
83+
mock_find.return_value = stk
84+
85+
self._verify2('openstack.proxy2.BaseProxy._get',
86+
self.proxy.get_stack_template,
87+
method_args=['IDENTITY'],
88+
expected_args=[stack_template.StackTemplate],
89+
expected_kwargs={'requires_id': False,
90+
'stack_name': stack_name,
91+
'stack_id': stack_id})
92+
mock_find.assert_called_once_with(mock.ANY, 'IDENTITY',
93+
ignore_missing=False)
94+
95+
def test_get_stack_template_with_stack_object(self):
96+
stack_id = '1234'
97+
stack_name = 'test_stack'
98+
stk = stack.Stack(id=stack_id, name=stack_name)
99+
100+
self._verify2('openstack.proxy2.BaseProxy._get',
101+
self.proxy.get_stack_template,
102+
method_args=[stk],
103+
expected_args=[stack_template.StackTemplate],
104+
expected_kwargs={'requires_id': False,
105+
'stack_name': stack_name,
106+
'stack_id': stack_id})
107+
77108
@mock.patch.object(stack.Stack, 'find')
78109
def test_resources_with_stack_object(self, mock_find):
79110
stack_id = '1234'
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
2+
# not use this file except in compliance with the License. You may obtain
3+
# a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10+
# License for the specific language governing permissions and limitations
11+
# under the License.
12+
13+
import testtools
14+
15+
from openstack.orchestration.v1 import stack_template
16+
17+
18+
FAKE = {
19+
'description': 'template description',
20+
'heat_template_version': '2014-10-16',
21+
'parameters': {
22+
'key_name': {
23+
'type': 'string'
24+
}
25+
},
26+
'resources': {
27+
'resource1': {
28+
'type': 'ResourceType'
29+
}
30+
},
31+
'outputs': {
32+
'key1': 'value1'
33+
}
34+
}
35+
36+
37+
class TestStackTemplate(testtools.TestCase):
38+
39+
def test_basic(self):
40+
sot = stack_template.StackTemplate()
41+
self.assertEqual('orchestration', sot.service.service_type)
42+
self.assertFalse(sot.allow_create)
43+
self.assertTrue(sot.allow_get)
44+
self.assertFalse(sot.allow_update)
45+
self.assertFalse(sot.allow_delete)
46+
self.assertFalse(sot.allow_list)
47+
48+
def test_make_it(self):
49+
sot = stack_template.StackTemplate(**FAKE)
50+
self.assertEqual(FAKE['description'], sot.description)
51+
self.assertEqual(FAKE['heat_template_version'],
52+
sot.heat_template_version)
53+
self.assertEqual(FAKE['outputs'], sot.outputs)
54+
self.assertEqual(FAKE['parameters'], sot.parameters)
55+
self.assertEqual(FAKE['resources'], sot.resources)

0 commit comments

Comments
 (0)