Pass HAProxy config to OS services driver.
Bug fix. We weren't passing the HAProxy config as a string down to the OS service module. Also remove the service_restart() method since it was unused. Also set a default balancing algorithm. Change-Id: I8db025488099fed5015d62e0bf9c73c6e6795483
This commit is contained in:
@@ -125,21 +125,23 @@ class LBaaSController(object):
|
|||||||
self.logger.error("Invalid algorithm: %s" % algo)
|
self.logger.error("Invalid algorithm: %s" % algo)
|
||||||
self.msg[self.RESPONSE_FIELD] = self.RESPONSE_FAILURE
|
self.msg[self.RESPONSE_FIELD] = self.RESPONSE_FAILURE
|
||||||
return self.msg
|
return self.msg
|
||||||
|
else:
|
||||||
|
algo = LoadBalancerDriver.ROUNDROBIN
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.driver.set_algorithm(current_lb['protocol'], algo)
|
self.driver.set_algorithm(current_lb['protocol'], algo)
|
||||||
except NotImplementedError:
|
except NotImplementedError:
|
||||||
self.logger.error(
|
self.logger.error(
|
||||||
"Selected driver does not support setting algorithm."
|
"Selected driver does not support setting algorithm."
|
||||||
)
|
)
|
||||||
self.msg[self.RESPONSE_FIELD] = self.RESPONSE_FAILURE
|
self.msg[self.RESPONSE_FIELD] = self.RESPONSE_FAILURE
|
||||||
return self.msg
|
return self.msg
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error(
|
self.logger.error(
|
||||||
"Selected driver failed setting algorithm."
|
"Selected driver failed setting algorithm."
|
||||||
)
|
)
|
||||||
self.msg[self.RESPONSE_FIELD] = self.RESPONSE_FAILURE
|
self.msg[self.RESPONSE_FIELD] = self.RESPONSE_FAILURE
|
||||||
return self.msg
|
return self.msg
|
||||||
|
|
||||||
for lb_node in current_lb['nodes']:
|
for lb_node in current_lb['nodes']:
|
||||||
port, address = None, None
|
port, address = None, None
|
||||||
@@ -183,7 +185,7 @@ class LBaaSController(object):
|
|||||||
self.msg[self.RESPONSE_FIELD] = self.RESPONSE_FAILURE
|
self.msg[self.RESPONSE_FIELD] = self.RESPONSE_FAILURE
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error("CREATE failed: %s, %s" % (e.__class__, e))
|
self.logger.error("CREATE failed: %s, %s" % (e.__class__, e))
|
||||||
for lb_node in self.msg['nodes']:
|
for lb_node in current_lb['nodes']:
|
||||||
lb_node['condition'] = self.NODE_ERR
|
lb_node['condition'] = self.NODE_ERR
|
||||||
self.msg[self.RESPONSE_FIELD] = self.RESPONSE_FAILURE
|
self.msg[self.RESPONSE_FIELD] = self.RESPONSE_FAILURE
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ class HAProxyDriver(LoadBalancerDriver):
|
|||||||
raise Exception('Invalid algorithm: %s' % protocol)
|
raise Exception('Invalid algorithm: %s' % protocol)
|
||||||
|
|
||||||
def create(self):
|
def create(self):
|
||||||
self.ossvc.write_config()
|
self.ossvc.write_config(self._config_to_string())
|
||||||
self.ossvc.service_stop()
|
self.ossvc.service_stop()
|
||||||
self.ossvc.service_start()
|
self.ossvc.service_start()
|
||||||
|
|
||||||
|
|||||||
@@ -34,11 +34,7 @@ class ServicesBase:
|
|||||||
""" Start the HAProxy service. """
|
""" Start the HAProxy service. """
|
||||||
return NotImplementedError()
|
return NotImplementedError()
|
||||||
|
|
||||||
def service_restart(self):
|
def write_config(self, config_str):
|
||||||
""" Restart the HAProxy service. """
|
|
||||||
return NotImplementedError()
|
|
||||||
|
|
||||||
def write_config(self):
|
|
||||||
""" Write the HAProxy configuration file. """
|
""" Write the HAProxy configuration file. """
|
||||||
return NotImplementedError()
|
return NotImplementedError()
|
||||||
|
|
||||||
|
|||||||
@@ -50,10 +50,7 @@ class UbuntuServices(ServicesBase):
|
|||||||
raise Exception("%s does not exist. Start failed." %
|
raise Exception("%s does not exist. Start failed." %
|
||||||
self._haproxy_pid)
|
self._haproxy_pid)
|
||||||
|
|
||||||
def service_restart(self):
|
def write_config(self, config_str):
|
||||||
return NotImplementedError()
|
|
||||||
|
|
||||||
def write_config(self):
|
|
||||||
"""
|
"""
|
||||||
Generate the new config and replace the current config file.
|
Generate the new config and replace the current config file.
|
||||||
|
|
||||||
@@ -61,7 +58,6 @@ class UbuntuServices(ServicesBase):
|
|||||||
the production config file, then rename the temporary config to the
|
the production config file, then rename the temporary config to the
|
||||||
production config.
|
production config.
|
||||||
"""
|
"""
|
||||||
config_str = self._config_to_string()
|
|
||||||
tmpfile = '/tmp/haproxy.cfg'
|
tmpfile = '/tmp/haproxy.cfg'
|
||||||
fh = open(tmpfile, 'w')
|
fh = open(tmpfile, 'w')
|
||||||
fh.write(config_str)
|
fh.write(config_str)
|
||||||
|
|||||||
@@ -19,10 +19,7 @@ class FakeOSServices(ServicesBase):
|
|||||||
def service_start(self):
|
def service_start(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def service_restart(self):
|
def write_config(self, config_str):
|
||||||
pass
|
|
||||||
|
|
||||||
def write_config(self):
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def remove_configs(self):
|
def remove_configs(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user