[vnf_base] improve exception 13/31013/1
authorboucherv <valentin.boucher@orange.com>
Mon, 20 Mar 2017 09:52:48 +0000 (10:52 +0100)
committerboucherv <valentin.boucher@orange.com>
Mon, 20 Mar 2017 09:52:48 +0000 (10:52 +0100)
Return on part of previous changes in commit: 30257
https://gerrit.opnfv.org/gerrit/#/c/30257/

Change-Id: I11b33ee2a6f9d4cbcf1449006b47be508fce655e
Signed-off-by: boucherv <valentin.boucher@orange.com>
functest/core/vnf_base.py
functest/opnfv_tests/vnf/ims/cloudify_ims.py
functest/tests/unit/core/test_vnf_base.py

index 0300dd2..f5e8605 100644 (file)
@@ -52,8 +52,13 @@ class VnfOnBoardingBase(base.TestcaseBase):
     def execute(self):
         self.start_time = time.time()
         # Prepare the test (Create Tenant, User, ...)
-        self.logger.info("Create VNF Onboarding environment")
-        self.prepare()
+        try:
+            self.logger.info("Create VNF Onboarding environment")
+            self.prepare()
+        except Exception:
+            self.logger.error("Error during VNF Onboarding environment" +
+                              "creation", exc_info=True)
+            return base.TestcaseBase.EX_TESTCASE_FAILED
 
         # Deploy orchestrator
         try:
@@ -179,11 +184,11 @@ class VnfOnBoardingBase(base.TestcaseBase):
     # TODO see how to use built-in exception from releng module
     def deploy_vnf(self):
         self.logger.error("VNF must be deployed")
-        return base.TestcaseBase.EX_TESTCASE_FAILED
+        raise Exception("VNF not deployed")
 
     def test_vnf(self):
         self.logger.error("VNF must be tested")
-        return base.TestcaseBase.EX_TESTCASE_FAILED
+        raise Exception("VNF not tested")
 
     def clean(self):
         self.logger.info("test cleaning")
@@ -232,4 +237,4 @@ class VnfOnBoardingBase(base.TestcaseBase):
         self.details[part]['status'] = 'FAIL'
         self.details[part]['result'] = error_msg
         self.logger.error("Step failure:{}".format(error_msg))
-        return base.TestcaseBase.EX_TESTCASE_FAILED
+        raise Exception(error_msg)
index 354bf88..74470ad 100644 (file)
@@ -276,6 +276,8 @@ class ImsVnf(vnf_base.VnfOnBoardingBase):
         i = 30
         while rq.status_code != 201 and i > 0:
             rq = requests.post(url, data=params)
+            self.logger.debug("Account creation http status code: %s"
+                              % rq.status_code)
             i = i - 1
             time.sleep(10)
 
@@ -292,6 +294,8 @@ class ImsVnf(vnf_base.VnfOnBoardingBase):
             i = 24
             while rq.status_code != 200 and i > 0:
                 rq = requests.post(url, cookies=cookies)
+                self.logger.debug("Number creation http status code: %s"
+                                  % rq.status_code)
                 i = i - 1
                 time.sleep(25)
 
index 25a74b7..1680f03 100644 (file)
@@ -8,11 +8,9 @@
 # http://www.apache.org/licenses/LICENSE-2.0
 
 import logging
-import mock
 import unittest
 
 from functest.core import vnf_base
-from functest.core import testcase_base
 
 
 class VnfBaseTesting(unittest.TestCase):
@@ -37,17 +35,15 @@ class VnfBaseTesting(unittest.TestCase):
                                           "result": "",
                                           "duration": 5}}
 
-    @mock.patch('logging.Logger.error')
-    def test_deploy_vnf_unimplemented(self, mock):
-        self.assertEqual(self.test.deploy_vnf(),
-                         testcase_base.TestcaseBase.EX_TESTCASE_FAILED)
-        mock.assert_called_with('VNF must be deployed')
-
-    @mock.patch('logging.Logger.error')
-    def test_test_vnf_unimplemented(self, mock):
-        self.assertEqual(self.test.test_vnf(),
-                         testcase_base.TestcaseBase.EX_TESTCASE_FAILED)
-        mock.assert_called_with('VNF must be tested')
+    def test_deploy_vnf_unimplemented(self):
+        with self.assertRaises(Exception) as context:
+            self.test.deploy_vnf()
+        self.assertTrue('VNF not deployed' in context.exception)
+
+    def test_test_vnf_unimplemented(self):
+        with self.assertRaises(Exception) as context:
+            self.test.test_vnf()()
+        self.assertTrue('VNF not tested' in context.exception)
 
     def test_parse_results(self):
         self.assertNotEqual(self.test.parse_results(), 0)