Skip to content

Commit 0114c78

Browse files
pavel-shirshovabdosi
authored andcommitted
Merged PR 1575118: Output difference for bgp configurations
When the generated output doesn't match with expected output the test will output the difference between them which helps to see the issue better
1 parent 5f695cd commit 0114c78

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

src/sonic-config-engine/tests/test_bgp_template.py

+13-14
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,26 @@ def run_script(self, argument):
2525
print 'CMD: sonic-cfggen ' + argument
2626
return subprocess.check_output(self.script_file + ' ' + argument, shell=True)
2727

28-
def run_diff(self, file1, file2, diff):
29-
return subprocess.check_output('diff {} {} >{}'.format(file1, file2, diff), shell=True)
28+
def run_diff(self, file1, file2):
29+
return subprocess.check_output('diff -u {} {} || true'.format(file1, file2), shell=True)
3030

31-
def test_bgpd_t1(self):
31+
def run_bgpd_test(self, minigraph, portconfig, valid_result_file):
3232
conf_template = os.path.join(self.test_dir, '..', '..', '..', 'dockers', 'docker-fpm-quagga', 'bgpd.conf.j2')
33-
argument = '-m ' + self.t1_minigraph + ' -p ' + self.dell_s6000_port_config + ' -t ' + conf_template + ' -y ' + self.deployment_id_asn_map + ' -j ' + self.device_metadata + ' > ' + self.output_file
33+
argument = '-m ' + minigraph + ' -p ' + portconfig + ' -t ' + conf_template + ' -y ' + self.deployment_id_asn_map + ' -j ' + self.device_metadata + ' > ' + self.output_file
3434
self.run_script(argument)
35-
self.assertTrue(filecmp.cmp(os.path.join(self.test_dir, 'sample_output', 'CO4SCH04001AALF.bgpd.conf'), self.output_file))
35+
original_filename = os.path.join(self.test_dir, 'sample_output', valid_result_file)
36+
r = filecmp.cmp(original_filename, self.output_file)
37+
diff_output = self.run_diff(original_filename, self.output_file) if not r else ""
38+
self.assertTrue(r, "Diff:\n" + diff_output)
39+
40+
def test_bgpd_t1(self):
41+
return self.run_bgpd_test(self.t1_minigraph, self.dell_s6000_port_config, 'CO4SCH04001AALF.bgpd.conf')
3642

3743
def test_bgpd_tycoon_t1(self):
38-
conf_template = os.path.join(self.test_dir, '..', '..', '..', 'dockers', 'docker-fpm-quagga', 'bgpd.conf.j2')
39-
argument = '-m ' + self.tycoon_t1_minigraph + ' -p ' + self.a7060_port_config + ' -t ' + conf_template + ' -y ' + self.deployment_id_asn_map + ' -j ' + self.device_metadata + ' > ' + self.output_file
40-
self.run_script(argument)
41-
self.assertTrue(filecmp.cmp(os.path.join(self.test_dir, 'sample_output', 'SN1-0102-0201-11T1.bgpd.conf'), self.output_file))
44+
return self.run_bgpd_test(self.tycoon_t1_minigraph, self.a7060_port_config, 'SN1-0102-0201-11T1.bgpd.conf')
4245

4346
def test_bgpd_m0(self):
44-
conf_template = os.path.join(self.test_dir, '..', '..', '..', 'dockers', 'docker-fpm-quagga', 'bgpd.conf.j2')
45-
argument = '-m ' + self.m0_minigraph + ' -p ' + self.hlx_port_config + ' -t ' + conf_template + ' -y ' + self.deployment_id_asn_map + ' -j ' + self.device_metadata + ' > ' + self.output_file
46-
self.run_script(argument)
47-
self.assertTrue(filecmp.cmp(os.path.join(self.test_dir, 'sample_output', 'MWH01-0100-0202-01M0.bgpd.conf'), self.output_file))
48-
47+
return self.run_bgpd_test(self.m0_minigraph, self.hlx_port_config, 'MWH01-0100-0202-01M0.bgpd.conf')
4948

5049
def tearDown(self):
5150
try:

0 commit comments

Comments
 (0)