Steve Baker | 647b345 | 2014-07-30 11:04:42 +1200 | [diff] [blame] | 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 json |
Steve Baker | 647b345 | 2014-07-30 11:04:42 +1200 | [diff] [blame] | 14 | |
Thomas Herve | 7aee65a | 2015-08-12 13:46:17 +0200 | [diff] [blame^] | 15 | from testtools import testcase |
| 16 | |
Steve Baker | 647b345 | 2014-07-30 11:04:42 +1200 | [diff] [blame] | 17 | from heat_integrationtests.common import exceptions |
Anastasia Kuznetsova | e45bfff | 2015-02-25 12:50:34 +0400 | [diff] [blame] | 18 | from heat_integrationtests.scenario import scenario_base |
Steve Baker | 647b345 | 2014-07-30 11:04:42 +1200 | [diff] [blame] | 19 | |
Steve Baker | 647b345 | 2014-07-30 11:04:42 +1200 | [diff] [blame] | 20 | |
Anastasia Kuznetsova | e45bfff | 2015-02-25 12:50:34 +0400 | [diff] [blame] | 21 | class CfnInitIntegrationTest(scenario_base.ScenarioTestsBase): |
| 22 | """ |
| 23 | The class is responsible for testing cfn-init and cfn-signal workability |
| 24 | """ |
Steve Baker | 647b345 | 2014-07-30 11:04:42 +1200 | [diff] [blame] | 25 | |
| 26 | def setUp(self): |
| 27 | super(CfnInitIntegrationTest, self).setUp() |
Steve Baker | 647b345 | 2014-07-30 11:04:42 +1200 | [diff] [blame] | 28 | |
Sergey Kraynev | ef9d842 | 2015-02-13 03:41:46 -0500 | [diff] [blame] | 29 | def check_stack(self, sid): |
Anastasia Kuznetsova | e45bfff | 2015-02-25 12:50:34 +0400 | [diff] [blame] | 30 | # Check status of all resources |
| 31 | for res in ('WaitHandle', 'SmokeSecurityGroup', 'SmokeKeys', |
Rakesh H S | eecee65 | 2015-07-15 17:44:41 +0530 | [diff] [blame] | 32 | 'CfnUser', 'SmokeServer', 'SmokeServerElasticIp'): |
Anastasia Kuznetsova | e45bfff | 2015-02-25 12:50:34 +0400 | [diff] [blame] | 33 | self._wait_for_resource_status( |
| 34 | sid, res, 'CREATE_COMPLETE') |
Steve Baker | 647b345 | 2014-07-30 11:04:42 +1200 | [diff] [blame] | 35 | |
| 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 Baker | 647b345 | 2014-07-30 11:04:42 +1200 | [diff] [blame] | 39 | |
| 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 Baker | 647b345 | 2014-07-30 11:04:42 +1200 | [diff] [blame] | 52 | 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 S | eecee65 | 2015-07-15 17:44:41 +0530 | [diff] [blame] | 64 | # 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 Baker | d6de8a2 | 2015-03-12 14:42:51 +1300 | [diff] [blame] | 80 | |
| 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 Kuznetsova | e45bfff | 2015-02-25 12:50:34 +0400 | [diff] [blame] | 87 | # Check that the user can authenticate with the generated keypair |
Steve Baker | 647b345 | 2014-07-30 11:04:42 +1200 | [diff] [blame] | 88 | if self.keypair: |
Steve Baker | 647b345 | 2014-07-30 11:04:42 +1200 | [diff] [blame] | 89 | 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 Herve | 7aee65a | 2015-08-12 13:46:17 +0200 | [diff] [blame^] | 98 | @testcase.skip('Skipped until keystone fixed #1484086') |
Steve Baker | 647b345 | 2014-07-30 11:04:42 +1200 | [diff] [blame] | 99 | def test_server_cfn_init(self): |
Anastasia Kuznetsova | e45bfff | 2015-02-25 12:50:34 +0400 | [diff] [blame] | 100 | """ |
| 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 Kraynev | 83ef84d | 2015-04-29 05:31:54 -0400 | [diff] [blame] | 112 | 'key_name': self.keypair_name, |
| 113 | 'flavor': self.conf.instance_type, |
| 114 | 'image': self.conf.image_ref, |
| 115 | 'timeout': self.conf.build_timeout, |
Rabi Mishra | ec4b03b | 2015-05-23 02:20:47 +0530 | [diff] [blame] | 116 | 'subnet': self.net['subnets'][0], |
Anastasia Kuznetsova | e45bfff | 2015-02-25 12:50:34 +0400 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | # Launch stack |
| 120 | stack_id = self.launch_stack( |
| 121 | template_name="test_server_cfn_init.yaml", |
Steve Baker | d6de8a2 | 2015-03-12 14:42:51 +1300 | [diff] [blame] | 122 | parameters=parameters, |
| 123 | expected_status=None |
Anastasia Kuznetsova | e45bfff | 2015-02-25 12:50:34 +0400 | [diff] [blame] | 124 | ) |
| 125 | |
| 126 | # Check stack |
| 127 | self.check_stack(stack_id) |