Fix passing of bdm to run instances
Change-Id: Id6e25a45d027a8bbc91b1757efaaa7feeb224bab
This commit is contained in:
parent
8ead64f89b
commit
84c47ad0bd
|
@ -12,7 +12,6 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import ast
|
||||
import base64
|
||||
import collections
|
||||
import copy
|
||||
|
@ -636,31 +635,17 @@ def _parse_image_parameters(context, image_id, kernel_id, ramdisk_id):
|
|||
|
||||
|
||||
def _parse_block_device_mapping(context, block_device_mapping, os_image):
|
||||
# NOTE(ft): The following code allows reconfiguration of devices
|
||||
# according to list of new parameters supplied in EC2 call.
|
||||
# This code merges these parameters with information taken from image.
|
||||
image_root_device_name = os_image.properties.get('root_device_name')
|
||||
image_bdm = dict(
|
||||
(_block_device_strip_dev(bd.get('device_name') or
|
||||
image_root_device_name),
|
||||
bd)
|
||||
for bd in ast.literal_eval(
|
||||
os_image.properties.get('block_device_mapping', '[]'))
|
||||
if bd.get('device_name') or bd.get('boot_index') == 0)
|
||||
|
||||
# TODO(ft): check block_device_mapping structure
|
||||
bdm = {}
|
||||
for args_bd in (block_device_mapping or []):
|
||||
_cloud_parse_block_device_mapping(context, args_bd)
|
||||
dev_name = _block_device_strip_dev(args_bd.get('device_name'))
|
||||
if (not dev_name or dev_name not in image_bdm or
|
||||
'snapshot_id' in args_bd or 'volume_id' in args_bd):
|
||||
continue
|
||||
image_bd = image_bdm[dev_name]
|
||||
for key in ('device_name', 'delete_on_termination', 'virtual_name',
|
||||
'snapshot_id', 'volume_id', 'volume_size',
|
||||
'no_device'):
|
||||
args_bd[key] = args_bd.get(key, image_bd.get(key))
|
||||
|
||||
return block_device_mapping
|
||||
bdm[args_bd['device_name']] = ':'.join(
|
||||
[args_bd.get('snapshot_id', args_bd.get('volume_id', '')),
|
||||
('snap' if 'snapshot_id' in args_bd else
|
||||
'vol' if 'volume_id' in args_bd else ''),
|
||||
str(args_bd.get('volume_size', '')),
|
||||
str(args_bd.get('delete_on_termination', ''))])
|
||||
return bdm
|
||||
|
||||
|
||||
def _format_group_set(context, os_security_groups):
|
||||
|
|
|
@ -145,7 +145,7 @@ class InstanceTestCase(base.ApiTestCase):
|
|||
min_count=1, max_count=1,
|
||||
kernel_id=None, ramdisk_id=None,
|
||||
availability_zone=None,
|
||||
block_device_mapping=None,
|
||||
block_device_mapping={},
|
||||
security_groups=None,
|
||||
nics=[{'port-id': fakes.ID_OS_PORT_1}],
|
||||
key_name=None, userdata=None)
|
||||
|
@ -288,7 +288,7 @@ class InstanceTestCase(base.ApiTestCase):
|
|||
min_count=1, max_count=1,
|
||||
kernel_id=None, ramdisk_id=None,
|
||||
availability_zone=None,
|
||||
block_device_mapping=None,
|
||||
block_device_mapping={},
|
||||
security_groups=None,
|
||||
nics=[{'port-id': port_id}
|
||||
for port_id in port_ids],
|
||||
|
@ -1427,7 +1427,7 @@ class InstancePrivateTestCase(test_base.BaseTestCase):
|
|||
|
||||
res = instance_api._parse_block_device_mapping(
|
||||
fake_context, [], os_image)
|
||||
self.assertEqual([], res)
|
||||
self.assertEqual({}, res)
|
||||
|
||||
res = instance_api._parse_block_device_mapping(
|
||||
fake_context, [{'device_name': '/dev/vdf',
|
||||
|
@ -1446,27 +1446,13 @@ class InstancePrivateTestCase(test_base.BaseTestCase):
|
|||
os_image)
|
||||
self.assertThat(
|
||||
res,
|
||||
matchers.ListMatches([{'device_name': '/dev/vdf',
|
||||
'snapshot_id': fakes.ID_OS_SNAPSHOT_1,
|
||||
'delete_on_termination': True},
|
||||
{'device_name': '/dev/vdg',
|
||||
'snapshot_id': fakes.ID_OS_SNAPSHOT_2,
|
||||
'volume_size': 111,
|
||||
'delete_on_termination': False},
|
||||
{'device_name': '/dev/vdh',
|
||||
'volume_id': fakes.ID_OS_VOLUME_1,
|
||||
'delete_on_termination': True},
|
||||
{'device_name': '/dev/vdi',
|
||||
'volume_id': fakes.ID_OS_VOLUME_2,
|
||||
'delete_on_termination': True},
|
||||
{'device_name': '/dev/sdb1',
|
||||
'snapshot_id': fakes.ID_OS_SNAPSHOT_1,
|
||||
'volume_size': 55,
|
||||
'volume_id': None,
|
||||
'delete_on_termination': None,
|
||||
'virtual_name': None,
|
||||
'no_device': None}],
|
||||
orderless_lists=True))
|
||||
matchers.DictMatches(
|
||||
{'/dev/vdf': fakes.ID_OS_SNAPSHOT_1 + ':snap::True',
|
||||
'/dev/vdg': fakes.ID_OS_SNAPSHOT_2 + ':snap:111:False',
|
||||
'/dev/vdh': fakes.ID_OS_VOLUME_1 + ':vol::True',
|
||||
'/dev/vdi': fakes.ID_OS_VOLUME_2 + ':vol::True',
|
||||
'/dev/sdb1': '::55:'},
|
||||
orderless_lists=True))
|
||||
|
||||
@mock.patch('ec2api.api.instance.novadb')
|
||||
@mock.patch('novaclient.v1_1.client.Client')
|
||||
|
|
Loading…
Reference in New Issue