Return 'status' field for STATS on deleted LB.
Fixes bug 1177642. Due to a race condition in some of our Jenkins tests, it is possible that we could send a STATS message to a LB that has just been deleted. To recognize this situation, we'll return a FAIL message, but include a new 'status' field in the JSON response indicating the LB is deleted. Change-Id: I785cfdff526e67f4b55bf3f9bff911052c27ece7
This commit is contained in:
		
							
								
								
									
										25
									
								
								libra/common/exc.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								libra/common/exc.py
									
									
									
									
									
										Normal 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) | ||||||
| @@ -14,6 +14,7 @@ | |||||||
|  |  | ||||||
| from libra import __version__ as libra_version | from libra import __version__ as libra_version | ||||||
| from libra import __release__ as libra_release | from libra import __release__ as libra_release | ||||||
|  | from libra.common.exc import DeletedStateError | ||||||
| from libra.common.faults import BadRequest | from libra.common.faults import BadRequest | ||||||
| from libra.worker.drivers.base import LoadBalancerDriver | from libra.worker.drivers.base import LoadBalancerDriver | ||||||
|  |  | ||||||
| @@ -337,7 +338,14 @@ class LBaaSController(object): | |||||||
|         return self.msg |         return self.msg | ||||||
|  |  | ||||||
|     def _action_stats(self): |     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: |         try: | ||||||
|             # TODO: Do something with the returned statistics |             # TODO: Do something with the returned statistics | ||||||
|             self.driver.get_stats(protocol=None) |             self.driver.get_stats(protocol=None) | ||||||
| @@ -346,6 +354,10 @@ class LBaaSController(object): | |||||||
|             self.logger.error(error) |             self.logger.error(error) | ||||||
|             self.msg[self.RESPONSE_FIELD] = self.RESPONSE_FAILURE |             self.msg[self.RESPONSE_FIELD] = self.RESPONSE_FAILURE | ||||||
|             self.msg[self.ERROR_FIELD] = error |             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: |         except Exception as e: | ||||||
|             self.logger.error("STATS failed: %s, %s" % (e.__class__, e)) |             self.logger.error("STATS failed: %s, %s" % (e.__class__, e)) | ||||||
|             self.msg[self.RESPONSE_FIELD] = self.RESPONSE_FAILURE |             self.msg[self.RESPONSE_FIELD] = self.RESPONSE_FAILURE | ||||||
|   | |||||||
| @@ -15,6 +15,7 @@ | |||||||
| import os | import os | ||||||
| import subprocess | import subprocess | ||||||
|  |  | ||||||
|  | from libra.common.exc import DeletedStateError | ||||||
| from libra.common.lbstats import LBStatistics | from libra.common.lbstats import LBStatistics | ||||||
| from libra.worker.drivers.haproxy.services_base import ServicesBase | from libra.worker.drivers.haproxy.services_base import ServicesBase | ||||||
| from libra.worker.drivers.haproxy.query import HAProxyQuery | 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 |         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): |         if not os.path.exists(self._haproxy_pid): | ||||||
|             raise Exception("HAProxy is not running.") |             raise Exception("HAProxy is not running.") | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 David Shrewsbury
					David Shrewsbury