ricolin | 945e14b | 2016-04-03 17:34:52 +0800 | [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 yaml |
| 14 | |
| 15 | from heat_integrationtests.functional import functional_base |
| 16 | |
| 17 | |
| 18 | class ReplaceDeprecatedResourceTest(functional_base.FunctionalTestsBase): |
| 19 | template = ''' |
| 20 | heat_template_version: "2013-05-23" |
| 21 | parameters: |
| 22 | flavor: |
| 23 | type: string |
| 24 | image: |
| 25 | type: string |
| 26 | network: |
| 27 | type: string |
| 28 | |
| 29 | resources: |
| 30 | config: |
| 31 | type: OS::Heat::SoftwareConfig |
| 32 | properties: |
| 33 | config: xxxx |
| 34 | |
| 35 | server: |
| 36 | type: OS::Nova::Server |
| 37 | properties: |
| 38 | image: {get_param: image} |
| 39 | flavor: {get_param: flavor} |
| 40 | networks: [{network: {get_param: network} }] |
| 41 | user_data_format: SOFTWARE_CONFIG |
| 42 | dep: |
| 43 | type: OS::Heat::SoftwareDeployments |
| 44 | properties: |
| 45 | config: {get_resource: config} |
| 46 | servers: {'0': {get_resource: server}} |
| 47 | signal_transport: NO_SIGNAL |
| 48 | outputs: |
| 49 | server: |
| 50 | value: {get_resource: server} |
| 51 | ''' |
| 52 | |
| 53 | deployment_group_snippet = ''' |
| 54 | type: OS::Heat::SoftwareDeploymentGroup |
| 55 | properties: |
| 56 | config: {get_resource: config} |
| 57 | servers: {'0': {get_resource: server}} |
| 58 | signal_transport: NO_SIGNAL |
| 59 | ''' |
| 60 | enable_cleanup = True |
| 61 | |
| 62 | def test_replace_software_deployments(self): |
| 63 | parms = {'flavor': self.conf.minimal_instance_type, |
| 64 | 'network': self.conf.fixed_network_name, |
| 65 | 'image': self.conf.minimal_image_ref |
| 66 | } |
| 67 | deployments_template = yaml.safe_load(self.template) |
| 68 | stack_identifier = self.stack_create( |
| 69 | parameters=parms, |
| 70 | template=deployments_template, |
| 71 | enable_cleanup=self.enable_cleanup) |
| 72 | expected_resources = {'config': 'OS::Heat::SoftwareConfig', |
| 73 | 'dep': 'OS::Heat::SoftwareDeployments', |
| 74 | 'server': 'OS::Nova::Server'} |
| 75 | resource = self.client.resources.get(stack_identifier, 'server') |
| 76 | self.assertEqual(expected_resources, |
| 77 | self.list_resources(stack_identifier)) |
| 78 | initial_phy_id = resource.physical_resource_id |
| 79 | resources = deployments_template['resources'] |
| 80 | resources['dep'] = yaml.safe_load(self.deployment_group_snippet) |
| 81 | self.update_stack( |
| 82 | stack_identifier, |
| 83 | deployments_template, |
| 84 | parameters=parms) |
| 85 | resource = self.client.resources.get(stack_identifier, 'server') |
| 86 | self.assertEqual(initial_phy_id, |
| 87 | resource.physical_resource_id) |
| 88 | expected_new_resources = {'config': 'OS::Heat::SoftwareConfig', |
| 89 | 'dep': 'OS::Heat::SoftwareDeploymentGroup', |
| 90 | 'server': 'OS::Nova::Server'} |
| 91 | self.assertEqual(expected_new_resources, |
| 92 | self.list_resources(stack_identifier)) |