From d6d6704ecf28b281a91633a937a328fd6dc33378 Mon Sep 17 00:00:00 2001 From: Rodny Molina Date: Tue, 15 May 2018 17:08:01 -0700 Subject: [PATCH 1/2] Moving get_routing_stack() to a centralized location to avoid code duplication Various areas of sonic-utilities are now demanding this functionality so i'm simply moving this routing to a centralized location. After spending some time debating about the ideal location for this function, we thought about sonic-config-engine/sonic_platform.py as the closest match. Functional tests' output will be provided as part of the equivalent PR to be submitted shortly within sonic-utilities repo. --- src/sonic-config-engine/sonic_platform.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/sonic-config-engine/sonic_platform.py b/src/sonic-config-engine/sonic_platform.py index f573d6a6575d..25faac326b0a 100644 --- a/src/sonic-config-engine/sonic_platform.py +++ b/src/sonic-config-engine/sonic_platform.py @@ -44,7 +44,7 @@ def get_system_mac(): proc = subprocess.Popen("ip link show eth0 | grep ether | awk '{print $2}'", shell=True, stdout=subprocess.PIPE) (mac, err) = proc.communicate() mac = mac.strip() - + # Align last byte of MAC if necessary version_info = get_sonic_version_info() if version_info and (version_info['asic_type'] == 'mellanox' or version_info['asic_type'] == 'centec'): @@ -53,3 +53,19 @@ def get_system_mac(): mac = mac[:-2] + aligned_last_byte return mac +def get_system_routing_stack(): + command = "sudo docker ps | grep bgp | awk '{print$2}' | cut -d'-' -f3 | cut -d':' -f1" + + try: + proc = subprocess.Popen(command, + stdout=subprocess.PIPE, + shell=True, + stderr=subprocess.STDOUT) + stdout = proc.communicate()[0] + proc.wait() + result = stdout.rstrip('\n') + + except OSError, e: + raise OSError("Cannot detect routing-stack") + + return result From 357c7ff93cf792175e4a8aee7d370aed48342616 Mon Sep 17 00:00:00 2001 From: Rodny Molina Date: Wed, 16 May 2018 18:56:33 -0700 Subject: [PATCH 2/2] Adding comment to function. --- src/sonic-config-engine/sonic_platform.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/sonic-config-engine/sonic_platform.py b/src/sonic-config-engine/sonic_platform.py index 25faac326b0a..1af367823f80 100644 --- a/src/sonic-config-engine/sonic_platform.py +++ b/src/sonic-config-engine/sonic_platform.py @@ -53,6 +53,11 @@ def get_system_mac(): mac = mac[:-2] + aligned_last_byte return mac +# +# Function to obtain the routing-stack being utilized. Function is not +# platform-specific; it's being placed in this file temporarily till a more +# suitable location is identified as part of upcoming refactoring efforts. +# def get_system_routing_stack(): command = "sudo docker ps | grep bgp | awk '{print$2}' | cut -d'-' -f3 | cut -d':' -f1"