blob: b2085e2deb489dcfccc476b1cae45d6292dc7896 [file] [log] [blame]
Steve Bakerc2f84ee2016-06-30 00:56:13 +00001#
2# Licensed under the Apache License, Version 2.0 (the "License"); you may
3# not use this file except in compliance with the License. You may obtain
4# a copy of the License at
5#
6# http://www.apache.org/licenses/LICENSE-2.0
7#
8# Unless required by applicable law or agreed to in writing, software
9# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11# License for the specific language governing permissions and limitations
12# under the License.
13
14import json
15
16from heat_integrationtests.common import exceptions
17from heat_integrationtests.scenario import scenario_base
18
19
20class ServerSignalIntegrationTest(scenario_base.ScenarioTestsBase):
21 """Test a server in a created network can signal to heat."""
22
huangtianhua4dd13942016-11-21 16:09:50 +080023 def _test_server_signal(self, user_data_format='RAW',
24 image=None):
Steve Bakerc2f84ee2016-06-30 00:56:13 +000025 """Check a server in a created network can signal to heat."""
26 parameters = {
27 'key_name': self.keypair_name,
rabic333f762016-09-29 08:34:03 +053028 'flavor': self.conf.minimal_instance_type,
huangtianhua4dd13942016-11-21 16:09:50 +080029 'image': image,
Steve Bakerc2f84ee2016-06-30 00:56:13 +000030 'timeout': self.conf.build_timeout,
huangtianhua4dd13942016-11-21 16:09:50 +080031 'user_data_format': user_data_format
Steve Bakerc2f84ee2016-06-30 00:56:13 +000032 }
33
34 # Launch stack
35 sid = self.launch_stack(
36 template_name="test_server_signal.yaml",
37 parameters=parameters,
38 expected_status=None
39 )
40
41 # Check status of all resources
42 for res in ('sg', 'floating_ip', 'network', 'router', 'subnet',
43 'router_interface', 'wait_handle', 'server',
44 'server_floating_ip_assoc'):
45 self._wait_for_resource_status(
46 sid, res, 'CREATE_COMPLETE')
47
48 server_resource = self.client.resources.get(sid, 'server')
49 server_id = server_resource.physical_resource_id
50 server = self.compute_client.servers.get(server_id)
51
52 try:
53 self._wait_for_resource_status(
54 sid, 'wait_condition', 'CREATE_COMPLETE')
55 except (exceptions.StackResourceBuildErrorException,
56 exceptions.TimeoutException):
57 raise
58 finally:
59 # attempt to log the server console regardless of WaitCondition
60 # going to complete. This allows successful and failed cloud-init
61 # logs to be compared
62 self._log_console_output(servers=[server])
63
64 stack = self.client.stacks.get(sid)
65
66 wc_data = json.loads(
67 self._stack_output(stack, 'wc_data'))
68 self.assertEqual({'1': 'test complete'}, wc_data)
69
70 server_ip = self._stack_output(stack, 'server_ip')
71
72 # Check that created server is reachable
73 if not self._ping_ip_address(server_ip):
74 self._log_console_output(servers=[server])
75 self.fail(
76 "Timed out waiting for %s to become reachable" % server_ip)
huangtianhua4dd13942016-11-21 16:09:50 +080077
78 def test_server_signal_userdata_format_raw(self):
79 self._test_server_signal(image=self.conf.minimal_image_ref)
80
81 def test_server_signal_userdata_format_software_config(self):
82 if not self.conf.image_ref:
83 raise self.skipException("No image configured to test")
84 self._test_server_signal(user_data_format='SOFTWARE_CONFIG',
85 image=self.conf.image_ref)