diff --git a/src/sonic-config-engine/minigraph.py b/src/sonic-config-engine/minigraph.py index 660606b451..632cf060b6 100644 --- a/src/sonic-config-engine/minigraph.py +++ b/src/sonic-config-engine/minigraph.py @@ -1178,6 +1178,10 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw if bool(results['PEER_SWITCH']): results['DEVICE_METADATA']['localhost']['subtype'] = 'DualToR' + if len(results['PEER_SWITCH'].keys()) > 1: + print("Warning: more than one peer switch was found. Only the first will be parsed: {}".format(results['PEER_SWITCH'].keys()[0])) + + results['DEVICE_METADATA']['localhost']['peer_switch'] = list(results['PEER_SWITCH'].keys())[0] if is_storage_device: results['DEVICE_METADATA']['localhost']['storage_device'] = "true" diff --git a/src/sonic-config-engine/tests/test_minigraph_case.py b/src/sonic-config-engine/tests/test_minigraph_case.py index efa8a063b6..cf8a7557ae 100644 --- a/src/sonic-config-engine/tests/test_minigraph_case.py +++ b/src/sonic-config-engine/tests/test_minigraph_case.py @@ -57,6 +57,11 @@ class TestCfgGenCaseInsensitive(TestCase): output = self.run_script(argument) self.assertEqual(output.strip(), 'DualToR') + def test_minigraph_peer_switch_hostname(self): + argument = '-m "' + self.sample_graph + '" -v "DEVICE_METADATA[\'localhost\'][\'peer_switch\']"' + output = self.run_script(argument) + self.assertEqual(output.strip(), 'switch2-t0') + def test_additional_json_data(self): argument = '-a \'{"key1":"value1"}\' -v key1' output = self.run_script(argument)