Create results/tempest dir for refstack config 29/41029/2
authorLinda Wang <wangwulin@huawei.com>
Tue, 5 Sep 2017 02:49:56 +0000 (02:49 +0000)
committerLinda Wang <wangwulin@huawei.com>
Tue, 5 Sep 2017 07:13:21 +0000 (07:13 +0000)
When generating refstack client reference tempest conf file,
the step of tempest.conf backup is necessary.
So if the dir results/tempest is absent, error shows:
[Errno 2] No such file or directory:
'/home/opnfv/functest/results/tempest/tempest.conf'

Change-Id: I7aba5baff55a51881d125b28f99d71d0cc0a5c72
Signed-off-by: Linda Wang <wangwulin@huawei.com>
functest/opnfv_tests/openstack/tempest/conf_utils.py
functest/tests/unit/openstack/tempest/test_conf_utils.py

index 52fa600..6c3e820 100644 (file)
@@ -130,6 +130,8 @@ def backup_tempest_config(conf_file):
     """
     Copy config file to tempest results directory
     """
+    if not os.path.exists(TEMPEST_RESULTS_DIR):
+        os.makedirs(TEMPEST_RESULTS_DIR)
     shutil.copyfile(conf_file,
                     os.path.join(TEMPEST_RESULTS_DIR, 'tempest.conf'))
 
index 7755808..22017a7 100644 (file)
@@ -170,9 +170,23 @@ class OSTempestConfUtilsTesting(unittest.TestCase):
 
     def test_backup_tempest_config_default(self):
         with mock.patch('functest.opnfv_tests.openstack.tempest.'
-                        'conf_utils.shutil.copyfile') as m1:
+                        'conf_utils.os.path.exists',
+                        return_value=False), \
+            mock.patch('functest.opnfv_tests.openstack.tempest.'
+                       'conf_utils.os.makedirs') as m1, \
+            mock.patch('functest.opnfv_tests.openstack.tempest.'
+                       'conf_utils.shutil.copyfile') as m2:
             conf_utils.backup_tempest_config('test_conf_file')
             self.assertTrue(m1.called)
+            self.assertTrue(m2.called)
+
+        with mock.patch('functest.opnfv_tests.openstack.tempest.'
+                        'conf_utils.os.path.exists',
+                        return_value=True), \
+            mock.patch('functest.opnfv_tests.openstack.tempest.'
+                       'conf_utils.shutil.copyfile') as m2:
+            conf_utils.backup_tempest_config('test_conf_file')
+            self.assertTrue(m2.called)
 
     def test_configure_tempest_default(self):
         with mock.patch('functest.opnfv_tests.openstack.tempest.'