Skip to content

Commit a10b795

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Use the safe get_binding_profile"
2 parents ab34c94 + 8ec918a commit a10b795

File tree

2 files changed

+19
-24
lines changed

2 files changed

+19
-24
lines changed

nova/cmd/manage.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1682,7 +1682,7 @@ def _get_ports(ctxt, instance, neutron):
16821682
@staticmethod
16831683
def _has_request_but_no_allocation(port):
16841684
request = port.get(constants.RESOURCE_REQUEST)
1685-
binding_profile = port.get(constants.BINDING_PROFILE, {}) or {}
1685+
binding_profile = neutron_api.get_binding_profile(port)
16861686
allocation = binding_profile.get(constants.ALLOCATION)
16871687
# We are defensive here about 'resources' and 'required' in the
16881688
# 'resource_request' as neutron API is not clear about those fields
@@ -1870,7 +1870,7 @@ def _get_port_allocations_to_heal(
18701870
# We also need to record the RP we are allocated from in the
18711871
# port. This will be sent back to Neutron before the allocation
18721872
# is updated in placement
1873-
binding_profile = port.get(constants.BINDING_PROFILE, {}) or {}
1873+
binding_profile = neutron_api.get_binding_profile(port)
18741874
binding_profile[constants.ALLOCATION] = rp_uuid
18751875
port[constants.BINDING_PROFILE] = binding_profile
18761876

@@ -1887,10 +1887,10 @@ def _update_ports(self, neutron, ports_to_update, output):
18871887
succeeded = []
18881888
try:
18891889
for port in ports_to_update:
1890+
profile = neutron_api.get_binding_profile(port)
18901891
body = {
18911892
'port': {
1892-
constants.BINDING_PROFILE:
1893-
port[constants.BINDING_PROFILE]
1893+
constants.BINDING_PROFILE: profile
18941894
}
18951895
}
18961896
output(
@@ -1917,7 +1917,7 @@ def _rollback_port_updates(neutron, ports_to_rollback, output):
19171917
manual_rollback_needed = []
19181918
last_exc = None
19191919
for port in ports_to_rollback:
1920-
profile = port[constants.BINDING_PROFILE]
1920+
profile = neutron_api.get_binding_profile(port)
19211921
profile.pop(constants.ALLOCATION)
19221922
body = {
19231923
'port': {

nova/network/neutronv2/api.py

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def _load_auth_plugin(conf):
8282
raise neutron_client_exc.Unauthorized(message=err_msg)
8383

8484

85-
def _get_binding_profile(port):
85+
def get_binding_profile(port):
8686
"""Convenience method to get the binding:profile from the port
8787
8888
The binding:profile in the port is undefined in the networking service
@@ -272,7 +272,7 @@ def _clear_migration_port_profile(
272272
# If the port already has a migration profile and if
273273
# it is to be torn down, then we need to clean up
274274
# the migration profile.
275-
port_profile = _get_binding_profile(p)
275+
port_profile = get_binding_profile(p)
276276
if not port_profile:
277277
continue
278278
if constants.MIGRATING_ATTR in port_profile:
@@ -293,7 +293,7 @@ def _setup_migration_port_profile(
293293
# the given 'host'.
294294
host_id = p.get(constants.BINDING_HOST_ID)
295295
if host_id != host:
296-
port_profile = _get_binding_profile(p)
296+
port_profile = get_binding_profile(p)
297297
# If the "migrating_to" attribute already points at the given
298298
# host, then skip the port update call since we're not changing
299299
# anything.
@@ -587,7 +587,7 @@ def _unbind_ports(self, context, ports,
587587
port_profile = {}
588588
network = {}
589589
else:
590-
port_profile = port.get(constants.BINDING_PROFILE, {})
590+
port_profile = get_binding_profile(port)
591591
net_id = port.get('network_id')
592592
if net_id in networks:
593593
network = networks.get(net_id)
@@ -1004,7 +1004,7 @@ def allocate_for_instance(self, context, instance, vpn,
10041004
# only communicate the allocations if the port has resource
10051005
# requests
10061006
if port.get(constants.RESOURCE_REQUEST):
1007-
profile = port.get(constants.BINDING_PROFILE, {})
1007+
profile = get_binding_profile(port)
10081008
# NOTE(gibi): In the resource provider mapping there can be
10091009
# more than one RP fulfilling a request group. But resource
10101010
# requests of a Neutron port is always mapped to a
@@ -1117,11 +1117,9 @@ def _update_ports_for_instance(self, context, instance, neutron,
11171117
'device_owner': zone}}
11181118
if (requested_ports_dict and
11191119
request.port_id in requested_ports_dict and
1120-
requested_ports_dict[request.port_id].get(
1121-
constants.BINDING_PROFILE)):
1122-
port_req_body['port'][constants.BINDING_PROFILE] = (
1123-
requested_ports_dict[request.port_id][
1124-
constants.BINDING_PROFILE])
1120+
get_binding_profile(requested_ports_dict[request.port_id])):
1121+
port_req_body['port'][constants.BINDING_PROFILE] = \
1122+
get_binding_profile(requested_ports_dict[request.port_id])
11251123
try:
11261124
self._populate_neutron_extension_values(
11271125
context, instance, request.pci_request_id, port_req_body,
@@ -1441,10 +1439,7 @@ def _populate_neutron_binding_profile(self, instance, pci_request_id,
14411439
_('PCI device not found for request ID %s.') %
14421440
pci_request_id)
14431441
pci_dev = pci_devices.pop()
1444-
if port_req_body['port'].get(constants.BINDING_PROFILE) is None:
1445-
port_req_body['port'][constants.BINDING_PROFILE] = {}
1446-
profile = copy.deepcopy(
1447-
port_req_body['port'][constants.BINDING_PROFILE])
1442+
profile = copy.deepcopy(get_binding_profile(port_req_body['port']))
14481443
profile.update(self._get_pci_device_profile(pci_dev))
14491444
port_req_body['port'][constants.BINDING_PROFILE] = profile
14501445

@@ -1669,8 +1664,8 @@ def deallocate_port_for_instance(self, context, instance, port_id):
16691664
# if there is resource associated to this port then that needs to
16701665
# be deallocated so lets return info about such allocation
16711666
resource_request = port.get(constants.RESOURCE_REQUEST)
1672-
allocated_rp = port.get(
1673-
constants.BINDING_PROFILE, {}).get(constants.ALLOCATION)
1667+
profile = get_binding_profile(port)
1668+
allocated_rp = profile.get(constants.ALLOCATION)
16741669
if resource_request and allocated_rp:
16751670
port_allocation = {
16761671
allocated_rp: resource_request.get('resources', {})}
@@ -1935,7 +1930,7 @@ def _get_trusted_mode_from_port(port):
19351930
If port binding does not provide any information about trusted
19361931
status this function is returning None
19371932
"""
1938-
value = _get_binding_profile(port).get('trusted')
1933+
value = get_binding_profile(port).get('trusted')
19391934
if value is not None:
19401935
# This allows the user to specify things like '1' and 'yes' in
19411936
# the port binding profile and we can handle it as a boolean.
@@ -2889,7 +2884,7 @@ def _build_vif_model(self, context, client, current_neutron_port,
28892884
vnic_type=current_neutron_port.get('binding:vnic_type',
28902885
network_model.VNIC_TYPE_NORMAL),
28912886
type=current_neutron_port.get('binding:vif_type'),
2892-
profile=_get_binding_profile(current_neutron_port),
2887+
profile=get_binding_profile(current_neutron_port),
28932888
details=current_neutron_port.get('binding:vif_details'),
28942889
ovs_interfaceid=ovs_interfaceid,
28952890
devname=devname,
@@ -3218,7 +3213,7 @@ def _update_port_binding_for_instance(self, context, instance, host,
32183213
network_model.VIF_TYPE_BINDING_FAILED)
32193214
for p in ports:
32203215
updates = {}
3221-
binding_profile = _get_binding_profile(p)
3216+
binding_profile = get_binding_profile(p)
32223217

32233218
# We need to update the port binding if the host has changed or if
32243219
# the binding is clearly wrong due to previous lost messages.

0 commit comments

Comments
 (0)