diff --git a/coriolis/tasks/osmorphing_tasks.py b/coriolis/tasks/osmorphing_tasks.py index 7e6aafc41..2ff9384c1 100644 --- a/coriolis/tasks/osmorphing_tasks.py +++ b/coriolis/tasks/osmorphing_tasks.py @@ -1,6 +1,8 @@ # Copyright 2016 Cloudbase Solutions Srl # All Rights Reserved. +import re + from oslo_log import log as logging from coriolis import constants @@ -14,6 +16,35 @@ LOG = logging.getLogger(__name__) +def _reorder_root_disk(volumes_info, root_device): + """ + Reorders volumes_info so that the root disk will always be the first volume + + root_device is returned by the osmount tools as the root partition device + (i.e. /dev/vdd2). We need to strip the trailing digits to get the actual + disk device. After that, we convert the last letter of the disk device name + into the equivalent index by alphabetical order (starting with 0, so 'a' -> 0). + Then we just swap the indexes in the volumes_info list. + """ + if not root_device: + LOG.warn('os_root_dev was not returned by OSMount Tools. ' + 'Skipping root disk reordering') + return + + pattern = r'[0-9]' + root_disk = re.sub(pattern, '', root_device) + disk_nmb = ord(root_disk[-1]) - 98 + if disk_nmb: + if disk_nmb < len(volumes_info): + volumes_info[0], volumes_info[disk_nmb] = ( + volumes_info[disk_nmb], volumes_info[0]) + else: + LOG.warn('Disk device name index out of range: %s for device %s' + 'Skipping root disk reordering', disk_nmb, root_disk) + return + + + class OSMorphingTask(base.TaskRunner): @classmethod @@ -28,7 +59,7 @@ def get_required_task_info_properties(cls): @classmethod def get_returned_task_info_properties(cls): - return [] + return ["instance_deployment_info"] @classmethod def get_required_provider_types(cls): @@ -53,6 +84,7 @@ def _run(self, ctxt, instance, origin, destination, task_info, osmorphing_connection_info = base.unmarshal_migr_conn_info( task_info['osmorphing_connection_info']) osmorphing_info = task_info.get('osmorphing_info', {}) + instance_deployment_info = task_info.get('instance_deployment_info', {}) user_scripts = task_info.get("user_scripts") instance_script = None @@ -72,7 +104,13 @@ def _run(self, ctxt, instance, origin, destination, task_info, instance_script, event_handler) - return {} + volumes_info = instance_deployment_info.get('volumes_info', []) + LOG.debug('Volumes info before root disk reordering: %s', volumes_info) + _reorder_root_disk(volumes_info, osmorphing_info.get('os_root_dev')) + LOG.debug('Volumes info after root disk reordering: %s', volumes_info) + + return { + 'instance_deployment_info': instance_deployment_info} class DeployOSMorphingResourcesTask(base.TaskRunner):