Skip to content

Commit

Permalink
Fix generate_l2_config: don't override hostname or device role (ToRRo…
Browse files Browse the repository at this point in the history
…uter) (sonic-net#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.
  • Loading branch information
qiluo-msft authored and santhosh-kt committed Feb 25, 2021
1 parent c0b0b9c commit cf9aad6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
6 changes: 0 additions & 6 deletions src/sonic-config-engine/config_samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
9 changes: 6 additions & 3 deletions src/sonic-config-engine/tests/test_j2files.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,15 @@ def test_ipinip(self):
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')
Expand Down

0 comments on commit cf9aad6

Please sign in to comment.