Fix handle_restore for server and volume resources

When resource references are used for properties restore
does not work for nova server and volume resources.

This patch fixes it and adds a functional test for it.

Change-Id: I34efb3f4e0d3578d95134793f5c5d413667790e0
Closes-Bug: #1687009
This commit is contained in:
rabi 2017-05-04 13:02:28 +05:30
parent 660d8d517d
commit a8129573d2
5 changed files with 91 additions and 5 deletions

View File

@ -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)

View File

@ -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:

View File

@ -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

View File

@ -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):

View File

@ -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))