Fix for CREATE if haproxy config does not exist.
If the CREATE action follows a DELETE actions, it's possible that a configuration file may not exist, so we must allow for that. Also, stop the HAProxy process before deleting configuration files.
This commit is contained in:
@@ -12,6 +12,7 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
from libra.worker.drivers.base import LoadBalancerDriver
|
from libra.worker.drivers.base import LoadBalancerDriver
|
||||||
@@ -81,12 +82,20 @@ class HAProxyDriver(LoadBalancerDriver):
|
|||||||
fh.write(config_str)
|
fh.write(config_str)
|
||||||
fh.close()
|
fh.close()
|
||||||
|
|
||||||
copy_cmd = "/usr/bin/sudo /bin/cp %s %s" % (self._config_file,
|
# Copy any existing configuration file to a backup.
|
||||||
self._backup_config)
|
if os.path.exists(self._config_file):
|
||||||
move_cmd = "/usr/bin/sudo /bin/mv %s %s" % (tmpfile, self._config_file)
|
copy_cmd = "/usr/bin/sudo /bin/cp %s %s" % (self._config_file,
|
||||||
|
self._backup_config)
|
||||||
|
try:
|
||||||
|
subprocess.check_output(copy_cmd.split(),
|
||||||
|
stderr=subprocess.STDOUT)
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
raise Exception("Failed to copy configuration file: %s" %
|
||||||
|
e.output.rstrip('\n'))
|
||||||
|
|
||||||
|
# Move the temporary config file to production version.
|
||||||
|
move_cmd = "/usr/bin/sudo /bin/mv %s %s" % (tmpfile, self._config_file)
|
||||||
try:
|
try:
|
||||||
subprocess.check_output(copy_cmd.split(), stderr=subprocess.STDOUT)
|
|
||||||
subprocess.check_output(move_cmd.split(), stderr=subprocess.STDOUT)
|
subprocess.check_output(move_cmd.split(), stderr=subprocess.STDOUT)
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
raise Exception("Failed to write configuration file: %s" %
|
raise Exception("Failed to write configuration file: %s" %
|
||||||
@@ -156,5 +165,5 @@ class HAProxyDriver(LoadBalancerDriver):
|
|||||||
self._start()
|
self._start()
|
||||||
|
|
||||||
def delete(self):
|
def delete(self):
|
||||||
self._delete_configs()
|
|
||||||
self._stop()
|
self._stop()
|
||||||
|
self._delete_configs()
|
||||||
|
Reference in New Issue
Block a user