Merge "Return 'status' field for STATS on deleted LB."

This commit is contained in:
Jenkins 2013-05-16 17:48:22 +00:00 committed by Gerrit Code Review
commit 719eb29395
3 changed files with 41 additions and 1 deletions

25
libra/common/exc.py Normal file
View File

@ -0,0 +1,25 @@
# Copyright 2013 Hewlett-Packard Development Company, L.P.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
class DeletedStateError(Exception):
"""
Exception representing an invalid operation on a load balancer that
is in the deleted state.
"""
def __init__(self, value):
self.value = value
def __str__(self):
return repr(self.value)

View File

@ -14,6 +14,7 @@
from libra import __version__ as libra_version
from libra import __release__ as libra_release
from libra.common.exc import DeletedStateError
from libra.common.faults import BadRequest
from libra.worker.drivers.base import LoadBalancerDriver
@ -337,7 +338,14 @@ class LBaaSController(object):
return self.msg
def _action_stats(self):
""" Get load balancer statistics. """
"""
Get load balancer statistics.
We push responsibility for knowing what state a load balancer
current is in to the driver. Trying to get statistics for a LB that
has been deleted is an error.
"""
try:
# TODO: Do something with the returned statistics
self.driver.get_stats(protocol=None)
@ -346,6 +354,10 @@ class LBaaSController(object):
self.logger.error(error)
self.msg[self.RESPONSE_FIELD] = self.RESPONSE_FAILURE
self.msg[self.ERROR_FIELD] = error
except DeletedStateError:
self.logger.info("Invalid operation STATS on a deleted LB")
self.msg['status'] = 'DELETED'
self.msg[self.RESPONSE_FIELD] = self.RESPONSE_FAILURE
except Exception as e:
self.logger.error("STATS failed: %s, %s" % (e.__class__, e))
self.msg[self.RESPONSE_FIELD] = self.RESPONSE_FAILURE

View File

@ -15,6 +15,7 @@
import os
import subprocess
from libra.common.exc import DeletedStateError
from libra.common.lbstats import LBStatistics
from libra.worker.drivers.haproxy.services_base import ServicesBase
from libra.worker.drivers.haproxy.query import HAProxyQuery
@ -146,6 +147,8 @@ class UbuntuServices(ServicesBase):
http://cbonte.github.com/haproxy-dconv/configuration-1.4.html#9
"""
if not os.path.exists(self._config_file):
raise DeletedStateError("Load balancer is deleted.")
if not os.path.exists(self._haproxy_pid):
raise Exception("HAProxy is not running.")