diff options
author | Manuel Buil <mbuil@suse.com> | 2018-11-05 20:46:46 +0100 |
---|---|---|
committer | Manuel Buil <mbuil@suse.com> | 2018-11-06 10:29:19 +0100 |
commit | 52e86db6e0a3343852c9aabba49dffe3d699d1a0 (patch) | |
tree | 0045cf59a98c3671ed4d250cf2819d23ae6777e7 /sfc/lib | |
parent | 6c11ccaa5e9f036a1b56926d80aaccb3dc5e3d78 (diff) |
Avoid race conditions
Sometimes the port pair group gets created before port pair was
committed in openstack. Before creating the port pair group, we check
that the port pair is already listed by openstack
Change-Id: Icfd23521859fc5d4e6bb6745be80f79bf9e31a0c
Signed-off-by: Manuel Buil <mbuil@suse.com>
Diffstat (limited to 'sfc/lib')
-rw-r--r-- | sfc/lib/openstack_utils.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/sfc/lib/openstack_utils.py b/sfc/lib/openstack_utils.py index 7915e77d..38ca61bb 100644 --- a/sfc/lib/openstack_utils.py +++ b/sfc/lib/openstack_utils.py @@ -316,6 +316,23 @@ class OpenStackSFC: {'vnf': vm_instance.name}) return None + # Avoid race conditions by checking the port pair is already committed + iterations = 5 + found_it = False + for i in range(iterations): + pp_list = self.neutron.list_sfc_port_pairs()['port_pairs'] + for pp in pp_list: + if pp['id'] == port_pair_info['port_pair']['id']: + found_it = True + break + if found_it: + break + else: + time.sleep(3) + + if not found_it: + raise Exception("Port pair was not committed in openstack") + logger.info("Creating the port pair groups for %s" % vm_instance.name) port_pair_group = {} port_pair_group['name'] = vm_instance.name + '-port-pair-group' |