Skip to content

Commit

Permalink
Merge branch 'multiasic_minigraph' of github.com:SuvarnaMeenakshi/son…
Browse files Browse the repository at this point in the history
…ic-buildimage into comment_fix
  • Loading branch information
SuvarnaMeenakshi committed May 2, 2020
2 parents 520c43b + 15228c1 commit 110d1b8
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 53 deletions.
2 changes: 1 addition & 1 deletion src/sonic-config-engine/sonic-cfggen
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def main():

if args.platform_info:
if asic_name is not None and asic_role.lower() == "backend":
mac = get_system_mac(asic_name)
mac = get_system_mac(namespace=asic_name)
else:
mac = get_system_mac()

Expand Down
36 changes: 15 additions & 21 deletions src/sonic-config-engine/sonic_device_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import subprocess
import re
from natsort import natsorted
import glob
DOCUMENTATION = '''
---
module: sonic_device_util
Expand All @@ -19,7 +20,7 @@
'''
SONIC_DEVICE_PATH = '/usr/share/sonic/device'
NPU_NAME_PREFIX = 'asic'

NAMESPACE_PATH_GLOB = '/run/netns/*'
def get_machine_info():
if not os.path.isfile('/host/machine.conf'):
return None
Expand All @@ -39,35 +40,28 @@ def get_npu_id_from_name(npu_name):
return None

def get_num_npus():
platform = get_platform_info(get_machine_info())
asic_conf_file_path = os.path.join(SONIC_DEVICE_PATH, platform, 'asic.conf')
if not os.path.isfile(asic_conf_file_path):
platform = get_platform_info(get_machine_info())
asic_conf_file_path = os.path.join(SONIC_DEVICE_PATH, platform, 'asic.conf')
if not os.path.isfile(asic_conf_file_path):
return 1
with open(asic_conf_file_path) as asic_conf_file:
for line in asic_conf_file:
tokens = line.split('=')
with open(asic_conf_file_path) as asic_conf_file:
for line in asic_conf_file:
tokens = line.split('=')
if len(tokens) < 2:
continue
if tokens[0].lower() == 'num_asic':
num_npus = tokens[1].strip()
return num_npus
continue
if tokens[0].lower() == 'num_asic':
num_npus = tokens[1].strip()
return num_npus

def get_namespaces():
"""
In a multi NPU platform, each NPU is in a Linux Namespace.
This method returns list of all the Namespace present on the device
"""
ns_list = []
try:
proc = subprocess.Popen('ip netns list | cut -d"(" -f1',
stdout=subprocess.PIPE,
shell=True,
stderr=subprocess.STDOUT)
stdout = proc.communicate()[0]
proc.wait()
ns_list = [n for n in stdout.split()]
except OSError,e:
raise OSError("Unable to get namespace list")
for path in glob.glob(NAMESPACE_PATH_GLOB):
ns = os.path.basename(path)
ns_list.append(ns)
return natsorted(ns_list)

def get_platform_info(machine_info):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ Ethernet12 37,38,39,40 Ethernet1/4 Eth3-ASIC0
Ethernet-BP0 13,14,15,16 Ethernet-BP0 Eth4-ASIC0
Ethernet-BP4 17,18,19,20 Ethernet-BP4 Eth5-ASIC0
Ethernet-BP8 21,22,23,24 Ethernet-BP8 Eth6-ASIC0
Ethernet-BP12 25,26,27,28 Ethernet-BP12 Eth7-ASIC0
Ethernet-BP12 25,26,27,28 Ethernet-BP12 Eth7-ASIC0
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@ Ethernet-BP268 49,50,51,52 Ethernet-BP268 Eth3-ASIC2
Ethernet-BP272 45,46,47,48 Ethernet-BP272 Eth4-ASIC2
Ethernet-BP276 41,42,43,44 Ethernet-BP276 Eth5-ASIC2
Ethernet-BP280 37,38,39,40 Ethernet-BP280 Eth6-ASIC2
Ethernet-BP284 33,34,35,36 Ethernet-BP284 Eth7-ASIC2


Ethernet-BP284 33,34,35,36 Ethernet-BP284 Eth7-ASIC2
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ Ethernet-BP396 17,18,19,20 Ethernet-BP396 Eth3-ASIC3
Ethernet-BP400 13,14,15,16 Ethernet-BP400 Eth4-ASIC3
Ethernet-BP404 9,10,11,12 Ethernet-BP404 Eth5-ASIC3
Ethernet-BP408 5,6,7,8 Ethernet-BP408 Eth6-ASIC3
Ethernet-BP412 1,2,3,4 Ethernet-BP412 Eth7-ASIC3
Ethernet-BP412 1,2,3,4 Ethernet-BP412 Eth7-ASIC3
44 changes: 18 additions & 26 deletions src/sonic-config-engine/tests/test_multinpu_cfggen.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ def setUp(self):
for asic in range(NUM_ASIC):
self.port_config.append(os.path.join(self.test_data_dir, "sample_port_config-{}.ini".format(asic)))


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


def run_script_for_asic(self,argument,asic, port_config=None):
argument = "{} -n asic{} ".format(argument, asic)
if port_config:
Expand All @@ -52,16 +50,14 @@ def test_dummy_run(self):
argument = ''
output = self.run_script(argument)
self.assertEqual(output, '')

def test_hwsku(self):
argument = "-v \"DEVICE_METADATA[\'localhost\'][\'hwsku\']\" -m \"{}\"".format(self.sample_graph)
output = self.run_script(argument)
self.assertEqual(output.strip(), SKU)

for asic in range(NUM_ASIC):
output = self.run_script_for_asic(argument, asic)
self.assertEqual(output.strip(), SKU)


def test_print_data(self):
argument = "-m \"{}\" --print-data".format(self.sample_graph)
Expand All @@ -70,8 +66,7 @@ def test_print_data(self):
for asic in range(NUM_ASIC):
output = self.run_script_for_asic(argument, asic)
self.assertGreater(len(output.strip()) , 0)



def test_additional_json_data(self):
argument = '-a \'{"key1":"value1"}\' -v key1'
output = self.run_script(argument)
Expand All @@ -80,7 +75,6 @@ def test_additional_json_data(self):
output = self.run_script_for_asic(argument, asic)
self.assertEqual(output.strip(), 'value1')


def test_read_yaml(self):
argument = '-v yml_item -y ' + os.path.join(self.test_dir, 'test.yml')
output = yaml.load(self.run_script(argument))
Expand Down Expand Up @@ -123,20 +117,20 @@ def test_mgmt_port(self):
for asic in range(NUM_ASIC):
output = json.loads(self.run_script_for_asic(argument, asic, self.port_config[asic]))
self.assertDictEqual(output, {})

def test_frontend_asic_portchannels(self):
argument = "-m {} -p {} -n asic0 --var-json \"PORTCHANNEL\"".format(self.sample_graph, self.port_config[0])
output = json.loads(self.run_script(argument))
self.assertDictEqual(output, \
{'PortChannel0002': {'admin_status': 'up', 'min_links': '2', 'members': ['Ethernet0', 'Ethernet4'], 'mtu': '9100'},
'PortChannel4001': {'admin_status': 'up', 'min_links': '2', 'members': ['Ethernet-BP0', 'Ethernet-BP4'], 'mtu': '9100'},
{'PortChannel0002': {'admin_status': 'up', 'min_links': '2', 'members': ['Ethernet0', 'Ethernet4'], 'mtu': '9100'},
'PortChannel4001': {'admin_status': 'up', 'min_links': '2', 'members': ['Ethernet-BP0', 'Ethernet-BP4'], 'mtu': '9100'},
'PortChannel4002': {'admin_status': 'up', 'min_links': '2', 'members': ['Ethernet-BP8', 'Ethernet-BP12'], 'mtu': '9100'}})

def test_backend_asic_portchannels(self):
argument = "-m {} -p {} -n asic3 --var-json \"PORTCHANNEL\"".format(self.sample_graph, self.port_config[3])
output = json.loads(self.run_script(argument))
self.assertDictEqual(output, \
{'PortChannel4013': {'admin_status': 'up', 'min_links': '2', 'members': ['Ethernet-BP384', 'Ethernet-BP388'], 'mtu': '9100'},
{'PortChannel4013': {'admin_status': 'up', 'min_links': '2', 'members': ['Ethernet-BP384', 'Ethernet-BP388'], 'mtu': '9100'},
'PortChannel4014': {'admin_status': 'up', 'min_links': '2', 'members': ['Ethernet-BP392', 'Ethernet-BP396'], 'mtu': '9100'}})

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


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

def test_frontend_asic_portchannel_intf(self):
argument = "-m {} -p {} -n asic0 --var-json \"PORTCHANNEL_INTERFACE\"".format(self.sample_graph, self.port_config[0])
argument = "-m {} -p {} -n asic0 --var-json \"PORTCHANNEL_INTERFACE\"".format(self.sample_graph, self.port_config[0])
output = json.loads(self.run_script(argument))
self.assertListEqual(output.keys(), \
['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'])

def test_backend_asic_portchannel_intf(self):
argument = "-m {} -p {} -n asic3 --var-json \"PORTCHANNEL_INTERFACE\"".format(self.sample_graph, self.port_config[3])
argument = "-m {} -p {} -n asic3 --var-json \"PORTCHANNEL_INTERFACE\"".format(self.sample_graph, self.port_config[3])
output = json.loads(self.run_script(argument))
self.assertListEqual(output.keys(), \
['PortChannel4013', 'PortChannel4013|10.1.0.2/31', 'PortChannel4014', 'PortChannel4014|10.1.0.6/31'])

def test_frontend_asic_device_neigh(self):
argument = "-m {} -p {} -n asic0 --var-json \"DEVICE_NEIGHBOR\"".format(self.sample_graph, self.port_config[0])
output = json.loads(self.run_script(argument))
self.assertDictEqual(output, \
{'Ethernet0': {'name': '01T2', 'port': 'Ethernet1'},
'Ethernet4': {'name': '01T2', 'port': 'Ethernet2'},
'Ethernet-BP4': {'name': 'ASIC2', 'port': 'Eth1-ASIC2'},
'Ethernet-BP12': {'name': 'ASIC3', 'port': 'Eth1-ASIC3'},
'Ethernet-BP0': {'name': 'ASIC2', 'port': 'Eth0-ASIC2'},
'Ethernet4': {'name': '01T2', 'port': 'Ethernet2'},
'Ethernet-BP4': {'name': 'ASIC2', 'port': 'Eth1-ASIC2'},
'Ethernet-BP12': {'name': 'ASIC3', 'port': 'Eth1-ASIC3'},
'Ethernet-BP0': {'name': 'ASIC2', 'port': 'Eth0-ASIC2'},
'Ethernet-BP8': {'name': 'ASIC3', 'port': 'Eth0-ASIC3'}})

def test_frontend_asic_device_neigh_metadata(self):
Expand All @@ -191,7 +184,7 @@ def test_backend_asic_device_neigh(self):
'Ethernet-BP384': {'name': 'ASIC0', 'port': 'Eth6-ASIC0'},
'Ethernet-BP392': {'name': 'ASIC1', 'port': 'Eth6-ASIC1'},
'Ethernet-BP388': {'name': 'ASIC0', 'port': 'Eth7-ASIC0'}})

def test_backend_device_neigh_metadata(self):
argument = "-m {} -p {} -n asic3 --var-json \"DEVICE_NEIGHBOR_METADATA\"".format(self.sample_graph, self.port_config[3])
output = json.loads(self.run_script(argument))
Expand All @@ -212,7 +205,7 @@ def test_backend_asic_bgp_neighbor(self):
argument = "-m {} -p {} -n asic3 --var-json \"BGP_NEIGHBOR\"".format(self.sample_graph, self.port_config[3])
output = json.loads(self.run_script(argument))
self.assertDictEqual(output, \
{'10.1.0.7': {'rrclient': 0, 'name': 'ASIC1', 'local_addr': '10.1.0.6', 'nhopself': 0, 'holdtime': '0', 'asn': '65100', 'keepalive': '0'},
{'10.1.0.7': {'rrclient': 0, 'name': 'ASIC1', 'local_addr': '10.1.0.6', 'nhopself': 0, 'holdtime': '0', 'asn': '65100', 'keepalive': '0'},
'10.1.0.3': {'rrclient': 0, 'name': 'ASIC0', 'local_addr': '10.1.0.2', 'nhopself': 0, 'holdtime': '0', 'asn': '65100', 'keepalive': '0'}})

def test_device_asic_metadata(self):
Expand All @@ -225,5 +218,4 @@ def test_device_asic_metadata(self):
if asic == 0 or asic == 1:
self.assertEqual(output['localhost']['sub_role'], 'FrontEnd')
else:
self.assertEqual(output['localhost']['sub_role'], 'BackEnd')

self.assertEqual(output['localhost']['sub_role'], 'BackEnd')

0 comments on commit 110d1b8

Please sign in to comment.