diff --git a/heat/engine/resources/openstack/cinder/volume.py b/heat/engine/resources/openstack/cinder/volume.py index b40b9e26f9..2c0974adbc 100644 --- a/heat/engine/resources/openstack/cinder/volume.py +++ b/heat/engine/resources/openstack/cinder/volume.py @@ -663,7 +663,7 @@ class CinderVolume(vb.BaseVolume, sh.SchedulerHintsMixin): self.IMAGE_REF, self.IMAGE, self.SOURCE_VOLID) props = dict( (key, value) for (key, value) in - six.iteritems(defn.properties(self.properties_schema)) + self.properties.data.items() if key not in ignore_props and value is not None) props[self.BACKUP_ID] = backup_id return defn.freeze(properties=props) diff --git a/heat/engine/resources/openstack/nova/server.py b/heat/engine/resources/openstack/nova/server.py index f4d53c73c4..45d0e9ecfb 100644 --- a/heat/engine/resources/openstack/nova/server.py +++ b/heat/engine/resources/openstack/nova/server.py @@ -1607,8 +1607,8 @@ class Server(server_base.BaseServer, sh.SchedulerHintsMixin, def handle_restore(self, defn, restore_data): image_id = restore_data['resource_data']['snapshot_image_id'] - props = dict((k, v) for k, v in self.properties.items() - if k in self.properties.data) + props = dict((k, v) for k, v in self.properties.data.items() + if v is not None) for key in [self.BLOCK_DEVICE_MAPPING, self.BLOCK_DEVICE_MAPPING_V2, self.NETWORKS]: if props.get(key) is not None: diff --git a/heat/tests/generic_resource.py b/heat/tests/generic_resource.py index 165c435f6d..b7b87e8852 100644 --- a/heat/tests/generic_resource.py +++ b/heat/tests/generic_resource.py @@ -13,7 +13,6 @@ import collections from oslo_log import log as logging -import six from heat.engine import attributes from heat.engine import constraints @@ -373,7 +372,7 @@ class ResourceWithRestoreType(ResWithComplexPropsAndAttrs): def handle_restore(self, defn, data): props = dict( (key, value) for (key, value) in - six.iteritems(defn.properties(self.properties_schema)) + self.properties.data.items() if value is not None) value = data['resource_data']['a_string'] props['a_string'] = value diff --git a/heat_integrationtests/common/test.py b/heat_integrationtests/common/test.py index 842f4e774b..9944bd16d0 100644 --- a/heat_integrationtests/common/test.py +++ b/heat_integrationtests/common/test.py @@ -614,6 +614,17 @@ class HeatIntegrationTest(testscenarios.WithScenarios, info = self.client.stacks.abandon(stack_id=stack_id) return info + def stack_snapshot(self, stack_id, + wait_for_status='SNAPSHOT_COMPLETE'): + snapshot = self.client.stacks.snapshot(stack_id=stack_id) + self._wait_for_stack_status(stack_id, wait_for_status) + return snapshot['id'] + + def stack_restore(self, stack_id, snapshot_id, + wait_for_status='RESTORE_COMPLETE'): + self.client.stacks.restore(stack_id, snapshot_id) + self._wait_for_stack_status(stack_id, wait_for_status) + def stack_suspend(self, stack_identifier): if (self.conf.skip_test_stack_action_list and 'SUSPEND' in self.conf.skip_test_stack_action_list): diff --git a/heat_integrationtests/functional/test_snapshot_restore.py b/heat_integrationtests/functional/test_snapshot_restore.py new file mode 100644 index 0000000000..f63a360055 --- /dev/null +++ b/heat_integrationtests/functional/test_snapshot_restore.py @@ -0,0 +1,76 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + + +from heat_integrationtests.functional import functional_base + + +class StackSnapshotRestoreTest(functional_base.FunctionalTestsBase): + + def setUp(self): + super(StackSnapshotRestoreTest, self).setUp() + if not self.conf.minimal_image_ref: + raise self.skipException("No image configured to test") + + if not self.conf.minimal_instance_type: + raise self.skipException( + "No minimal_instance_type configured to test") + + self.assign_keypair() + + def test_stack_snapshot_restore(self): + template = ''' +heat_template_version: ocata +parameters: + keyname: + type: string + flavor: + type: string + image: + type: string + network: + type: string +resources: + my_port: + type: OS::Neutron::Port + properties: + network: {get_param: network} + my_server: + type: OS::Nova::Server + properties: + image: {get_param: image} + flavor: {get_param: flavor} + key_name: {get_param: keyname} + networks: [{port: {get_resource: my_port} }] + +''' + + def get_server_image(server_id): + server = self.compute_client.servers.get(server_id) + return server.image['id'] + + parameters = {'keyname': self.keypair_name, + 'flavor': self.conf.minimal_instance_type, + 'image': self.conf.minimal_image_ref, + 'network': self.conf.fixed_network_name} + stack_identifier = self.stack_create(template=template, + parameters=parameters) + server_resource = self.client.resources.get( + stack_identifier, 'my_server') + server_id = server_resource.physical_resource_id + prev_image_id = get_server_image(server_id) + + # Do snapshot and restore + snapshot_id = self.stack_snapshot(stack_identifier) + self.stack_restore(stack_identifier, snapshot_id) + + self.assertNotEqual(prev_image_id, get_server_image(server_id))