From 30f5557d36d13e0b7ff655b41f7371f089b755d9 Mon Sep 17 00:00:00 2001 From: Qi Luo Date: Thu, 1 Oct 2020 23:24:35 -0700 Subject: [PATCH] Fix generate_l2_config: don't override hostname or device role (ToRRouter) (#5510) * Fix generate_l2_config: don't override hostname because sonic-cfggen may not read from Redis. Fix test_l2switch_template test case to test preset l2 feature. * Improve test script: compare json files with sort_keys * Revert changes on sample_output * Remove members field in VLAN section. Fix test assertTrue statement. --- src/sonic-config-engine/config_samples.py | 6 ------ src/sonic-config-engine/tests/test_j2files.py | 9 ++++++--- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/sonic-config-engine/config_samples.py b/src/sonic-config-engine/config_samples.py index 3c3ace8846..9934164296 100644 --- a/src/sonic-config-engine/config_samples.py +++ b/src/sonic-config-engine/config_samples.py @@ -41,13 +41,7 @@ def generate_empty_config(data): return new_data def generate_l2_config(data): - if 'hostname' not in data['DEVICE_METADATA']['localhost']: - data['DEVICE_METADATA']['localhost']['hostname'] = 'sonic' - if 'type' not in data['DEVICE_METADATA']['localhost']: - data['DEVICE_METADATA']['localhost']['type'] = 'ToRRouter' data['VLAN'] = {'Vlan1000': {'vlanid': '1000'}} - vp = natsorted(list(data['PORT'].keys())) - data['VLAN']['Vlan1000'].setdefault('members', vp) data['VLAN_MEMBER'] = {} for port in natsorted(data['PORT']): data['PORT'][port].setdefault('admin_status', 'up') diff --git a/src/sonic-config-engine/tests/test_j2files.py b/src/sonic-config-engine/tests/test_j2files.py index 30e1f1ca26..98bb243762 100644 --- a/src/sonic-config-engine/tests/test_j2files.py +++ b/src/sonic-config-engine/tests/test_j2files.py @@ -96,12 +96,15 @@ class TestJ2Files(TestCase): assert filecmp.cmp(sample_output_file, self.output_file) def test_l2switch_template(self): - argument = '-k Mellanox-SN2700 -t ' + os.path.join(self.test_dir, '../data/l2switch.j2') + ' -p ' + self.t0_port_config + ' > ' + self.output_file - self.run_script(argument) + argument = '-k Mellanox-SN2700 --preset l2 -p ' + self.t0_port_config + output = self.run_script(argument) + output_json = json.loads(output) sample_output_file = os.path.join(self.test_dir, 'sample_output', utils.PYvX_DIR, 'l2switch.json') + with open(sample_output_file) as sample_output_fd: + sample_output_json = json.load(sample_output_fd) - self.assertTrue(filecmp.cmp(sample_output_file, self.output_file)) + self.assertTrue(json.dumps(sample_output_json, sort_keys=True) == json.dumps(output_json, sort_keys=True)) def test_qos_arista7050_render_template(self): arista_dir_path = os.path.join(self.test_dir, '..', '..', '..', 'device', 'arista', 'x86_64-arista_7050_qx32s', 'Arista-7050-QX-32S')