Fix generate_l2_config: don't override hostname or device role (ToRRouter) (#5511)

* 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.
This commit is contained in:
Qi Luo 2020-10-01 09:16:55 -07:00 committed by GitHub
parent 1da60a6811
commit e9be0864cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 9 deletions

View File

@ -42,13 +42,7 @@ def generate_empty_config(data):
return new_data
def generate_l2_config(data):
if not data['DEVICE_METADATA']['localhost'].has_key('hostname'):
data['DEVICE_METADATA']['localhost']['hostname'] = 'sonic'
if not data['DEVICE_METADATA']['localhost'].has_key('type'):
data['DEVICE_METADATA']['localhost']['type'] = 'ToRRouter'
data['VLAN'] = {'Vlan1000': {'vlanid': '1000'}}
vp = natsorted(data['PORT'].keys())
data['VLAN']['Vlan1000'].setdefault('members', vp)
data['VLAN_MEMBER'] = {}
for port in natsorted(data['PORT'].keys()):
data['PORT'][port].setdefault('admin_status', 'up')

View File

@ -89,12 +89,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', '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')