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