Steve Baker | f6c8f12 | 2015-02-10 13:54:46 +1300 | [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 | |
Steve Baker | 0b679bb | 2015-03-11 13:46:42 +1300 | [diff] [blame] | 13 | from heatclient.common import template_utils |
Steve Baker | f6c8f12 | 2015-02-10 13:54:46 +1300 | [diff] [blame] | 14 | import six |
| 15 | |
| 16 | from heat_integrationtests.common import exceptions |
Anastasia Kuznetsova | e45bfff | 2015-02-25 12:50:34 +0400 | [diff] [blame] | 17 | from heat_integrationtests.scenario import scenario_base |
Steve Baker | f6c8f12 | 2015-02-10 13:54:46 +1300 | [diff] [blame] | 18 | |
| 19 | CFG1_SH = '''#!/bin/sh |
| 20 | echo "Writing to /tmp/$bar" |
| 21 | echo $foo > /tmp/$bar |
| 22 | echo -n "The file /tmp/$bar contains `cat /tmp/$bar` for server \ |
| 23 | $deploy_server_id during $deploy_action" > $heat_outputs_path.result |
| 24 | echo "Written to /tmp/$bar" |
| 25 | echo "Output to stderr" 1>&2 |
| 26 | ''' |
| 27 | |
| 28 | CFG3_PP = '''file {'barfile': |
| 29 | ensure => file, |
| 30 | mode => 0644, |
| 31 | path => "/tmp/$::bar", |
| 32 | content => "$::foo", |
| 33 | } |
| 34 | file {'output_result': |
| 35 | ensure => file, |
| 36 | path => "$::heat_outputs_path.result", |
| 37 | mode => 0644, |
| 38 | content => "The file /tmp/$::bar contains $::foo for server \ |
| 39 | $::deploy_server_id during $::deploy_action", |
| 40 | }''' |
| 41 | |
| 42 | |
Anastasia Kuznetsova | e45bfff | 2015-02-25 12:50:34 +0400 | [diff] [blame] | 43 | class SoftwareConfigIntegrationTest(scenario_base.ScenarioTestsBase): |
Steve Baker | f6c8f12 | 2015-02-10 13:54:46 +1300 | [diff] [blame] | 44 | |
| 45 | def setUp(self): |
| 46 | super(SoftwareConfigIntegrationTest, self).setUp() |
Steve Baker | f6c8f12 | 2015-02-10 13:54:46 +1300 | [diff] [blame] | 47 | self.stack_name = self._stack_rand_name() |
Steve Baker | f6c8f12 | 2015-02-10 13:54:46 +1300 | [diff] [blame] | 48 | |
Steve Baker | 8c9aee1 | 2015-03-10 16:17:45 +1300 | [diff] [blame] | 49 | def check_stack(self): |
| 50 | sid = self.stack_identifier |
Anastasia Kuznetsova | e45bfff | 2015-02-25 12:50:34 +0400 | [diff] [blame] | 51 | # Check that all stack resources were created |
Steve Baker | f6c8f12 | 2015-02-10 13:54:46 +1300 | [diff] [blame] | 52 | for res in ('cfg2a', 'cfg2b', 'cfg1', 'cfg3', 'server'): |
| 53 | self._wait_for_resource_status( |
| 54 | sid, res, 'CREATE_COMPLETE') |
| 55 | |
| 56 | server_resource = self.client.resources.get(sid, 'server') |
| 57 | server_id = server_resource.physical_resource_id |
| 58 | server = self.compute_client.servers.get(server_id) |
| 59 | |
Anastasia Kuznetsova | e45bfff | 2015-02-25 12:50:34 +0400 | [diff] [blame] | 60 | # Waiting for each deployment to contribute their |
| 61 | # config to resource |
Steve Baker | f6c8f12 | 2015-02-10 13:54:46 +1300 | [diff] [blame] | 62 | try: |
Steve Baker | f6c8f12 | 2015-02-10 13:54:46 +1300 | [diff] [blame] | 63 | for res in ('dep2b', 'dep1', 'dep3'): |
| 64 | self._wait_for_resource_status( |
| 65 | sid, res, 'CREATE_IN_PROGRESS') |
| 66 | |
Anastasia Kuznetsova | e45bfff | 2015-02-25 12:50:34 +0400 | [diff] [blame] | 67 | server_metadata = self.client.resources.metadata( |
| 68 | sid, 'server') |
Steve Baker | f6c8f12 | 2015-02-10 13:54:46 +1300 | [diff] [blame] | 69 | deployments = dict((d['name'], d) for d in |
| 70 | server_metadata['deployments']) |
| 71 | |
| 72 | for res in ('dep2a', 'dep2b', 'dep1', 'dep3'): |
| 73 | self._wait_for_resource_status( |
| 74 | sid, res, 'CREATE_COMPLETE') |
| 75 | except (exceptions.StackResourceBuildErrorException, |
| 76 | exceptions.TimeoutException) as e: |
Steve Baker | f6c8f12 | 2015-02-10 13:54:46 +1300 | [diff] [blame] | 77 | raise e |
Steve Baker | 803f150 | 2015-03-11 13:47:08 +1300 | [diff] [blame] | 78 | finally: |
| 79 | # attempt to log the server console regardless of deployments |
| 80 | # going to complete. This allows successful and failed boot |
| 81 | # logs to be compared |
| 82 | self._log_console_output(servers=[server]) |
Steve Baker | f6c8f12 | 2015-02-10 13:54:46 +1300 | [diff] [blame] | 83 | |
Steve Baker | f6c8f12 | 2015-02-10 13:54:46 +1300 | [diff] [blame] | 84 | complete_server_metadata = self.client.resources.metadata( |
| 85 | sid, 'server') |
Anastasia Kuznetsova | e45bfff | 2015-02-25 12:50:34 +0400 | [diff] [blame] | 86 | |
| 87 | # Ensure any previously available deployments haven't changed so |
Steve Baker | f6c8f12 | 2015-02-10 13:54:46 +1300 | [diff] [blame] | 88 | # config isn't re-triggered |
| 89 | complete_deployments = dict((d['name'], d) for d in |
| 90 | complete_server_metadata['deployments']) |
| 91 | for k, v in six.iteritems(deployments): |
| 92 | self.assertEqual(v, complete_deployments[k]) |
| 93 | |
| 94 | stack = self.client.stacks.get(sid) |
| 95 | |
| 96 | res1 = self._stack_output(stack, 'res1') |
| 97 | self.assertEqual( |
| 98 | 'The file %s contains %s for server %s during %s' % ( |
| 99 | '/tmp/baaaaa', 'fooooo', server_id, 'CREATE'), |
| 100 | res1['result']) |
| 101 | self.assertEqual(0, res1['status_code']) |
| 102 | self.assertEqual('Output to stderr\n', res1['stderr']) |
| 103 | self.assertTrue(len(res1['stdout']) > 0) |
| 104 | |
| 105 | res2 = self._stack_output(stack, 'res2') |
| 106 | self.assertEqual( |
| 107 | 'The file %s contains %s for server %s during %s' % ( |
| 108 | '/tmp/cfn-init-foo', 'barrr', server_id, 'CREATE'), |
| 109 | res2['result']) |
| 110 | self.assertEqual(0, res2['status_code']) |
| 111 | self.assertEqual('', res2['stderr']) |
| 112 | self.assertEqual('', res2['stdout']) |
| 113 | |
| 114 | res3 = self._stack_output(stack, 'res3') |
| 115 | self.assertEqual( |
| 116 | 'The file %s contains %s for server %s during %s' % ( |
| 117 | '/tmp/ba', 'fo', server_id, 'CREATE'), |
| 118 | res3['result']) |
| 119 | self.assertEqual(0, res3['status_code']) |
| 120 | self.assertEqual('', res3['stderr']) |
| 121 | self.assertTrue(len(res1['stdout']) > 0) |
| 122 | |
| 123 | dep1_resource = self.client.resources.get(sid, 'dep1') |
| 124 | dep1_id = dep1_resource.physical_resource_id |
| 125 | dep1_dep = self.client.software_deployments.get(dep1_id) |
Steve Baker | 8c9aee1 | 2015-03-10 16:17:45 +1300 | [diff] [blame] | 126 | if hasattr(dep1_dep, 'updated_time'): |
| 127 | # Only check updated_time if the attribute exists. |
| 128 | # This allows latest heat agent code to be tested with |
| 129 | # Juno heat (which doesn't expose updated_time) |
| 130 | self.assertIsNotNone(dep1_dep.updated_time) |
| 131 | self.assertNotEqual( |
| 132 | dep1_dep.updated_time, |
| 133 | dep1_dep.creation_time) |
Steve Baker | f6c8f12 | 2015-02-10 13:54:46 +1300 | [diff] [blame] | 134 | |
| 135 | def test_server_software_config(self): |
Anastasia Kuznetsova | e45bfff | 2015-02-25 12:50:34 +0400 | [diff] [blame] | 136 | """ |
| 137 | Check that passed files with scripts are executed on created server. |
| 138 | |
| 139 | The alternative scenario is the following: |
| 140 | 1. Create a stack and pass files with scripts. |
| 141 | 2. Check that all stack resources are created successfully. |
| 142 | 3. Wait for all deployments. |
| 143 | 4. Check that stack was created. |
| 144 | 5. Check stack outputs. |
| 145 | """ |
| 146 | |
| 147 | parameters = { |
| 148 | 'key_name': self.keypair_name, |
| 149 | 'flavor': self.conf.instance_type, |
| 150 | 'image': self.conf.image_ref, |
| 151 | 'network': self.net['id'] |
| 152 | } |
| 153 | |
| 154 | files = { |
| 155 | 'cfg1.sh': CFG1_SH, |
| 156 | 'cfg3.pp': CFG3_PP |
| 157 | } |
| 158 | |
Steve Baker | 0b679bb | 2015-03-11 13:46:42 +1300 | [diff] [blame] | 159 | env_files, env = template_utils.process_environment_and_files( |
| 160 | self.conf.boot_config_env) |
| 161 | |
Anastasia Kuznetsova | e45bfff | 2015-02-25 12:50:34 +0400 | [diff] [blame] | 162 | # Launch stack |
Steve Baker | 8c9aee1 | 2015-03-10 16:17:45 +1300 | [diff] [blame] | 163 | self.stack_identifier = self.launch_stack( |
Anastasia Kuznetsova | e45bfff | 2015-02-25 12:50:34 +0400 | [diff] [blame] | 164 | stack_name=self.stack_name, |
| 165 | template_name='test_server_software_config.yaml', |
| 166 | parameters=parameters, |
Steve Baker | 0b679bb | 2015-03-11 13:46:42 +1300 | [diff] [blame] | 167 | files=dict(list(files.items()) + list(env_files.items())), |
| 168 | expected_status=None, |
| 169 | environment=env |
Anastasia Kuznetsova | e45bfff | 2015-02-25 12:50:34 +0400 | [diff] [blame] | 170 | ) |
| 171 | |
Anastasia Kuznetsova | e45bfff | 2015-02-25 12:50:34 +0400 | [diff] [blame] | 172 | # Check stack |
Steve Baker | 8c9aee1 | 2015-03-10 16:17:45 +1300 | [diff] [blame] | 173 | self.check_stack() |