blob: 96306ac083ff55f169e01f43a4f50671e916984e [file] [log] [blame]
tengqmc0fffda2014-12-11 22:32:27 +08001# 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
Pavlo Shchelokovskyy60e0ecd2014-12-14 22:17:21 +020013
14from heatclient import exc
tengqmc0fffda2014-12-11 22:32:27 +080015import six
16
Rabi Mishra477efc92015-07-31 13:01:45 +053017from heat_integrationtests.functional import functional_base
tengqmc0fffda2014-12-11 22:32:27 +080018
tengqmc0fffda2014-12-11 22:32:27 +080019
Rabi Mishra477efc92015-07-31 13:01:45 +053020class RemoteStackTest(functional_base.FunctionalTestsBase):
tengqmc0fffda2014-12-11 22:32:27 +080021 template = '''
22heat_template_version: 2013-05-23
23resources:
24 my_stack:
25 type: OS::Heat::Stack
26 properties:
27 context:
28 region_name: RegionOne
29 template:
30 get_file: remote_stack.yaml
31outputs:
32 key:
33 value: {get_attr: [my_stack, outputs]}
34'''
35
36 remote_template = '''
37heat_template_version: 2013-05-23
38resources:
39 random1:
40 type: OS::Heat::RandomString
41outputs:
42 remote_key:
43 value: {get_attr: [random1, value]}
44'''
45
46 def setUp(self):
47 super(RemoteStackTest, self).setUp()
tengqmc0fffda2014-12-11 22:32:27 +080048
49 def test_remote_stack_alone(self):
50 stack_id = self.stack_create(template=self.remote_template)
51 expected_resources = {'random1': 'OS::Heat::RandomString'}
52 self.assertEqual(expected_resources, self.list_resources(stack_id))
53 stack = self.client.stacks.get(stack_id)
54 output_value = self._stack_output(stack, 'remote_key')
55 self.assertEqual(32, len(output_value))
56
57 def test_stack_create(self):
58 files = {'remote_stack.yaml': self.remote_template}
59 stack_id = self.stack_create(files=files)
60
61 expected_resources = {'my_stack': 'OS::Heat::Stack'}
62 self.assertEqual(expected_resources, self.list_resources(stack_id))
63
64 stack = self.client.stacks.get(stack_id)
65 output = self._stack_output(stack, 'key')
66 parent_output_value = output['remote_key']
67 self.assertEqual(32, len(parent_output_value))
68
69 rsrc = self.client.resources.get(stack_id, 'my_stack')
70 remote_id = rsrc.physical_resource_id
71 rstack = self.client.stacks.get(remote_id)
72 self.assertEqual(remote_id, rstack.id)
73 remote_output_value = self._stack_output(rstack, 'remote_key')
74 self.assertEqual(32, len(remote_output_value))
75 self.assertEqual(parent_output_value, remote_output_value)
76
77 remote_resources = {'random1': 'OS::Heat::RandomString'}
78 self.assertEqual(remote_resources, self.list_resources(remote_id))
79
80 def test_stack_create_bad_region(self):
tengqmc0fffda2014-12-11 22:32:27 +080081 tmpl_bad_region = self.template.replace('RegionOne', 'DARKHOLE')
82 files = {'remote_stack.yaml': self.remote_template}
83 kwargs = {
tengqmc0fffda2014-12-11 22:32:27 +080084 'template': tmpl_bad_region,
85 'files': files
86 }
87 ex = self.assertRaises(exc.HTTPBadRequest, self.stack_create, **kwargs)
88
89 error_msg = ('ERROR: Cannot establish connection to Heat endpoint '
90 'at region "DARKHOLE" due to "publicURL endpoint for '
91 'orchestration service in DARKHOLE region not found"')
92 self.assertEqual(error_msg, six.text_type(ex))
93
94 def test_stack_resource_validation_fail(self):
tengqmc0fffda2014-12-11 22:32:27 +080095 tmpl_bad_format = self.remote_template.replace('resources', 'resource')
96 files = {'remote_stack.yaml': tmpl_bad_format}
Sergey Kraynev203f8752016-01-25 04:21:32 -050097 kwargs = {'files': files}
tengqmc0fffda2014-12-11 22:32:27 +080098 ex = self.assertRaises(exc.HTTPBadRequest, self.stack_create, **kwargs)
99
100 error_msg = ('ERROR: Failed validating stack template using Heat '
101 'endpoint at region "RegionOne" due to '
102 '"ERROR: The template section is invalid: resource"')
103 self.assertEqual(error_msg, six.text_type(ex))
104
105 def test_stack_update(self):
106 files = {'remote_stack.yaml': self.remote_template}
107 stack_id = self.stack_create(files=files)
108
109 expected_resources = {'my_stack': 'OS::Heat::Stack'}
110 self.assertEqual(expected_resources, self.list_resources(stack_id))
111
112 rsrc = self.client.resources.get(stack_id, 'my_stack')
113 physical_resource_id = rsrc.physical_resource_id
114 rstack = self.client.stacks.get(physical_resource_id)
115 self.assertEqual(physical_resource_id, rstack.id)
116
117 remote_resources = {'random1': 'OS::Heat::RandomString'}
118 self.assertEqual(remote_resources,
119 self.list_resources(rstack.id))
120 # do an update
121 update_template = self.remote_template.replace('random1', 'random2')
122 files = {'remote_stack.yaml': update_template}
123 self.update_stack(stack_id, self.template, files=files)
124
125 # check if the remote stack is still there with the same ID
126 self.assertEqual(expected_resources, self.list_resources(stack_id))
127 rsrc = self.client.resources.get(stack_id, 'my_stack')
128 physical_resource_id = rsrc.physical_resource_id
129 rstack = self.client.stacks.get(physical_resource_id)
130 self.assertEqual(physical_resource_id, rstack.id)
131
132 remote_resources = {'random2': 'OS::Heat::RandomString'}
133 self.assertEqual(remote_resources,
134 self.list_resources(rstack.id))
135
136 def test_stack_suspend_resume(self):
137 files = {'remote_stack.yaml': self.remote_template}
138 stack_id = self.stack_create(files=files)
Angus Salkelda7500d12015-04-10 15:44:07 +1000139 self.stack_suspend(stack_id)
140 self.stack_resume(stack_id)