blob: 00a360b055ab969bf9686cdf61c3c2daf9cdaa98 [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
Thomas Herve7aee65a2015-08-12 13:46:17 +020015from testtools import testcase
16
Steve Baker647b3452014-07-30 11:04:42 +120017from heat_integrationtests.common import exceptions
Anastasia Kuznetsovae45bfff2015-02-25 12:50:34 +040018from heat_integrationtests.scenario import scenario_base
Steve Baker647b3452014-07-30 11:04:42 +120019
Steve Baker647b3452014-07-30 11:04:42 +120020
Anastasia Kuznetsovae45bfff2015-02-25 12:50:34 +040021class CfnInitIntegrationTest(scenario_base.ScenarioTestsBase):
22 """
23 The class is responsible for testing cfn-init and cfn-signal workability
24 """
Steve Baker647b3452014-07-30 11:04:42 +120025
26 def setUp(self):
27 super(CfnInitIntegrationTest, self).setUp()
Steve Baker647b3452014-07-30 11:04:42 +120028
Sergey Kraynevef9d8422015-02-13 03:41:46 -050029 def check_stack(self, sid):
Anastasia Kuznetsovae45bfff2015-02-25 12:50:34 +040030 # Check status of all resources
31 for res in ('WaitHandle', 'SmokeSecurityGroup', 'SmokeKeys',
Rakesh H Seecee652015-07-15 17:44:41 +053032 'CfnUser', 'SmokeServer', 'SmokeServerElasticIp'):
Anastasia Kuznetsovae45bfff2015-02-25 12:50:34 +040033 self._wait_for_resource_status(
34 sid, res, 'CREATE_COMPLETE')
Steve Baker647b3452014-07-30 11:04:42 +120035
36 server_resource = self.client.resources.get(sid, 'SmokeServer')
37 server_id = server_resource.physical_resource_id
38 server = self.compute_client.servers.get(server_id)
Steve Baker647b3452014-07-30 11:04:42 +120039
40 try:
41 self._wait_for_resource_status(
42 sid, 'WaitCondition', 'CREATE_COMPLETE')
43 except (exceptions.StackResourceBuildErrorException,
44 exceptions.TimeoutException) as e:
45 raise e
46 finally:
47 # attempt to log the server console regardless of WaitCondition
48 # going to complete. This allows successful and failed cloud-init
49 # logs to be compared
50 self._log_console_output(servers=[server])
51
Steve Baker647b3452014-07-30 11:04:42 +120052 stack = self.client.stacks.get(sid)
53
54 # This is an assert of great significance, as it means the following
55 # has happened:
56 # - cfn-init read the provided metadata and wrote out a file
57 # - a user was created and credentials written to the server
58 # - a cfn-signal was built which was signed with provided credentials
59 # - the wait condition was fulfilled and the stack has changed state
60 wait_status = json.loads(
61 self._stack_output(stack, 'WaitConditionStatus'))
62 self.assertEqual('smoke test complete', wait_status['smoke_status'])
63
Rakesh H Seecee652015-07-15 17:44:41 +053064 # Check EIP attributes.
65 server_floatingip_id = self._stack_output(stack,
66 'ElasticIp_Id')
67 self.assertIsNotNone(server_floatingip_id)
68
69 # Fetch EIP details.
70 net_show = self.network_client.show_floatingip(
71 floatingip=server_floatingip_id)
72 floating_ip = net_show['floatingip']['floating_ip_address']
73 port_id = net_show['floatingip']['port_id']
74
75 # Ensure that EIP was assigned to server.
76 port_show = self.network_client.show_port(port=port_id)
77 self.assertEqual(server.id, port_show['port']['device_id'])
78 server_ip = self._stack_output(stack, 'SmokeServerElasticIp')
79 self.assertEqual(server_ip, floating_ip)
Steve Bakerd6de8a22015-03-12 14:42:51 +130080
81 # Check that created server is reachable
82 if not self._ping_ip_address(server_ip):
83 self._log_console_output(servers=[server])
84 self.fail(
85 "Timed out waiting for %s to become reachable" % server_ip)
86
Anastasia Kuznetsovae45bfff2015-02-25 12:50:34 +040087 # Check that the user can authenticate with the generated keypair
Steve Baker647b3452014-07-30 11:04:42 +120088 if self.keypair:
Steve Baker647b3452014-07-30 11:04:42 +120089 try:
90 linux_client = self.get_remote_client(
91 server_ip, username='ec2-user')
92 linux_client.validate_authentication()
93 except (exceptions.ServerUnreachable,
94 exceptions.SSHTimeout) as e:
95 self._log_console_output(servers=[server])
96 raise e
97
Thomas Herve7aee65a2015-08-12 13:46:17 +020098 @testcase.skip('Skipped until keystone fixed #1484086')
Steve Baker647b3452014-07-30 11:04:42 +120099 def test_server_cfn_init(self):
Anastasia Kuznetsovae45bfff2015-02-25 12:50:34 +0400100 """
101 Check cfn-init and cfn-signal availability on the created server.
102
103 The alternative scenario is the following:
104 1. Create a stack with a server and configured security group.
105 2. Check that all stack resources were created.
106 3. Check that created server is reachable.
107 4. Check that stack was created successfully.
108 5. Check that is it possible to connect to server
109 via generated keypair.
110 """
111 parameters = {
Sergey Kraynev83ef84d2015-04-29 05:31:54 -0400112 'key_name': self.keypair_name,
113 'flavor': self.conf.instance_type,
114 'image': self.conf.image_ref,
115 'timeout': self.conf.build_timeout,
Rabi Mishraec4b03b2015-05-23 02:20:47 +0530116 'subnet': self.net['subnets'][0],
Anastasia Kuznetsovae45bfff2015-02-25 12:50:34 +0400117 }
118
119 # Launch stack
120 stack_id = self.launch_stack(
121 template_name="test_server_cfn_init.yaml",
Steve Bakerd6de8a22015-03-12 14:42:51 +1300122 parameters=parameters,
123 expected_status=None
Anastasia Kuznetsovae45bfff2015-02-25 12:50:34 +0400124 )
125
126 # Check stack
127 self.check_stack(stack_id)