Skip to content

Commit 80c0604

Browse files
authored
Make the minigraph_facts module backward compatible (#2597)
What is the motivation for this PR? The minigraph_facts module uses library sonic_py_common.multi_asic.get_namespace_list to get the namespace list and store the value in variable namespace_list. On older SONiC image, sonic_py_common.multi_asic is not available. Running this module will fail with ImportError. How did you do it? This change improved this module to make it backward compatible with older SONiC images by protecting sonic_py_common.multi_asic importing using try...except. When ImportError is caught, just assign value [''] to variable namespace_list. How did you verify/test it? Test run the minigaph_facts module on image supports sonic_py_common.multi_asic and on image does not support sonic_py_common.multi_asic. Signed-off-by: Xin Wang <xiwang5@microsoft.com>
1 parent 19a520b commit 80c0604

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

ansible/library/minigraph_facts.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import ipaddr as ipaddress
1010
from collections import defaultdict
1111
from natsort import natsorted
12-
from sonic_py_common import multi_asic
1312

1413
from lxml import etree as ET
1514
from lxml.etree import QName
@@ -61,7 +60,12 @@ def parse_png(png, hname):
6160
console_port = ''
6261
mgmt_dev = ''
6362
mgmt_port = ''
64-
namespace_list = multi_asic.get_namespace_list()
63+
try:
64+
from sonic_py_common import multi_asic
65+
namespace_list = multi_asic.get_namespace_list()
66+
except ImportError:
67+
namespace_list = ['']
68+
6569
for child in png:
6670
if child.tag == str(QName(ns, "DeviceInterfaceLinks")):
6771
for link in child.findall(str(QName(ns, "DeviceLinkBase"))):
@@ -165,7 +169,7 @@ def parse_dpg(dpg, hname):
165169
else:
166170
intf['mask'] = str(prefix_len)
167171
intf.update({'attachto': intfname, 'prefixlen': int(prefix_len)})
168-
172+
169173
# TODO: remove peer_addr after dependency removed
170174
ipaddr_val = int(ipn.ip)
171175
peer_addr_val = None
@@ -179,7 +183,7 @@ def parse_dpg(dpg, hname):
179183
peer_addr_val = ipaddr_val + 1
180184
else:
181185
peer_addr_val = ipaddr_val - 1
182-
186+
183187
if peer_addr_val is not None:
184188
intf['peer_addr'] = ipaddress.IPAddress(peer_addr_val)
185189
intfs.append(intf)

0 commit comments

Comments
 (0)