From 58cdcabf1c6580fbf04ae54ca846692ec2127d78 Mon Sep 17 00:00:00 2001 From: liyingjun Date: Thu, 26 Jun 2014 01:55:30 +0800 Subject: [PATCH] Fix booting from volume when using api v3 The current code in novaclient/base.py, class BootingManagerWithFind do not take in account the differences required to boot an instance from a volume in API v3. V3 expects UUID as volume id and also the source type to be set. Change-Id: Id8cfb2d7811aead27cb26cf7ff615c7a9ed05d54 Close-bug: 1325303 --- novaclient/base.py | 4 ++++ novaclient/tests/v1_1/test_shell.py | 5 ++++- novaclient/tests/v3/test_shell.py | 12 ++++++++---- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/novaclient/base.py b/novaclient/base.py index 6b000f8fe..cdd439a98 100644 --- a/novaclient/base.py +++ b/novaclient/base.py @@ -204,11 +204,15 @@ class BootingManagerWithFind(ManagerWithFind): mapping_parts = mapping.split(':') source_id = mapping_parts[0] + bdm_dict['uuid'] = source_id + bdm_dict['boot_index'] = 0 if len(mapping_parts) == 1: bdm_dict['volume_id'] = source_id + bdm_dict['source_type'] = 'volume' elif len(mapping_parts) > 1: source_type = mapping_parts[1] + bdm_dict['source_type'] = source_type if source_type.startswith('snap'): bdm_dict['snapshot_id'] = source_id else: diff --git a/novaclient/tests/v1_1/test_shell.py b/novaclient/tests/v1_1/test_shell.py index 262fd6668..16b5878e5 100644 --- a/novaclient/tests/v1_1/test_shell.py +++ b/novaclient/tests/v1_1/test_shell.py @@ -266,7 +266,10 @@ class ShellTest(utils.TestCase): { 'volume_id': 'blah', 'delete_on_termination': '0', - 'device_name': 'vda' + 'device_name': 'vda', + 'uuid': 'blah', + 'boot_index': 0, + 'source_type': '' } ], 'imageRef': '', diff --git a/novaclient/tests/v3/test_shell.py b/novaclient/tests/v3/test_shell.py index 3d9c2b598..b8a96165e 100644 --- a/novaclient/tests/v3/test_shell.py +++ b/novaclient/tests/v3/test_shell.py @@ -329,7 +329,10 @@ class ShellTest(utils.TestCase): { 'volume_id': 'blah', 'delete_on_termination': '0', - 'device_name': 'vda' + 'device_name': 'vda', + 'boot_index': 0, + 'uuid': 'blah', + 'source_type': '' } ], 'image_ref': '', @@ -344,15 +347,16 @@ class ShellTest(utils.TestCase): 'source=volume,dest=volume,device=vda,size=1,format=ext4,' 'type=disk,shutdown=preserve some-server' ) + id = ('fake-id,source=volume,dest=volume,device=vda,size=1,' + 'format=ext4,type=disk,shutdown=preserve') self.assert_called_anytime( 'POST', '/servers', {'server': { 'flavor_ref': '1', 'name': 'some-server', 'os-block-device-mapping:block_device_mapping': [ - {'device_name': 'id', 'volume_id': - 'fake-id,source=volume,dest=volume,device=vda,size=1,' - 'format=ext4,type=disk,shutdown=preserve'}], + {'device_name': 'id', 'volume_id': id, + 'source_type': 'volume', 'boot_index': 0, 'uuid': id}], 'image_ref': '1', 'os-multiple-create:min_count': 1, 'os-multiple-create:max_count': 1,