Skip to content

Commit

Permalink
Merge pull request #9 from Azure/master
Browse files Browse the repository at this point in the history
merge with master
  • Loading branch information
simonJi2018 committed Aug 9, 2018
2 parents 482ad6d + 4d784d8 commit 67fdf82
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 26 deletions.
3 changes: 2 additions & 1 deletion dockers/docker-sonic-mgmt/Dockerfile.j2
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ RUN azure-cli_bundle_*/installer

# Known bug: azure keyvault cannot work behind a proxy
# Temporary fix: upgrade the azure-keyvault package within az cli
RUN ~/lib/azure-cli/bin/python -m pip install azure-keyvault -U
# TODO: if azure-cli contains newer version azure-keyvault, remove this
RUN ~/lib/azure-cli/bin/python -m pip install azure-keyvault==0.3.7 -U

RUN git clone https://github.com/Azure/sonic-mgmt
41 changes: 35 additions & 6 deletions src/sonic-config-engine/minigraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def parse_device(device):
d_type = None # don't shadow type()
hwsku = None
name = None
deployment_id = None
if str(QName(ns3, "type")) in device.attrib:
d_type = device.attrib[str(QName(ns3, "type"))]

Expand All @@ -53,7 +54,9 @@ def parse_device(device):
name = node.text
elif node.tag == str(QName(ns, "HwSku")):
hwsku = node.text
return (lo_prefix, mgmt_prefix, name, hwsku, d_type)
elif node.tag == str(QName(ns, "DeploymentId")):
deployment_id = node.text
return (lo_prefix, mgmt_prefix, name, hwsku, d_type, deployment_id)

def parse_png(png, hname):
neighbors = {}
Expand All @@ -63,10 +66,32 @@ def parse_png(png, hname):
mgmt_dev = ''
mgmt_port = ''
port_speeds = {}
console_ports = {}
for child in png:
if child.tag == str(QName(ns, "DeviceInterfaceLinks")):
for link in child.findall(str(QName(ns, "DeviceLinkBase"))):
linktype = link.find(str(QName(ns, "ElementType"))).text
if linktype == "DeviceSerialLink":
enddevice = link.find(str(QName(ns, "EndDevice"))).text
endport = link.find(str(QName(ns, "EndPort"))).text
startdevice = link.find(str(QName(ns, "StartDevice"))).text
startport = link.find(str(QName(ns, "StartPort"))).text
baudrate = link.find(str(QName(ns, "Bandwidth"))).text
flowcontrol = 1 if link.find(str(QName(ns, "FlowControl"))) is not None and link.find(str(QName(ns, "FlowControl"))).text == 'true' else 0
if enddevice.lower() == hname.lower():
console_ports[endport] = {
'remote_device': startdevice,
'baud_rate': baudrate,
'flow_control': flowcontrol
}
else:
console_ports[startport] = {
'remote_device': enddevice,
'baud_rate': baudrate,
'flow_control': flowcontrol
}
continue

if linktype != "DeviceInterfaceLink" and linktype != "UnderlayInterfaceLink":
continue

Expand All @@ -92,8 +117,10 @@ def parse_png(png, hname):

if child.tag == str(QName(ns, "Devices")):
for device in child.findall(str(QName(ns, "Device"))):
(lo_prefix, mgmt_prefix, name, hwsku, d_type) = parse_device(device)
(lo_prefix, mgmt_prefix, name, hwsku, d_type, deployment_id) = parse_device(device)
device_data = {'lo_addr': lo_prefix, 'type': d_type, 'mgmt_addr': mgmt_prefix, 'hwsku': hwsku }
if deployment_id:
device_data['deployment_id'] = deployment_id
devices[name] = device_data

if child.tag == str(QName(ns, "DeviceInterfaceLinks")):
Expand All @@ -113,7 +140,7 @@ def parse_png(png, hname):
elif node.tag == str(QName(ns, "EndDevice")):
mgmt_dev = node.text

return (neighbors, devices, console_dev, console_port, mgmt_dev, mgmt_port, port_speeds)
return (neighbors, devices, console_dev, console_port, mgmt_dev, mgmt_port, port_speeds, console_ports)


def parse_dpg(dpg, hname):
Expand Down Expand Up @@ -394,6 +421,7 @@ def parse_xml(filename, platform=None, port_config_file=None):
port_speeds_default = {}
port_speed_png = {}
port_descriptions = {}
console_ports = {}
syslog_servers = []
dhcp_servers = []
ntp_servers = []
Expand All @@ -419,9 +447,9 @@ def parse_xml(filename, platform=None, port_config_file=None):
elif child.tag == str(QName(ns, "CpgDec")):
(bgp_sessions, bgp_asn, bgp_peers_with_range) = parse_cpg(child, hostname)
elif child.tag == str(QName(ns, "PngDec")):
(neighbors, devices, console_dev, console_port, mgmt_dev, mgmt_port, port_speed_png) = parse_png(child, hostname)
(neighbors, devices, console_dev, console_port, mgmt_dev, mgmt_port, port_speed_png, console_ports) = parse_png(child, hostname)
elif child.tag == str(QName(ns, "UngDec")):
(u_neighbors, u_devices, _, _, _, _, _) = parse_png(child, hostname)
(u_neighbors, u_devices, _, _, _, _, _, _) = parse_png(child, hostname)
elif child.tag == str(QName(ns, "MetadataDeclaration")):
(syslog_servers, dhcp_servers, ntp_servers, tacacs_servers, mgmt_routes, erspan_dst, deployment_id) = parse_meta(child, hostname)
elif child.tag == str(QName(ns, "DeviceInfos")):
Expand Down Expand Up @@ -489,6 +517,7 @@ def parse_xml(filename, platform=None, port_config_file=None):
ports.setdefault(port_name, {})['description'] = port_descriptions[port_name]

results['PORT'] = ports
results['CONSOLE_PORT'] = console_ports

if port_config_file:
port_set = set(ports.keys())
Expand Down Expand Up @@ -546,7 +575,7 @@ def parse_xml(filename, platform=None, port_config_file=None):

def parse_device_desc_xml(filename):
root = ET.parse(filename).getroot()
(lo_prefix, mgmt_prefix, hostname, hwsku, d_type) = parse_device(root)
(lo_prefix, mgmt_prefix, hostname, hwsku, d_type, _) = parse_device(root)

results = {}
results['DEVICE_METADATA'] = {'localhost': {
Expand Down
23 changes: 22 additions & 1 deletion src/sonic-config-engine/sonic_platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,32 @@ def get_system_mac():
return None

mac = mac.strip()

# Align last byte of MAC if necessary
if version_info and (version_info['asic_type'] == 'mellanox' or version_info['asic_type'] == 'centec'):
last_byte = mac[-2:]
aligned_last_byte = format(int(int(last_byte, 16) & 0b11000000), '02x')
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"

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
45 changes: 30 additions & 15 deletions src/sonic-config-engine/tests/simple-sample-graph-case.xml
Original file line number Diff line number Diff line change
Expand Up @@ -181,27 +181,42 @@
</DeviceDataPlaneInfo>
</DpgDec>
<PngDec>
<DeviceInterfaceLinks/>
<DeviceInterfaceLinks>
<DeviceLinkBase i:type="DeviceSerialLink">
<ElementType>DeviceSerialLink</ElementType>
<Bandwidth>9600</Bandwidth>
<EndDevice>switch-t0</EndDevice>
<EndPort>1</EndPort>
<FlowControl>true</FlowControl>
<StartDevice>managed_device</StartDevice>
<StartPort>console</StartPort>
</DeviceLinkBase>
<DeviceLinkBase i:type="DeviceInterfaceLink">
<ElementType>DeviceInterfaceLink</ElementType>
<AutoNegotiation>true</AutoNegotiation>
<Bandwidth>10000</Bandwidth>
<EndDevice>switch-t0</EndDevice>
<EndPort>fortyGigE0/0</EndPort>
<StartDevice>switch-01t1</StartDevice>
<StartPort>port1</StartPort>
</DeviceLinkBase>
</DeviceInterfaceLinks>
<Devices>
<Device i:type="ToRRouter">
<Hostname>switch-t0</Hostname>
<HwSku>Force10-S6000</HwSku>
</Device>
<Device i:type="LeafRouter">
<Hostname>ARISTA01T1</Hostname>
<HwSku>Arista</HwSku>
</Device>
<Device i:type="LeafRouter">
<Hostname>ARISTA02T1</Hostname>
<HwSku>Arista</HwSku>
</Device>
<Device i:type="LeafRouter">
<Hostname>ARISTA03T1</Hostname>
<HwSku>Arista</HwSku>
</Device>
<Device i:type="LeafRouter">
<Hostname>ARISTA04T1</Hostname>
<HwSku>Arista</HwSku>
<Hostname>switch-01t1</Hostname>
<Address xmlns:a="Microsoft.Search.Autopilot.NetMux">
<a:IPPrefix>10.1.0.186/32</a:IPPrefix>
</Address>
<DeploymentId>2</DeploymentId>
<DeviceLocation i:nil="true"/>
<ManagementAddress xmlns:a="Microsoft.Search.Autopilot.NetMux">
<a:IPPrefix>10.7.0.196/26</a:IPPrefix>
</ManagementAddress>
<HwSku>Force10-S6000</HwSku>
</Device>
</Devices>
</PngDec>
Expand Down
10 changes: 10 additions & 0 deletions src/sonic-config-engine/tests/test_minigraph_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,21 @@ def test_minigraph_portchannels(self):
output = self.run_script(argument)
self.assertEqual(output.strip(), "{'PortChannel01': {'members': ['Ethernet4']}}")

def test_minigraph_console_port(self):
argument = '-m "' + self.sample_graph + '" -p "' + self.port_config + '" -v CONSOLE_PORT'
output = self.run_script(argument)
self.assertEqual(output.strip(), "{'1': {'baud_rate': '9600', 'remote_device': 'managed_device', 'flow_control': 1}}")

def test_minigraph_deployment_id(self):
argument = '-m "' + self.sample_graph + '" -p "' + self.port_config + '" -v "DEVICE_METADATA[\'localhost\'][\'deployment_id\']"'
output = self.run_script(argument)
self.assertEqual(output.strip(), "1")

def test_minigraph_neighbor_metadata(self):
argument = '-m "' + self.sample_graph + '" -p "' + self.port_config + '" -v "DEVICE_NEIGHBOR_METADATA"'
output = self.run_script(argument)
self.assertEqual(output.strip(), "{'switch-01t1': {'lo_addr': '10.1.0.186/32', 'mgmt_addr': '10.7.0.196/26', 'hwsku': 'Force10-S6000', 'type': 'LeafRouter', 'deployment_id': '2'}}")

def test_metadata_everflow(self):
argument = '-m "' + self.sample_graph + '" -p "' + self.port_config + '" -v "MIRROR_SESSION"'
output = self.run_script(argument)
Expand Down
2 changes: 1 addition & 1 deletion src/sonic-dbsyncd
2 changes: 1 addition & 1 deletion src/sonic-platform-common
2 changes: 1 addition & 1 deletion src/sonic-snmpagent

0 comments on commit 67fdf82

Please sign in to comment.