diff options
author | 2017-02-20 10:29:29 +0000 | |
---|---|---|
committer | 2017-02-20 10:40:40 +0000 | |
commit | 5807f2c7d8eb73b11331147de9a240f53b329693 (patch) | |
tree | 0bfdf03905272f78e42c67962f17b5ab1bf605d3 /functest/utils | |
parent | 0b5f01779a50b36d775a5ed8fed53106d04c450c (diff) |
[odl-sfc] Add timeout to get_vnf_id and create_vnf functions
create_vnf function could end up in and endless loop if it is not able to
retrieve the VNF id. Also, a timeout could help to detect problems when
instantiation is too slow.
Change-Id: I21744338a73f122d0c7a8fbe699738b11a7e2b76
Signed-off-by: Juan Vidal <juan.vidal.allende@ericsson.com>
Diffstat (limited to 'functest/utils')
-rw-r--r-- | functest/utils/openstack_tacker.py | 40 |
1 files changed, 22 insertions, 18 deletions
diff --git a/functest/utils/openstack_tacker.py b/functest/utils/openstack_tacker.py index d745f105..1c02e040 100644 --- a/functest/utils/openstack_tacker.py +++ b/functest/utils/openstack_tacker.py @@ -45,8 +45,17 @@ 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: + try: + vnf_id = get_id_from_name(tacker_client, 'vnf', vnf_name) + except: + 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): @@ -136,28 +145,23 @@ 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 wait_for_vnf(tacker_client, vnf_id=None, vnf_name=None, timeout=60): 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 + + vnf = next((v for v in list_vnfs(tacker_client, verbose=True)['vnfs'] + if v['id'] == _id), None) + if vnf is None: + raise Exception("Could not retrieve VNF with ID [%s]" % _id) + logger.info('Waiting for vnf {0}'.format(str(vnf))) + while True and timeout >= 0: if vnf['status'] == 'ERROR': raise Exception('Error when booting vnf %s' % _id) elif vnf['status'] == 'PENDING_CREATE': time.sleep(3) + timeout -= 3 continue else: break |