Honor Nova's restriction for bdm fields

Nova does not allow None values for bdm fields. However it stores them
in image metadata for volume bdm during snapshot operation of volume
backed instance. Ec2Api sends them back to Nova during run instance
operation, which violates Nova's restriction.

Here we cut out None values from image bdms before use it.

Change-Id: Ice913c935e288f1cb615443324c05ca3c31efca6
(cherry picked from commit 239464ab74)
(cherry picked from commit 9434a2a1ac)
This commit is contained in:
Andrey Pavlov 2017-01-13 17:34:56 +03:00 committed by Feodor Tersin
parent 187095b411
commit 66bdf406e2
7 changed files with 16 additions and 4 deletions

View File

@ -2,3 +2,4 @@
host=review.openstack.org
port=29418
project=openstack/ec2-api.git
defaultbranch=stable/mitaka

View File

@ -1003,6 +1003,8 @@ def _build_block_device_mapping(context, block_device_mapping, os_image):
_populate_parsed_bdm_parameter(bdm, short_root_device_name)
else:
image_bdm = {k: v for k, v in six.iteritems(image_bdm)
if v is not None}
image_bdm.update(bdm)
bdm = image_bdm

View File

@ -639,6 +639,10 @@ def _get_subnet_host_routes_and_gateway_ip(context, route_table, cidr_block,
get('cidrs', [])))
if not subnet_gateway_is_used:
# NOTE(andrey-mp): add route to metadata server
host_routes.append(
{'destination': '169.254.169.254/32',
'nexthop': gateway_ip})
# NOTE(ft): gateway_ip is set to None to allow correct handling
# of 0.0.0.0/0 route by Neutron.
gateway_ip = None

View File

@ -458,7 +458,9 @@ OS_SUBNET_1 = {'id': ID_OS_SUBNET_1,
'ip_version': '4',
'cidr': CIDR_SUBNET_1,
'host_routes': [{'nexthop': IP_GATEWAY_SUBNET_1,
'destination': '10.10.0.0/16'}],
'destination': '10.10.0.0/16'},
{'nexthop': IP_GATEWAY_SUBNET_1,
'destination': '169.254.169.254/32'}],
'gateway_ip': IP_GATEWAY_SUBNET_1}
OS_SUBNET_2 = {'id': ID_OS_SUBNET_2,
'network_id': ID_OS_NETWORK_2,

View File

@ -1508,7 +1508,8 @@ class InstancePrivateTestCase(test_base.BaseTestCase):
'device_name': '/dev/vda',
'source_type': 'snapshot',
'snapshot_id': fakes.ID_OS_SNAPSHOT_1,
'delete_on_termination': True},
'delete_on_termination': True,
'disk_bus': None},
{'device_name': 'vdb',
'source_type': 'snapshot',
'snapshot_id': fakes.random_os_id(),

View File

@ -952,7 +952,9 @@ class RouteTableTestCase(base.ApiTestCase):
{'destination': '192.168.222.0/24',
'nexthop': '127.0.0.1'},
{'destination': '192.168.200.0/24',
'nexthop': '127.0.0.1'}]))
'nexthop': '127.0.0.1'},
{'destination': '169.254.169.254/32',
'nexthop': fakes.IP_GATEWAY_SUBNET_1}]))
self.assertEqual(None, gateway_ip)
host_routes, gateway_ip = (

View File

@ -1,6 +1,6 @@
[metadata]
name = ec2-api
version = 2.0.0
version = 2.0.1
summary = OpenStack Ec2api Service
description-file =
README.rst