aboutsummaryrefslogtreecommitdiffstats
path: root/functest/utils/openstack_tacker.py
diff options
context:
space:
mode:
Diffstat (limited to 'functest/utils/openstack_tacker.py')
-rw-r--r--functest/utils/openstack_tacker.py72
1 files changed, 48 insertions, 24 deletions
diff --git a/functest/utils/openstack_tacker.py b/functest/utils/openstack_tacker.py
index f3597965..8327fdbe 100644
--- a/functest/utils/openstack_tacker.py
+++ b/functest/utils/openstack_tacker.py
@@ -45,8 +45,16 @@ def get_vnfd_id(tacker_client, vnfd_name):
return get_id_from_name(tacker_client, 'vnfd', vnfd_name)
-def get_vnf_id(tacker_client, vnf_name):
- return get_id_from_name(tacker_client, 'vnf', vnf_name)
+def get_vnf_id(tacker_client, vnf_name, timeout=5):
+ vnf_id = None
+ while vnf_id is None and timeout >= 0:
+ vnf_id = get_id_from_name(tacker_client, 'vnf', vnf_name)
+ if vnf_id is None:
+ logger.info("Could not retrieve ID for vnf with name [%s]."
+ " Retrying." % vnf_name)
+ time.sleep(1)
+ timeout -= 1
+ return vnf_id
def get_sfc_id(tacker_client, sfc_name):
@@ -118,6 +126,7 @@ def create_vnf(tacker_client, vnf_name, vnfd_id=None,
}
}
if param_file is not None:
+ params = None
with open(param_file) as f:
params = f.read()
vnf_body['vnf']['attributes']['param_values'] = params
@@ -135,32 +144,44 @@ def create_vnf(tacker_client, vnf_name, vnfd_id=None,
return None
-def wait_for_vnf(tacker_client, vnf_id=None, vnf_name=None):
+def get_vnf(tacker_client, vnf_id=None, vnf_name=None):
try:
- _id = None
- if vnf_id is not None:
- _id = vnf_id
- elif vnf_name is not None:
- while _id is None:
- try:
- _id = get_vnf_id(tacker_client, vnf_name)
- except:
- logger.error("Bazinga")
- else:
+ if vnf_id is None and vnf_name is None:
raise Exception('You must specify vnf_id or vnf_name')
- while True:
- vnf = [v for v in list_vnfs(tacker_client, verbose=True)['vnfs']
- if v['id'] == _id]
- vnf = vnf[0]
- logger.info('Waiting for vnf {0}'.format(str(vnf)))
+
+ _id = get_vnf_id(tacker_client, vnf_name) if vnf_id is None else vnf_id
+
+ if _id is not None:
+ all_vnfs = list_vnfs(tacker_client, verbose=True)['vnfs']
+ return next((vnf for vnf in all_vnfs if vnf['id'] == _id), None)
+ else:
+ raise Exception('Could not retrieve ID from name [%s]' % vnf_name)
+
+ except Exception, e:
+ logger.error("Could not retrieve VNF [vnf_id=%s, vnf_name=%s] - %s"
+ % (vnf_id, vnf_name, e))
+ return None
+
+
+def wait_for_vnf(tacker_client, vnf_id=None, vnf_name=None, timeout=60):
+ try:
+ vnf = get_vnf(tacker_client, vnf_id, vnf_name)
+ if vnf is None:
+ raise Exception("Could not retrieve VNF - id='%s', name='%s'"
+ % vnf_id, vnf_name)
+ logger.info('Waiting for vnf {0}'.format(str(vnf)))
+ while vnf['status'] != 'ACTIVE' and timeout >= 0:
if vnf['status'] == 'ERROR':
- raise Exception('Error when booting vnf %s' % _id)
+ raise Exception('Error when booting vnf %s' % vnf['id'])
elif vnf['status'] == 'PENDING_CREATE':
time.sleep(3)
- continue
- else:
- break
- return _id
+ timeout -= 3
+ vnf = get_vnf(tacker_client, vnf_id, vnf_name)
+
+ if (timeout < 0):
+ raise Exception('Timeout when booting vnf %s' % vnf['id'])
+
+ return vnf['id']
except Exception, e:
logger.error("error [wait_for_vnf(tacker_client, '%s', '%s')]: %s"
% (vnf_id, vnf_name, e))
@@ -194,7 +215,8 @@ def list_sfcs(tacker_client, verbose=False):
def create_sfc(tacker_client, sfc_name,
chain_vnf_ids=None,
- chain_vnf_names=None):
+ chain_vnf_names=None,
+ symmetrical=False):
try:
sfc_body = {
'sfc': {
@@ -203,6 +225,8 @@ def create_sfc(tacker_client, sfc_name,
'chain': []
}
}
+ if symmetrical:
+ sfc_body['sfc']['symmetrical'] = True
if chain_vnf_ids is not None:
sfc_body['sfc']['chain'] = chain_vnf_ids
else: