diff --git a/src/sonic-config-engine/minigraph.py b/src/sonic-config-engine/minigraph.py
index c564d6051980..ed90a8849362 100644
--- a/src/sonic-config-engine/minigraph.py
+++ b/src/sonic-config-engine/minigraph.py
@@ -65,6 +65,18 @@ def default(self, obj):
return str(obj)
return json.JSONEncoder.default(self, obj)
+def get_peer_switch_info(link_metadata, devices):
+ peer_switch_table = {}
+ for data in link_metadata.values():
+ if "PeerSwitch" in data:
+ peer_hostname = data["PeerSwitch"]
+ peer_lo_addr = devices[peer_hostname]["lo_addr"]
+ peer_switch_table[peer_hostname] = {
+ 'address_ipv4': peer_lo_addr
+ }
+
+ return peer_switch_table
+
def parse_device(device):
lo_prefix = None
mgmt_prefix = None
@@ -674,16 +686,31 @@ def parse_linkmeta(meta, hname):
# Cannot find a matching hname, something went wrong
continue
+ has_peer_switch = False
+ upper_tor_hostname = ''
+ lower_tor_hostname = ''
+
properties = linkmeta.find(str(QName(ns1, "Properties")))
for device_property in properties.findall(str(QName(ns1, "DeviceProperty"))):
name = device_property.find(str(QName(ns1, "Name"))).text
value = device_property.find(str(QName(ns1, "Value"))).text
if name == "FECDisabled":
fec_disabled = value
+ elif name == "GeminiPeeringLink":
+ has_peer_switch = True
+ elif name == "UpperTOR":
+ upper_tor_hostname = value
+ elif name == "LowerTOR":
+ lower_tor_hostname = value
linkmetas[port] = {}
if fec_disabled:
linkmetas[port]["FECDisabled"] = fec_disabled
+ if has_peer_switch:
+ if upper_tor_hostname == hname:
+ linkmetas[port]["PeerSwitch"] = lower_tor_hostname
+ else:
+ linkmetas[port]["PeerSwitch"] = upper_tor_hostname
return linkmetas
@@ -1001,8 +1028,14 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw
}
}
+ results['PEER_SWITCH'] = get_peer_switch_info(linkmetas, devices)
+
+ if bool(results['PEER_SWITCH']):
+ results['DEVICE_METADATA']['localhost']['subtype'] = 'DualToR'
+
if is_storage_device:
results['DEVICE_METADATA']['localhost']['storage_device'] = "true"
+
# for this hostname, if sub_role is defined, add sub_role in
# device_metadata
if sub_role is not None:
diff --git a/src/sonic-config-engine/tests/simple-sample-graph-case.xml b/src/sonic-config-engine/tests/simple-sample-graph-case.xml
index c499dc15760d..c70a1561b69a 100644
--- a/src/sonic-config-engine/tests/simple-sample-graph-case.xml
+++ b/src/sonic-config-engine/tests/simple-sample-graph-case.xml
@@ -286,7 +286,7 @@
- DevicePeeringLink
+ GeminiPeeringLink
True
diff --git a/src/sonic-config-engine/tests/test_minigraph_case.py b/src/sonic-config-engine/tests/test_minigraph_case.py
index 4ab1915864c3..019c791a1899 100644
--- a/src/sonic-config-engine/tests/test_minigraph_case.py
+++ b/src/sonic-config-engine/tests/test_minigraph_case.py
@@ -52,6 +52,11 @@ def test_jinja_expression(self):
output = self.run_script(argument)
self.assertEqual(output.strip(), 'ToRRouter')
+ def test_minigraph_subtype(self):
+ argument = '-m "' + self.sample_graph + '" -v "DEVICE_METADATA[\'localhost\'][\'subtype\']"'
+ output = self.run_script(argument)
+ self.assertEqual(output.strip(), 'DualToR')
+
def test_additional_json_data(self):
argument = '-a \'{"key1":"value1"}\' -v key1'
output = self.run_script(argument)
@@ -174,6 +179,20 @@ def test_minigraph_bgp_mon(self):
output = self.run_script(argument)
self.assertEqual(output.strip(), "{}")
+ def test_minigraph_peer_switch(self):
+ argument = '-m "' + self.sample_graph + '" -p "' + self.port_config + '" -v "PEER_SWITCH"'
+ expected_table = {
+ 'switch2-t0': {
+ 'address_ipv4': "25.1.1.10"
+ }
+ }
+
+ output = self.run_script(argument)
+ self.assertEqual(
+ utils.to_dict(output.strip()),
+ expected_table
+ )
+
def test_mux_cable_parsing(self):
result = minigraph.parse_xml(self.sample_graph, port_config_file=self.port_config)