Remove duplicated code in vnfs
[functest.git] / functest / opnfv_tests / vnf / router / cloudify_vrouter.py
index e8c8632..a0145b8 100644 (file)
@@ -15,7 +15,6 @@ import logging
 import os
 import time
 
-from cloudify_rest_client.executions import Execution
 import pkg_resources
 import scp
 
@@ -181,8 +180,8 @@ class CloudifyVrouter(cloudify.Cloudify):
             descriptor.get('name'), descriptor.get('name'),
             self.vnf.get('inputs'))
 
-        wait_for_execution(
-            self.cfy_client, get_execution_id(
+        cloudify.wait_for_execution(
+            self.cfy_client, cloudify.get_execution_id(
                 self.cfy_client, descriptor.get('name')),
             self.__logger, timeout=7200)
 
@@ -190,7 +189,7 @@ class CloudifyVrouter(cloudify.Cloudify):
         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)
 
         duration = time.time() - start_time
@@ -237,7 +236,8 @@ class CloudifyVrouter(cloudify.Cloudify):
             execution = self.cfy_client.executions.start(
                 dep_name, 'uninstall', parameters=dict(ignore_failure=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(
@@ -249,63 +249,3 @@ class CloudifyVrouter(cloudify.Cloudify):
         if self.flavor_alt:
             self.orig_cloud.delete_flavor(self.flavor_alt.id)
         super(CloudifyVrouter, self).clean()
-
-
-def wait_for_execution(client, execution, logger, timeout=7200, ):
-    """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))