Driver helper methods correctly update LB status

Per discussion with the community, consensus was that the load
balancer object would not have its provisioning status updated
to ERROR if any children provisioned to ERROR.  This applies
that to the driver helper methods that drivers should call upon
a successful driver provisioning action or a failed driver
provisioning action.

Change-Id: I9f1786c7cbc7c776d3c866a4e5e83270e5b216d2
This commit is contained in:
Brandon Logan 2015-03-04 15:23:10 -06:00
parent a5b5b2f96d
commit b21651c17f
2 changed files with 25 additions and 20 deletions

View File

@ -46,9 +46,8 @@ class BaseManagerMixin(object):
def successful_completion(self, context, obj, delete=False): def successful_completion(self, context, obj, delete=False):
""" """
Sets the provisioning_status of the load balancer and obj to Sets the provisioning_status of the load balancer and obj to
ACTIVE. Also sets the operating status of obj to ONLINE. Should be ACTIVE. Should be called last in the implementor's BaseManagerMixin
called last in the implementor's BaseManagerMixin methods for methods for successful runs.
successful runs.
:param context: neutron context :param context: neutron context
:param obj: instance of a :param obj: instance of a
@ -56,21 +55,21 @@ class BaseManagerMixin(object):
:param delete: set True if being called from a delete method. Will :param delete: set True if being called from a delete method. Will
most likely result in the obj being deleted from the db. most likely result in the obj being deleted from the db.
""" """
# TODO(blogan): Will need to decide what to do with all operating
# statuses. Update to ONLINE here, or leave the operating status
# alone and let health checks update
obj_sa_cls = data_models.DATA_MODEL_TO_SA_MODEL_MAP[obj.__class__] obj_sa_cls = data_models.DATA_MODEL_TO_SA_MODEL_MAP[obj.__class__]
if delete: if delete:
self.db_delete_method(context, obj.id) self.db_delete_method(context, obj.id)
if obj == obj.root_loadbalancer and delete: if obj == obj.root_loadbalancer and delete:
# Load balancer was deleted and no longer exists # Load balancer was deleted and no longer exists
return return
lb_op_status = obj.root_loadbalancer.operating_status lb_op_status = None
lb_p_status = constants.ACTIVE
if obj == obj.root_loadbalancer: if obj == obj.root_loadbalancer:
# only set the status to online if this an operation on the
# load balancer
lb_op_status = lb_const.ONLINE lb_op_status = lb_const.ONLINE
self.driver.plugin.db.update_status( self.driver.plugin.db.update_status(
context, models.LoadBalancer, obj.root_loadbalancer.id, context, models.LoadBalancer, obj.root_loadbalancer.id,
provisioning_status=constants.ACTIVE, provisioning_status=lb_p_status,
operating_status=lb_op_status) operating_status=lb_op_status)
if obj == obj.root_loadbalancer or delete: if obj == obj.root_loadbalancer or delete:
# Do not want to update the status of the load balancer again # Do not want to update the status of the load balancer again
@ -88,28 +87,29 @@ class BaseManagerMixin(object):
def failed_completion(self, context, obj): def failed_completion(self, context, obj):
""" """
Sets the provisioning status of the load balancer and obj to Sets the provisioning status of the obj to ERROR. If obj is a
ERROR. Should be called whenever something goes wrong (raised loadbalancer it will be set to ERROR, otherwise set to ACTIVE. Should
exception) in an implementor's BaseManagerMixin methods. be called whenever something goes wrong (raised exception) in an
implementor's BaseManagerMixin methods.
:param context: neutron context :param context: neutron context
:param obj: instance of a :param obj: instance of a
neutron_lbaas.services.loadbalancer.data_model neutron_lbaas.services.loadbalancer.data_model
""" """
# TODO(blogan): Will need to decide what to do with all operating if isinstance(obj, data_models.LoadBalancer):
# statuses. Update to ONLINE here, or leave the operating status self.driver.plugin.db.update_status(
# alone and let health checks update context, models.LoadBalancer, obj.root_loadbalancer.id,
self.driver.plugin.db.update_status( provisioning_status=constants.ERROR,
context, models.LoadBalancer, obj.root_loadbalancer.id, operating_status=lb_const.OFFLINE)
provisioning_status=constants.ERROR)
if obj == obj.root_loadbalancer:
# Do not want to update the status of the load balancer again
return return
obj_sa_cls = data_models.DATA_MODEL_TO_SA_MODEL_MAP[obj.__class__] obj_sa_cls = data_models.DATA_MODEL_TO_SA_MODEL_MAP[obj.__class__]
self.driver.plugin.db.update_status( self.driver.plugin.db.update_status(
context, obj_sa_cls, obj.id, context, obj_sa_cls, obj.id,
provisioning_status=constants.ERROR, provisioning_status=constants.ERROR,
operating_status=lb_const.OFFLINE) operating_status=lb_const.OFFLINE)
self.driver.plugin.db.update_status(
context, models.LoadBalancer, obj.root_loadbalancer.id,
provisioning_status=constants.ACTIVE)
@six.add_metaclass(abc.ABCMeta) @six.add_metaclass(abc.ABCMeta)

View File

@ -114,6 +114,11 @@ class TestLBManager(TestBaseManager):
lb = self.plugin.db.get_loadbalancer(self.context, lb = self.plugin.db.get_loadbalancer(self.context,
self.listener.loadbalancer.id) self.listener.loadbalancer.id)
self.assertEqual(constants.ERROR, lb.provisioning_status) self.assertEqual(constants.ERROR, lb.provisioning_status)
self.assertEqual(lb_const.OFFLINE, lb.operating_status)
listener = self.plugin.db.get_listener(self.context, self.listener.id)
self.assertEqual(constants.PENDING_CREATE,
listener.provisioning_status)
self.assertEqual(lb_const.OFFLINE, listener.operating_status)
class TestListenerManager(TestBaseManager): class TestListenerManager(TestBaseManager):
@ -147,7 +152,7 @@ class TestListenerManager(TestBaseManager):
self.manager.failed_completion(self.context, self.listener) self.manager.failed_completion(self.context, self.listener)
lb = self.plugin.db.get_loadbalancer(self.context, lb = self.plugin.db.get_loadbalancer(self.context,
self.listener.loadbalancer.id) self.listener.loadbalancer.id)
self.assertEqual(constants.ERROR, lb.provisioning_status) self.assertEqual(constants.ACTIVE, lb.provisioning_status)
self.assertEqual(lb_const.OFFLINE, lb.operating_status) self.assertEqual(lb_const.OFFLINE, lb.operating_status)
listener = self.plugin.db.get_listener(self.context, self.listener.id) listener = self.plugin.db.get_listener(self.context, self.listener.id)
self.assertEqual(constants.ERROR, listener.provisioning_status) self.assertEqual(constants.ERROR, listener.provisioning_status)