From e4891831ce5c2582dcc7f8fd2c436a655b951540 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Fri, 21 Aug 2020 10:27:45 -0400 Subject: [PATCH] Better handle missing elements from net config Prevents situations with an un-editable, invalid config being stuck. --- daemon-common/common.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/daemon-common/common.py b/daemon-common/common.py index 8777ecc8..d9da50fe 100644 --- a/daemon-common/common.py +++ b/daemon-common/common.py @@ -310,12 +310,24 @@ def getDomainNetworks(parsed_xml, stats_data): dnets = [] for device in parsed_xml.devices.getchildren(): if device.tag == 'interface': - net_type = device.attrib.get('type') - net_mac = device.mac.attrib.get('address') - net_bridge = device.source.attrib.get(net_type) - net_model = device.model.attrib.get('type') - net_stats_list = [x for x in stats_data.get('net_stats', []) if x.get('bridge') == net_bridge] try: + net_type = device.attrib.get('type') + except: + net_type = None + try: + net_mac = device.mac.attrib.get('address') + except: + net_mac = None + try: + net_bridge = device.source.attrib.get(net_type) + except: + net_bridge = None + try: + net_model = device.model.attrib.get('type') + except: + net_model = None + try: + net_stats_list = [x for x in stats_data.get('net_stats', []) if x.get('bridge') == net_bridge] net_stats = net_stats_list[0] except: net_stats = {}