Skip to content

Commit

Permalink
- Add retry for connecting to api-server
Browse files Browse the repository at this point in the history
- Prevent delete of service instance on pool delete if
  vip or member reference still exists
- Raise error if incorrect lb method specified

Change-Id: I32facee5081006d05e196b4af20f7adabb300c1c
  • Loading branch information
rrugge committed Sep 26, 2014
1 parent 0aebaa2 commit 53a43c4
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -252,15 +252,13 @@ def update_pool(self, context, old_pool, pool):
"""
if pool['vip_id']:
self._update_loadbalancer_instance(pool['id'], pool['vip_id'])
else:
self._clear_loadbalancer_instance(pool['tenant_id'], pool['id'])

def delete_pool(self, context, pool):
"""Driver can call the code below in order to delete the pool.
self.plugin._delete_db_pool(context, pool["id"])
or set the status to ERROR if deletion failed
"""
self._clear_loadbalancer_instance(pool['tenant_id'], pool['id'])
pass

def stats(self, context, pool_id):
pass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# Copyright (c) 2014 Juniper Networks, Inc. All rights reserved.
#

import requests
import time
import uuid

from oslo.config import cfg
Expand Down Expand Up @@ -53,11 +55,20 @@ def __init__(self):
except cfg.NoSuchOptError:
api_server_url = "/"

self._api = VncApi(admin_user, admin_password, admin_tenant_name,
api_srvr_ip, api_srvr_port, api_server_url,
auth_host=auth_host, auth_port=auth_port,
auth_protocol=auth_protocol, auth_url=auth_url,
auth_type=auth_type)
# Retry till a api-server is up
connected = False
while not connected:
try:
self._api = VncApi(
admin_user, admin_password, admin_tenant_name,
api_srvr_ip, api_srvr_port, api_server_url,
auth_host=auth_host, auth_port=auth_port,
auth_protocol=auth_protocol, auth_url=auth_url,
auth_type=auth_type)
connected = True
except requests.exceptions.RequestException as e:
time.sleep(3)

self._pool_manager = \
loadbalancer_pool.LoadbalancerPoolManager(self._api)
self._vip_manager = virtual_ip.VirtualIpManager(self._api)
Expand Down Expand Up @@ -151,7 +162,7 @@ def get_pool_health_monitor(self, context, id, pool_id, fields=None):
raise loadbalancer.PoolNotFound(pool_id=id)

in_list = False
for mref in pool.get_loadbalancer_healthmonitor_refs():
for mref in pool.get_loadbalancer_healthmonitor_refs() or []:
if mref['uuid'] == id:
in_list = True
break
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

from neutron.extensions import loadbalancer
from neutron.openstack.common import uuidutils
from vnc_api.vnc_api import IdPermsType, NoIdError
from vnc_api.vnc_api import IdPermsType, NoIdError, HttpError
from vnc_api.vnc_api import LoadbalancerPool, LoadbalancerPoolType

from resource_manager import ResourceManager

from resource_manager import LoadbalancerMethodInvalid

class LoadbalancerPoolManager(ResourceManager):

Expand Down Expand Up @@ -78,7 +78,14 @@ def resource_list(self, tenant_id=None):
return self._api.loadbalancer_pools_list(parent_id=parent_id)

def resource_update(self, obj):
return self._api.loadbalancer_pool_update(obj)
try:
return self._api.loadbalancer_pool_update(obj)
except HttpError as e:
if 'LoadbalancerMethodType' in e.content:
pool_props = obj.get_loadbalancer_pool_properties()
lb_method = pool_props.get_loadbalancer_method()
raise LoadbalancerMethodInvalid(lb_method=lb_method,
pool_id=obj.uuid)

def resource_delete(self, id):
return self._api.loadbalancer_pool_delete(id=id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
import six
import uuid

class LoadbalancerMethodInvalid(n_exc.BadRequest):
message = _("Method %(lb_method)s not supported for pool %(pool_id)s")


@six.add_metaclass(ABCMeta)
class ResourceManager(object):
Expand Down

0 comments on commit 53a43c4

Please sign in to comment.