def test_get_keepalivedlvs_pid(self, mock_path): fake_path = '/fake/path' mock_path.return_value = [fake_path] self.useFixture(test_utils.OpenFixture(fake_path, ' space data ')).mock_open result = util.get_keepalivedlvs_pid(self.listener_id) self.assertEqual(' space data', result)
def test_get_keepalivedlvs_pid(self, mock_path): fake_path = '/fake/path' mock_path.return_value = [fake_path] self.useFixture(test_utils.OpenFixture( fake_path, ' space data ')).mock_open result = util.get_keepalivedlvs_pid(self.listener_id) self.assertEqual(' space data', result)
def _check_udp_listener_status(self, listener_id): if os.path.exists(util.keepalived_lvs_pids_path(listener_id)[0]): if os.path.exists(os.path.join( '/proc', util.get_keepalivedlvs_pid(listener_id))): # Check if the listener is disabled with open(util.keepalived_lvs_cfg_path(listener_id), 'r') as file: cfg = file.read() m = re.search('virtual_server', cfg) if m: return consts.ACTIVE return consts.OFFLINE return consts.ERROR return consts.OFFLINE
def delete_lvs_listener(self, listener_id): try: self._check_lvs_listener_exists(listener_id) except exceptions.HTTPException: return webob.Response(json={'message': 'OK'}) # check if that keepalived is still running and if stop it keepalived_pid, vrrp_pid, check_pid = util.keepalived_lvs_pids_path( listener_id) if os.path.exists(keepalived_pid) and os.path.exists( os.path.join('/proc', util.get_keepalivedlvs_pid(listener_id))): cmd = ("/usr/sbin/service " "octavia-keepalivedlvs-{0} stop".format(listener_id)) try: subprocess.check_output(cmd.split(), stderr=subprocess.STDOUT) except subprocess.CalledProcessError as e: LOG.error("Failed to stop keepalivedlvs service: %s", str(e)) return webob.Response(json=dict( message="Error stopping keepalivedlvs", details=e.output), status=500) # Since the lvs check script based on the keepalived pid file for # checking whether it is alived. So here, we had stop the keepalived # process by the previous step, must make sure the pid files are not # exist. if (os.path.exists(keepalived_pid) or os.path.exists(vrrp_pid) or os.path.exists(check_pid)): for pid in [keepalived_pid, vrrp_pid, check_pid]: os.remove(pid) # disable the service init_system = util.get_os_init_system() init_path = util.keepalived_lvs_init_path(init_system, listener_id) if init_system == consts.INIT_SYSTEMD: util.run_systemctl_command( consts.DISABLE, "octavia-keepalivedlvs-%s" % str(listener_id)) elif init_system == consts.INIT_SYSVINIT: init_disable_cmd = "insserv -r {file}".format(file=init_path) elif init_system != consts.INIT_UPSTART: raise util.UnknownInitError() if init_system == consts.INIT_SYSVINIT: try: subprocess.check_output(init_disable_cmd.split(), stderr=subprocess.STDOUT) except subprocess.CalledProcessError as e: LOG.error( "Failed to disable " "octavia-keepalivedlvs-%(list)s service: " "%(err)s", { 'list': listener_id, 'err': str(e) }) return webob.Response(json=dict( message=("Error disabling octavia-keepalivedlvs-" "{0} service".format(listener_id)), details=e.output), status=500) # delete init script ,config file and log file for that listener if os.path.exists(init_path): os.remove(init_path) if os.path.exists(util.keepalived_lvs_cfg_path(listener_id)): os.remove(util.keepalived_lvs_cfg_path(listener_id)) return webob.Response(json={'message': 'OK'})
def delete_udp_listener(self, listener_id): try: self._check_udp_listener_exists(listener_id) except exceptions.HTTPException: return webob.Response(json={'message': 'OK'}) # check if that keepalived is still running and if stop it keepalived_pid, vrrp_pid, check_pid = util.keepalived_lvs_pids_path( listener_id) if os.path.exists(keepalived_pid) and os.path.exists( os.path.join('/proc', util.get_keepalivedlvs_pid(listener_id))): cmd = ("/usr/sbin/service " "octavia-keepalivedlvs-{0} stop".format(listener_id)) try: subprocess.check_output(cmd.split(), stderr=subprocess.STDOUT) except subprocess.CalledProcessError as e: LOG.error("Failed to stop keepalivedlvs service: %s", e) return webob.Response(json=dict( message="Error stopping keepalivedlvs", details=e.output), status=500) # Since the lvs check script based on the keepalived pid file for # checking whether it is alived. So here, we had stop the keepalived # process by the previous step, must make sure the pid files are not # exist. if (os.path.exists(keepalived_pid) or os.path.exists(vrrp_pid) or os.path.exists(check_pid)): for pid in [keepalived_pid, vrrp_pid, check_pid]: os.remove(pid) # disable the service init_system = util.get_os_init_system() init_path = util.keepalived_lvs_init_path(init_system, listener_id) if init_system == consts.INIT_SYSTEMD: util.run_systemctl_command( consts.DISABLE, "octavia-keepalivedlvs-%s" % str(listener_id)) elif init_system == consts.INIT_SYSVINIT: init_disable_cmd = "insserv -r {file}".format(file=init_path) elif init_system != consts.INIT_UPSTART: raise util.UnknownInitError() if init_system == consts.INIT_SYSVINIT: try: subprocess.check_output(init_disable_cmd.split(), stderr=subprocess.STDOUT) except subprocess.CalledProcessError as e: LOG.error("Failed to disable " "octavia-keepalivedlvs-%(list)s service: " "%(err)s", {'list': listener_id, 'err': e}) return webob.Response(json=dict( message=( "Error disabling octavia-keepalivedlvs-" "{0} service".format(listener_id)), details=e.output), status=500) # delete init script ,config file and log file for that listener if os.path.exists(init_path): os.remove(init_path) if os.path.exists(util.keepalived_lvs_cfg_path(listener_id)): os.remove(util.keepalived_lvs_cfg_path(listener_id)) return webob.Response(json={'message': 'OK'})