diff --git a/src/sonic-config-engine/.gitignore b/src/sonic-config-engine/.gitignore index e41d5b085e5..740428d3d1d 100644 --- a/src/sonic-config-engine/.gitignore +++ b/src/sonic-config-engine/.gitignore @@ -1,2 +1,3 @@ dist/ tests/output +tests/output2 diff --git a/src/sonic-config-engine/tests/test_cfggen.py b/src/sonic-config-engine/tests/test_cfggen.py index 2c0368c9f18..981aa15d28b 100644 --- a/src/sonic-config-engine/tests/test_cfggen.py +++ b/src/sonic-config-engine/tests/test_cfggen.py @@ -20,6 +20,15 @@ def setUp(self): self.sample_graph_bgp_speaker = os.path.join(self.test_dir, 't0-sample-bgp-speaker.xml') self.sample_device_desc = os.path.join(self.test_dir, 'device.xml') self.port_config = os.path.join(self.test_dir, 't0-sample-port-config.ini') + self.output_file = os.path.join(self.test_dir, 'output') + self.output2_file = os.path.join(self.test_dir, 'output2') + + def tearDown(self): + try: + os.remove(self.output_file) + os.remove(self.output2_file) + except OSError: + pass def run_script(self, argument, check_stderr=False): print '\n Running sonic-cfggen ' + argument @@ -111,14 +120,14 @@ def test_render_template(self): def test_template_batch_mode(self): argument = '-y ' + os.path.join(self.test_dir, 'test.yml') argument += ' -a \'{"key1":"value"}\'' - argument += ' -t ' + os.path.join(self.test_dir, 'test.j2') + ',' + os.path.join(self.test_dir, 'test.txt') - argument += ' -t ' + os.path.join(self.test_dir, 'test2.j2') + ',' + os.path.join(self.test_dir, 'test2.txt') + argument += ' -t ' + os.path.join(self.test_dir, 'test.j2') + ',' + self.output_file + argument += ' -t ' + os.path.join(self.test_dir, 'test2.j2') + ',' + self.output2_file output = self.run_script(argument) - assert(os.path.exists(os.path.join(self.test_dir, 'test.txt'))) - assert(os.path.exists(os.path.join(self.test_dir, 'test2.txt'))) - with open(os.path.join(self.test_dir, 'test.txt')) as tf: + assert(os.path.exists(self.output_file)) + assert(os.path.exists(self.output2_file)) + with open(self.output_file) as tf: self.assertEqual(tf.read().strip(), 'value1\nvalue2') - with open(os.path.join(self.test_dir, 'test2.txt')) as tf: + with open(self.output2_file) as tf: self.assertEqual(tf.read().strip(), 'value') def test_template_json_batch_mode(self):