diff options
Diffstat (limited to 'functest/opnfv_tests/vnf/ims/cloudify_ims.py')
-rw-r--r-- | functest/opnfv_tests/vnf/ims/cloudify_ims.py | 129 |
1 files changed, 24 insertions, 105 deletions
diff --git a/functest/opnfv_tests/vnf/ims/cloudify_ims.py b/functest/opnfv_tests/vnf/ims/cloudify_ims.py index 08699e4bb..bbb19694a 100644 --- a/functest/opnfv_tests/vnf/ims/cloudify_ims.py +++ b/functest/opnfv_tests/vnf/ims/cloudify_ims.py @@ -14,9 +14,7 @@ from __future__ import division import logging import os import time -import yaml -from cloudify_rest_client.executions import Execution import pkg_resources import scp import six @@ -25,6 +23,7 @@ from functest.core import cloudify from functest.opnfv_tests.vnf.ims import clearwater from functest.utils import config from functest.utils import env +from functest.utils import functest_utils __author__ = "Valentin Boucher <valentin.boucher@orange.com>" @@ -63,26 +62,34 @@ class CloudifyIms(cloudify.Cloudify): config_file = os.path.join(self.case_dir, self.config) self.details['orchestrator'] = dict( - name=get_config("orchestrator.name", config_file), - version=get_config("orchestrator.version", config_file), + name=functest_utils.get_parameter_from_yaml( + "orchestrator.name", config_file), + version=functest_utils.get_parameter_from_yaml( + "orchestrator.version", config_file), status='ERROR', result='' ) self.vnf = dict( - descriptor=get_config("vnf.descriptor", config_file), - inputs=get_config("vnf.inputs", config_file) + descriptor=functest_utils.get_parameter_from_yaml( + "vnf.descriptor", config_file), + inputs=functest_utils.get_parameter_from_yaml( + "vnf.inputs", config_file) ) self.details['vnf'] = dict( descriptor_version=self.vnf['descriptor']['version'], - name=get_config("vnf.name", config_file), - version=get_config("vnf.version", config_file), + name=functest_utils.get_parameter_from_yaml( + "vnf.name", config_file), + version=functest_utils.get_parameter_from_yaml( + "vnf.version", config_file), ) self.__logger.debug("VNF configuration: %s", self.vnf) self.details['test_vnf'] = dict( - name=get_config("vnf_test_suite.name", config_file), - version=get_config("vnf_test_suite.version", config_file) + name=functest_utils.get_parameter_from_yaml( + "vnf_test_suite.name", config_file), + version=functest_utils.get_parameter_from_yaml( + "vnf_test_suite.version", config_file) ) self.image_alt = None @@ -159,7 +166,7 @@ class CloudifyIms(cloudify.Cloudify): network_name=self.network.name, key_pair_name=self.keypair.name )) - if (self.deploy_vnf() and self.test_vnf()): + if self.deploy_vnf() and self.test_vnf(): self.result = 100 return 0 self.result = 1/3 * 100 @@ -200,16 +207,16 @@ class CloudifyIms(cloudify.Cloudify): descriptor.get('name'), descriptor.get('name'), self.vnf.get('inputs')) - wait_for_execution( + cloudify.wait_for_execution( self.cfy_client, - get_execution_id(self.cfy_client, descriptor.get('name')), + cloudify.get_execution_id(self.cfy_client, descriptor.get('name')), self.__logger, timeout=300) self.__logger.info("Start the VNF Instance deployment") execution = self.cfy_client.executions.start( descriptor.get('name'), 'install') # Show execution log - execution = wait_for_execution( + execution = cloudify.wait_for_execution( self.cfy_client, execution, self.__logger, timeout=3600) self.__logger.info(execution) @@ -222,7 +229,7 @@ class CloudifyIms(cloudify.Cloudify): self.vnf['descriptor'].get('name'))['outputs']['ellis_ip'] self.clearwater = clearwater.ClearwaterTesting(self.case_name, ellis_ip) - self.clearwater.availability_check_by_creating_numbers() + self.clearwater.availability_check() self.details['vnf'].update(status='PASS', duration=time.time() - start_time) @@ -282,7 +289,8 @@ class CloudifyIms(cloudify.Cloudify): parameters=dict(ignore_failure=True), force=True) - wait_for_execution(self.cfy_client, execution, self.__logger) + cloudify.wait_for_execution( + self.cfy_client, execution, self.__logger) self.cfy_client.deployments.delete( self.vnf['descriptor'].get('name')) self.cfy_client.blueprints.delete( @@ -294,92 +302,3 @@ class CloudifyIms(cloudify.Cloudify): if self.flavor_alt: self.orig_cloud.delete_flavor(self.flavor_alt.id) super(CloudifyIms, self).clean() - - -# ---------------------------------------------------------- -# -# YAML UTILS -# -# ----------------------------------------------------------- -def get_config(parameter, file_path): - """ - Get config parameter. - - Returns the value of a given parameter in file.yaml - parameter must be given in string format with dots - Example: general.openstack.image_name - """ - with open(file_path) as config_file: - file_yaml = yaml.safe_load(config_file) - config_file.close() - value = file_yaml - for element in parameter.split("."): - value = value.get(element) - if value is None: - raise ValueError("The parameter %s is not defined in" - " reporting.yaml" % parameter) - return value - - -def wait_for_execution(client, execution, logger, timeout=3600, ): - """Wait for a workflow execution on Cloudify Manager.""" - # if execution already ended - return without waiting - if execution.status in Execution.END_STATES: - return execution - - if timeout is not None: - deadline = time.time() + timeout - - # Poll for execution status and execution logs, until execution ends - # and we receive an event of type in WORKFLOW_END_TYPES - offset = 0 - batch_size = 50 - event_list = [] - execution_ended = False - while True: - event_list = client.events.list( - execution_id=execution.id, - _offset=offset, - _size=batch_size, - include_logs=True, - sort='@timestamp').items - - offset = offset + len(event_list) - for event in event_list: - logger.debug(event.get('message')) - - if timeout is not None: - if time.time() > deadline: - raise RuntimeError( - 'execution of operation {0} for deployment {1} ' - 'timed out'.format(execution.workflow_id, - execution.deployment_id)) - else: - # update the remaining timeout - timeout = deadline - time.time() - - if not execution_ended: - execution = client.executions.get(execution.id) - execution_ended = execution.status in Execution.END_STATES - - if execution_ended: - break - - time.sleep(5) - - return execution - - -def get_execution_id(client, deployment_id): - """ - Get the execution id of a env preparation. - - network, security group, fip, VM creation - """ - executions = client.executions.list(deployment_id=deployment_id) - for execution in executions: - if execution.workflow_id == 'create_deployment_environment': - return execution - raise RuntimeError('Failed to get create_deployment_environment ' - 'workflow execution.' - 'Available executions: {0}'.format(executions)) |