From fdf14fa4362383ef8b1186a54a4cae462dcd6811 Mon Sep 17 00:00:00 2001 From: Prakash Bailkeri Date: Wed, 24 Feb 2016 21:16:36 +0530 Subject: [PATCH] Handle KeyError if aap json data is missing mac field Currently UI and neutron plugin db is sending aap mac as empty string "". This scenario is handled in the current code. But if the mac_address field is missing in the input json data or is set as "NULL", api server doesn't handle it. In case of missing field, KeyError is thrown and in case of "NULL", the mac_address is not defaulted to port mac. Fix the parsing of mac_address field of aap config Change-Id: I1c48406a3d21376cc852b605a8ce14700c17f1e4 Closes-bug: #1549339 (cherry picked from commit c1962f7aad3dbc5ae35220738418e2e3c0ccf376) --- src/config/api-server/vnc_cfg_types.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/config/api-server/vnc_cfg_types.py b/src/config/api-server/vnc_cfg_types.py index 1281a8ba278..1341c6245cd 100644 --- a/src/config/api-server/vnc_cfg_types.py +++ b/src/config/api-server/vnc_cfg_types.py @@ -462,7 +462,7 @@ def pre_dbe_create(cls, tenant_name, obj_dict, db_conn): aap_config = obj_dict.get( 'virtual_machine_interface_allowed_address_pairs', {}) for aap in aap_config.get('allowed_address_pair', []): - if aap['mac'] == "": + if not aap.get('mac', None): aap['mac'] = mac_addrs_dict['mac_address'][0] if 'virtual_machine_interface_bindings' in obj_dict: @@ -548,7 +548,7 @@ def pre_dbe_update(cls, id, fq_name, obj_dict, db_conn, aap_config = obj_dict.get( 'virtual_machine_interface_allowed_address_pairs', {}) for aap in aap_config.get('allowed_address_pair', []): - if aap['mac'] == "": + if not aap.get('mac', None): aap['mac'] = read_result[ 'virtual_machine_interface_mac_addresses']['mac_address'][0]