3 # Copyright (c) 2016 Orange and others.
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 """Define the parent class of all VNF TestCases."""
16 from xtesting.core import testcase
18 __author__ = ("Morgan Richomme <morgan.richomme@orange.com>, "
19 "Valentin Boucher <valentin.boucher@orange.com>")
22 class VnfPreparationException(Exception):
23 """Raise when VNF preparation cannot be executed."""
26 class OrchestratorDeploymentException(Exception):
27 """Raise when orchestrator cannot be deployed."""
30 class VnfDeploymentException(Exception):
31 """Raise when VNF cannot be deployed."""
34 class VnfTestException(Exception):
35 """Raise when VNF cannot be tested."""
38 class VnfOnBoarding(testcase.TestCase):
39 # pylint: disable=too-many-instance-attributes
40 """Base model for VNF test cases."""
42 __logger = logging.getLogger(__name__)
44 def __init__(self, **kwargs):
45 super(VnfOnBoarding, self).__init__(**kwargs)
46 self.uuid = uuid.uuid4()
47 self.user_name = "{}-{}".format(self.case_name, self.uuid)
48 self.tenant_name = "{}-{}".format(self.case_name, self.uuid)
50 self.created_object = []
51 self.os_project = None
52 self.tenant_description = "Created by OPNFV Functest: {}".format(
55 def run(self, **kwargs):
57 Run of the VNF test case:
59 * Deploy an orchestrator if needed (e.g. heat, cloudify, ONAP,...),
61 * Perform tests on the VNF
63 A VNF test case is successfull when the 3 steps are PASS
64 If one of the step is FAIL, the test case is FAIL
67 TestCase.EX_OK if result is 'PASS'.
68 TestCase.EX_TESTCASE_FAILED otherwise.
70 self.start_time = time.time()
74 if (self.deploy_orchestrator() and
77 self.stop_time = time.time()
78 # Calculation with different weight depending on the steps TODO
80 return testcase.TestCase.EX_OK
82 self.stop_time = time.time()
83 return testcase.TestCase.EX_TESTCASE_FAILED
84 except Exception: # pylint: disable=broad-except
85 self.stop_time = time.time()
86 self.__logger.exception("Exception on VNF testing")
87 return testcase.TestCase.EX_TESTCASE_FAILED
91 Prepare the environment for VNF testing:
93 Returns base.TestCase.EX_OK if preparation is successfull
95 Raise VnfPreparationException in case of problem
97 self.__logger.exception("VNF must be prepared")
98 raise VnfPreparationException
100 def deploy_orchestrator(self):
102 Deploy an orchestrator (optional).
104 If this method is overriden then raise orchestratorDeploymentException
105 if error during orchestrator deployment
107 self.__logger.info("Deploy orchestrator (if necessary)")
110 def deploy_vnf(self):
114 This function MUST be implemented by vnf test cases.
115 The details section MAY be updated in the vnf test cases.
117 The deployment can be executed via a specific orchestrator
118 or using build-in orchestrators such as heat, OpenBaton, cloudify,
122 True if the VNF is properly deployed
123 False if the VNF is not deployed
125 Raise VnfDeploymentException if error during VNF deployment
127 self.__logger.error("VNF must be deployed")
128 raise VnfDeploymentException
134 This function MUST be implemented by vnf test cases.
135 The details section MAY be updated in the vnf test cases.
137 Once a VNF is deployed, it is assumed that specific test suite can be
138 run to validate the VNF.
139 Please note that the same test suite can be used on several test case
140 (e.g. clearwater test suite can be used whatever the orchestrator used
144 True if VNF tests are PASS
145 False if test suite is FAIL
147 Raise VnfTestException if error during VNF test
149 self.__logger.error("VNF must be tested")
150 raise VnfTestException
156 It is up to the test providers to delete resources used for the tests.
162 self.__logger.info('Removing the VNF resources ..')
163 for creator in reversed(self.created_object):
166 except Exception as exc: # pylint: disable=broad-except
167 self.__logger.error('Unexpected error cleaning - %s', exc)