blob: 197e0c0b455d9a043b304ed46fb83f9e4c2085ca [file] [log] [blame]
Steve Baker647b3452014-07-30 11:04:42 +12001# 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
13import json
Steve Baker647b3452014-07-30 11:04:42 +120014
15from heat_integrationtests.common import exceptions
Anastasia Kuznetsovae45bfff2015-02-25 12:50:34 +040016from heat_integrationtests.scenario import scenario_base
Steve Baker647b3452014-07-30 11:04:42 +120017
Steve Baker647b3452014-07-30 11:04:42 +120018
Anastasia Kuznetsovae45bfff2015-02-25 12:50:34 +040019class CfnInitIntegrationTest(scenario_base.ScenarioTestsBase):
20 """
21 The class is responsible for testing cfn-init and cfn-signal workability
22 """
Steve Baker647b3452014-07-30 11:04:42 +120023
24 def setUp(self):
25 super(CfnInitIntegrationTest, self).setUp()
Angus Salkelde2996362015-07-31 16:22:42 +100026 raise self.skipException("Skipping until bug #1479869 is fixed.")
Steve Baker647b3452014-07-30 11:04:42 +120027
Sergey Kraynevef9d8422015-02-13 03:41:46 -050028 def check_stack(self, sid):
Anastasia Kuznetsovae45bfff2015-02-25 12:50:34 +040029 # Check status of all resources
30 for res in ('WaitHandle', 'SmokeSecurityGroup', 'SmokeKeys',
Rakesh H Seecee652015-07-15 17:44:41 +053031 'CfnUser', 'SmokeServer', 'SmokeServerElasticIp'):
Anastasia Kuznetsovae45bfff2015-02-25 12:50:34 +040032 self._wait_for_resource_status(
33 sid, res, 'CREATE_COMPLETE')
Steve Baker647b3452014-07-30 11:04:42 +120034
35 server_resource = self.client.resources.get(sid, 'SmokeServer')
36 server_id = server_resource.physical_resource_id
37 server = self.compute_client.servers.get(server_id)
Steve Baker647b3452014-07-30 11:04:42 +120038
39 try:
40 self._wait_for_resource_status(
41 sid, 'WaitCondition', 'CREATE_COMPLETE')
42 except (exceptions.StackResourceBuildErrorException,
43 exceptions.TimeoutException) as e:
44 raise e
45 finally:
46 # attempt to log the server console regardless of WaitCondition
47 # going to complete. This allows successful and failed cloud-init
48 # logs to be compared
49 self._log_console_output(servers=[server])
50
Steve Baker647b3452014-07-30 11:04:42 +120051 stack = self.client.stacks.get(sid)
52
53 # This is an assert of great significance, as it means the following
54 # has happened:
55 # - cfn-init read the provided metadata and wrote out a file
56 # - a user was created and credentials written to the server
57 # - a cfn-signal was built which was signed with provided credentials
58 # - the wait condition was fulfilled and the stack has changed state
59 wait_status = json.loads(
60 self._stack_output(stack, 'WaitConditionStatus'))
61 self.assertEqual('smoke test complete', wait_status['smoke_status'])
62
Rakesh H Seecee652015-07-15 17:44:41 +053063 # Check EIP attributes.
64 server_floatingip_id = self._stack_output(stack,
65 'ElasticIp_Id')
66 self.assertIsNotNone(server_floatingip_id)
67
68 # Fetch EIP details.
69 net_show = self.network_client.show_floatingip(
70 floatingip=server_floatingip_id)
71 floating_ip = net_show['floatingip']['floating_ip_address']
72 port_id = net_show['floatingip']['port_id']
73
74 # Ensure that EIP was assigned to server.
75 port_show = self.network_client.show_port(port=port_id)
76 self.assertEqual(server.id, port_show['port']['device_id'])
77 server_ip = self._stack_output(stack, 'SmokeServerElasticIp')
78 self.assertEqual(server_ip, floating_ip)
Steve Bakerd6de8a22015-03-12 14:42:51 +130079
80 # Check that created server is reachable
81 if not self._ping_ip_address(server_ip):
82 self._log_console_output(servers=[server])
83 self.fail(
84 "Timed out waiting for %s to become reachable" % server_ip)
85
Anastasia Kuznetsovae45bfff2015-02-25 12:50:34 +040086 # Check that the user can authenticate with the generated keypair
Steve Baker647b3452014-07-30 11:04:42 +120087 if self.keypair:
Steve Baker647b3452014-07-30 11:04:42 +120088 try:
89 linux_client = self.get_remote_client(
90 server_ip, username='ec2-user')
91 linux_client.validate_authentication()
92 except (exceptions.ServerUnreachable,
93 exceptions.SSHTimeout) as e:
94 self._log_console_output(servers=[server])
95 raise e
96
97 def test_server_cfn_init(self):
Anastasia Kuznetsovae45bfff2015-02-25 12:50:34 +040098 """
99 Check cfn-init and cfn-signal availability on the created server.
100
101 The alternative scenario is the following:
102 1. Create a stack with a server and configured security group.
103 2. Check that all stack resources were created.
104 3. Check that created server is reachable.
105 4. Check that stack was created successfully.
106 5. Check that is it possible to connect to server
107 via generated keypair.
108 """
109 parameters = {
Sergey Kraynev83ef84d2015-04-29 05:31:54 -0400110 'key_name': self.keypair_name,
111 'flavor': self.conf.instance_type,
112 'image': self.conf.image_ref,
113 'timeout': self.conf.build_timeout,
Rabi Mishraec4b03b2015-05-23 02:20:47 +0530114 'subnet': self.net['subnets'][0],
Anastasia Kuznetsovae45bfff2015-02-25 12:50:34 +0400115 }
116
117 # Launch stack
118 stack_id = self.launch_stack(
119 template_name="test_server_cfn_init.yaml",
Steve Bakerd6de8a22015-03-12 14:42:51 +1300120 parameters=parameters,
121 expected_status=None
Anastasia Kuznetsovae45bfff2015-02-25 12:50:34 +0400122 )
123
124 # Check stack
125 self.check_stack(stack_id)