Skip to content

Commit 110d1b8

Browse files
Merge branch 'multiasic_minigraph' of github.com:SuvarnaMeenakshi/sonic-buildimage into comment_fix
2 parents 520c43b + 15228c1 commit 110d1b8

File tree

6 files changed

+37
-53
lines changed

6 files changed

+37
-53
lines changed

src/sonic-config-engine/sonic-cfggen

+1-1
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ def main():
278278

279279
if args.platform_info:
280280
if asic_name is not None and asic_role.lower() == "backend":
281-
mac = get_system_mac(asic_name)
281+
mac = get_system_mac(namespace=asic_name)
282282
else:
283283
mac = get_system_mac()
284284

src/sonic-config-engine/sonic_device_util.py

+15-21
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import subprocess
55
import re
66
from natsort import natsorted
7+
import glob
78
DOCUMENTATION = '''
89
---
910
module: sonic_device_util
@@ -19,7 +20,7 @@
1920
'''
2021
SONIC_DEVICE_PATH = '/usr/share/sonic/device'
2122
NPU_NAME_PREFIX = 'asic'
22-
23+
NAMESPACE_PATH_GLOB = '/run/netns/*'
2324
def get_machine_info():
2425
if not os.path.isfile('/host/machine.conf'):
2526
return None
@@ -39,35 +40,28 @@ def get_npu_id_from_name(npu_name):
3940
return None
4041

4142
def get_num_npus():
42-
platform = get_platform_info(get_machine_info())
43-
asic_conf_file_path = os.path.join(SONIC_DEVICE_PATH, platform, 'asic.conf')
44-
if not os.path.isfile(asic_conf_file_path):
43+
platform = get_platform_info(get_machine_info())
44+
asic_conf_file_path = os.path.join(SONIC_DEVICE_PATH, platform, 'asic.conf')
45+
if not os.path.isfile(asic_conf_file_path):
4546
return 1
46-
with open(asic_conf_file_path) as asic_conf_file:
47-
for line in asic_conf_file:
48-
tokens = line.split('=')
47+
with open(asic_conf_file_path) as asic_conf_file:
48+
for line in asic_conf_file:
49+
tokens = line.split('=')
4950
if len(tokens) < 2:
50-
continue
51-
if tokens[0].lower() == 'num_asic':
52-
num_npus = tokens[1].strip()
53-
return num_npus
51+
continue
52+
if tokens[0].lower() == 'num_asic':
53+
num_npus = tokens[1].strip()
54+
return num_npus
5455

5556
def get_namespaces():
5657
"""
5758
In a multi NPU platform, each NPU is in a Linux Namespace.
5859
This method returns list of all the Namespace present on the device
5960
"""
6061
ns_list = []
61-
try:
62-
proc = subprocess.Popen('ip netns list | cut -d"(" -f1',
63-
stdout=subprocess.PIPE,
64-
shell=True,
65-
stderr=subprocess.STDOUT)
66-
stdout = proc.communicate()[0]
67-
proc.wait()
68-
ns_list = [n for n in stdout.split()]
69-
except OSError,e:
70-
raise OSError("Unable to get namespace list")
62+
for path in glob.glob(NAMESPACE_PATH_GLOB):
63+
ns = os.path.basename(path)
64+
ns_list.append(ns)
7165
return natsorted(ns_list)
7266

7367
def get_platform_info(machine_info):

src/sonic-config-engine/tests/multi_npu_data/sample_port_config-0.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ Ethernet12 37,38,39,40 Ethernet1/4 Eth3-ASIC0
66
Ethernet-BP0 13,14,15,16 Ethernet-BP0 Eth4-ASIC0
77
Ethernet-BP4 17,18,19,20 Ethernet-BP4 Eth5-ASIC0
88
Ethernet-BP8 21,22,23,24 Ethernet-BP8 Eth6-ASIC0
9-
Ethernet-BP12 25,26,27,28 Ethernet-BP12 Eth7-ASIC0
9+
Ethernet-BP12 25,26,27,28 Ethernet-BP12 Eth7-ASIC0

src/sonic-config-engine/tests/multi_npu_data/sample_port_config-2.ini

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,4 @@ Ethernet-BP268 49,50,51,52 Ethernet-BP268 Eth3-ASIC2
66
Ethernet-BP272 45,46,47,48 Ethernet-BP272 Eth4-ASIC2
77
Ethernet-BP276 41,42,43,44 Ethernet-BP276 Eth5-ASIC2
88
Ethernet-BP280 37,38,39,40 Ethernet-BP280 Eth6-ASIC2
9-
Ethernet-BP284 33,34,35,36 Ethernet-BP284 Eth7-ASIC2
10-
11-
9+
Ethernet-BP284 33,34,35,36 Ethernet-BP284 Eth7-ASIC2

src/sonic-config-engine/tests/multi_npu_data/sample_port_config-3.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ Ethernet-BP396 17,18,19,20 Ethernet-BP396 Eth3-ASIC3
66
Ethernet-BP400 13,14,15,16 Ethernet-BP400 Eth4-ASIC3
77
Ethernet-BP404 9,10,11,12 Ethernet-BP404 Eth5-ASIC3
88
Ethernet-BP408 5,6,7,8 Ethernet-BP408 Eth6-ASIC3
9-
Ethernet-BP412 1,2,3,4 Ethernet-BP412 Eth7-ASIC3
9+
Ethernet-BP412 1,2,3,4 Ethernet-BP412 Eth7-ASIC3

src/sonic-config-engine/tests/test_multinpu_cfggen.py

+18-26
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ def setUp(self):
2222
for asic in range(NUM_ASIC):
2323
self.port_config.append(os.path.join(self.test_data_dir, "sample_port_config-{}.ini".format(asic)))
2424

25-
2625
def run_script(self, argument, check_stderr=False):
2726
print '\n Running sonic-cfggen ' + argument
2827
if check_stderr:
@@ -40,7 +39,6 @@ def run_script(self, argument, check_stderr=False):
4039
def run_diff(self, file1, file2):
4140
return subprocess.check_output('diff -u {} {} || true'.format(file1, file2), shell=True)
4241

43-
4442
def run_script_for_asic(self,argument,asic, port_config=None):
4543
argument = "{} -n asic{} ".format(argument, asic)
4644
if port_config:
@@ -52,16 +50,14 @@ def test_dummy_run(self):
5250
argument = ''
5351
output = self.run_script(argument)
5452
self.assertEqual(output, '')
55-
53+
5654
def test_hwsku(self):
5755
argument = "-v \"DEVICE_METADATA[\'localhost\'][\'hwsku\']\" -m \"{}\"".format(self.sample_graph)
5856
output = self.run_script(argument)
5957
self.assertEqual(output.strip(), SKU)
60-
6158
for asic in range(NUM_ASIC):
6259
output = self.run_script_for_asic(argument, asic)
6360
self.assertEqual(output.strip(), SKU)
64-
6561

6662
def test_print_data(self):
6763
argument = "-m \"{}\" --print-data".format(self.sample_graph)
@@ -70,8 +66,7 @@ def test_print_data(self):
7066
for asic in range(NUM_ASIC):
7167
output = self.run_script_for_asic(argument, asic)
7268
self.assertGreater(len(output.strip()) , 0)
73-
74-
69+
7570
def test_additional_json_data(self):
7671
argument = '-a \'{"key1":"value1"}\' -v key1'
7772
output = self.run_script(argument)
@@ -80,7 +75,6 @@ def test_additional_json_data(self):
8075
output = self.run_script_for_asic(argument, asic)
8176
self.assertEqual(output.strip(), 'value1')
8277

83-
8478
def test_read_yaml(self):
8579
argument = '-v yml_item -y ' + os.path.join(self.test_dir, 'test.yml')
8680
output = yaml.load(self.run_script(argument))
@@ -123,20 +117,20 @@ def test_mgmt_port(self):
123117
for asic in range(NUM_ASIC):
124118
output = json.loads(self.run_script_for_asic(argument, asic, self.port_config[asic]))
125119
self.assertDictEqual(output, {})
126-
120+
127121
def test_frontend_asic_portchannels(self):
128122
argument = "-m {} -p {} -n asic0 --var-json \"PORTCHANNEL\"".format(self.sample_graph, self.port_config[0])
129123
output = json.loads(self.run_script(argument))
130124
self.assertDictEqual(output, \
131-
{'PortChannel0002': {'admin_status': 'up', 'min_links': '2', 'members': ['Ethernet0', 'Ethernet4'], 'mtu': '9100'},
132-
'PortChannel4001': {'admin_status': 'up', 'min_links': '2', 'members': ['Ethernet-BP0', 'Ethernet-BP4'], 'mtu': '9100'},
125+
{'PortChannel0002': {'admin_status': 'up', 'min_links': '2', 'members': ['Ethernet0', 'Ethernet4'], 'mtu': '9100'},
126+
'PortChannel4001': {'admin_status': 'up', 'min_links': '2', 'members': ['Ethernet-BP0', 'Ethernet-BP4'], 'mtu': '9100'},
133127
'PortChannel4002': {'admin_status': 'up', 'min_links': '2', 'members': ['Ethernet-BP8', 'Ethernet-BP12'], 'mtu': '9100'}})
134-
128+
135129
def test_backend_asic_portchannels(self):
136130
argument = "-m {} -p {} -n asic3 --var-json \"PORTCHANNEL\"".format(self.sample_graph, self.port_config[3])
137131
output = json.loads(self.run_script(argument))
138132
self.assertDictEqual(output, \
139-
{'PortChannel4013': {'admin_status': 'up', 'min_links': '2', 'members': ['Ethernet-BP384', 'Ethernet-BP388'], 'mtu': '9100'},
133+
{'PortChannel4013': {'admin_status': 'up', 'min_links': '2', 'members': ['Ethernet-BP384', 'Ethernet-BP388'], 'mtu': '9100'},
140134
'PortChannel4014': {'admin_status': 'up', 'min_links': '2', 'members': ['Ethernet-BP392', 'Ethernet-BP396'], 'mtu': '9100'}})
141135

142136
def test_frontend_asic_portchannel_mem(self):
@@ -145,34 +139,33 @@ def test_frontend_asic_portchannel_mem(self):
145139
self.assertListEqual(output.keys(), \
146140
['PortChannel4002|Ethernet-BP8', 'PortChannel0002|Ethernet0', 'PortChannel0002|Ethernet4', 'PortChannel4002|Ethernet-BP12', 'PortChannel4001|Ethernet-BP0', 'PortChannel4001|Ethernet-BP4'])
147141

148-
149142
def test_backend_asic_portchannels_mem(self):
150143
argument = "-m {} -p {} -n asic3 --var-json \"PORTCHANNEL_MEMBER\"".format(self.sample_graph, self.port_config[3])
151144
output = json.loads(self.run_script(argument))
152145
self.assertListEqual(output.keys(), \
153146
['PortChannel4013|Ethernet-BP384', 'PortChannel4014|Ethernet-BP392', 'PortChannel4014|Ethernet-BP396', 'PortChannel4013|Ethernet-BP388'])
154147

155148
def test_frontend_asic_portchannel_intf(self):
156-
argument = "-m {} -p {} -n asic0 --var-json \"PORTCHANNEL_INTERFACE\"".format(self.sample_graph, self.port_config[0])
149+
argument = "-m {} -p {} -n asic0 --var-json \"PORTCHANNEL_INTERFACE\"".format(self.sample_graph, self.port_config[0])
157150
output = json.loads(self.run_script(argument))
158151
self.assertListEqual(output.keys(), \
159152
['PortChannel4001|10.1.0.1/31', 'PortChannel0002|FC00::1/126', 'PortChannel4002|10.1.0.3/31', 'PortChannel0002', 'PortChannel0002|10.0.0.0/31', 'PortChannel4001', 'PortChannel4002'])
160-
153+
161154
def test_backend_asic_portchannel_intf(self):
162-
argument = "-m {} -p {} -n asic3 --var-json \"PORTCHANNEL_INTERFACE\"".format(self.sample_graph, self.port_config[3])
155+
argument = "-m {} -p {} -n asic3 --var-json \"PORTCHANNEL_INTERFACE\"".format(self.sample_graph, self.port_config[3])
163156
output = json.loads(self.run_script(argument))
164157
self.assertListEqual(output.keys(), \
165158
['PortChannel4013', 'PortChannel4013|10.1.0.2/31', 'PortChannel4014', 'PortChannel4014|10.1.0.6/31'])
166-
159+
167160
def test_frontend_asic_device_neigh(self):
168161
argument = "-m {} -p {} -n asic0 --var-json \"DEVICE_NEIGHBOR\"".format(self.sample_graph, self.port_config[0])
169162
output = json.loads(self.run_script(argument))
170163
self.assertDictEqual(output, \
171164
{'Ethernet0': {'name': '01T2', 'port': 'Ethernet1'},
172-
'Ethernet4': {'name': '01T2', 'port': 'Ethernet2'},
173-
'Ethernet-BP4': {'name': 'ASIC2', 'port': 'Eth1-ASIC2'},
174-
'Ethernet-BP12': {'name': 'ASIC3', 'port': 'Eth1-ASIC3'},
175-
'Ethernet-BP0': {'name': 'ASIC2', 'port': 'Eth0-ASIC2'},
165+
'Ethernet4': {'name': '01T2', 'port': 'Ethernet2'},
166+
'Ethernet-BP4': {'name': 'ASIC2', 'port': 'Eth1-ASIC2'},
167+
'Ethernet-BP12': {'name': 'ASIC3', 'port': 'Eth1-ASIC3'},
168+
'Ethernet-BP0': {'name': 'ASIC2', 'port': 'Eth0-ASIC2'},
176169
'Ethernet-BP8': {'name': 'ASIC3', 'port': 'Eth0-ASIC3'}})
177170

178171
def test_frontend_asic_device_neigh_metadata(self):
@@ -191,7 +184,7 @@ def test_backend_asic_device_neigh(self):
191184
'Ethernet-BP384': {'name': 'ASIC0', 'port': 'Eth6-ASIC0'},
192185
'Ethernet-BP392': {'name': 'ASIC1', 'port': 'Eth6-ASIC1'},
193186
'Ethernet-BP388': {'name': 'ASIC0', 'port': 'Eth7-ASIC0'}})
194-
187+
195188
def test_backend_device_neigh_metadata(self):
196189
argument = "-m {} -p {} -n asic3 --var-json \"DEVICE_NEIGHBOR_METADATA\"".format(self.sample_graph, self.port_config[3])
197190
output = json.loads(self.run_script(argument))
@@ -212,7 +205,7 @@ def test_backend_asic_bgp_neighbor(self):
212205
argument = "-m {} -p {} -n asic3 --var-json \"BGP_NEIGHBOR\"".format(self.sample_graph, self.port_config[3])
213206
output = json.loads(self.run_script(argument))
214207
self.assertDictEqual(output, \
215-
{'10.1.0.7': {'rrclient': 0, 'name': 'ASIC1', 'local_addr': '10.1.0.6', 'nhopself': 0, 'holdtime': '0', 'asn': '65100', 'keepalive': '0'},
208+
{'10.1.0.7': {'rrclient': 0, 'name': 'ASIC1', 'local_addr': '10.1.0.6', 'nhopself': 0, 'holdtime': '0', 'asn': '65100', 'keepalive': '0'},
216209
'10.1.0.3': {'rrclient': 0, 'name': 'ASIC0', 'local_addr': '10.1.0.2', 'nhopself': 0, 'holdtime': '0', 'asn': '65100', 'keepalive': '0'}})
217210

218211
def test_device_asic_metadata(self):
@@ -225,5 +218,4 @@ def test_device_asic_metadata(self):
225218
if asic == 0 or asic == 1:
226219
self.assertEqual(output['localhost']['sub_role'], 'FrontEnd')
227220
else:
228-
self.assertEqual(output['localhost']['sub_role'], 'BackEnd')
229-
221+
self.assertEqual(output['localhost']['sub_role'], 'BackEnd')

0 commit comments

Comments
 (0)