summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Mancy <rmancy@redhat.com>2011-11-11 07:40:39 +1000
committerDan Callaghan <dcallagh@redhat.com>2011-11-11 14:41:34 +1000
commit4b64b12060841a78a561ac0843a99444beac7047 (patch)
treeb2680005490d83f0f30fe446ccc23e249f9e69eb
parentcb409a0d5a9caa42ce12ecd9382a7ce1c609efd3 (diff)
timed handling of session renewal for qpid
-rw-r--r--IntegrationTests/labcontroller-test.cfg3
-rw-r--r--LabController/proxy/labcontroller.conf3
-rw-r--r--LabController/proxy/src/bkr/labcontroller/default.conf3
-rw-r--r--LabController/proxy/src/bkr/labcontroller/main.py33
-rw-r--r--LabController/proxy/src/bkr/labcontroller/proxy.py35
-rw-r--r--LabController/proxy/src/bkr/labcontroller/watchdog.py7
6 files changed, 52 insertions, 32 deletions
diff --git a/IntegrationTests/labcontroller-test.cfg b/IntegrationTests/labcontroller-test.cfg
index 11ec503..c58b310 100644
--- a/IntegrationTests/labcontroller-test.cfg
+++ b/IntegrationTests/labcontroller-test.cfg
@@ -16,8 +16,7 @@ PASSWORD = "testing"
# Set CACHE = True only if you define ARCHIVE_* variables correctly!
CACHE = False
-
-
+RENEW_SESSION_INTERVAL= 10
LOG_MAXBYTES = 2150
LOG_BACKUPCOUNT=5
diff --git a/LabController/proxy/labcontroller.conf b/LabController/proxy/labcontroller.conf
index d821b5b..f1d5ca7 100644
--- a/LabController/proxy/labcontroller.conf
+++ b/LabController/proxy/labcontroller.conf
@@ -28,6 +28,9 @@ ARCHIVE_BASEPATH = "/var/www/html/beaker"
ARCHIVE_RSYNC = "rsync://USER@HOST/var/www/html/beaker"
RSYNC_FLAGS = "-ar --password-file /root/rsync-secret.txt"
+# How often to renew our session on the server
+#RENEW_SESSION_INTERVAL = 300
+
# Set to True if you wish to enable QPID support for beaker
# Please be aware that qpid libraries will need to be installed
# and the beaker server must be using QPID as well.
diff --git a/LabController/proxy/src/bkr/labcontroller/default.conf b/LabController/proxy/src/bkr/labcontroller/default.conf
index cfa779c..3c90e91 100644
--- a/LabController/proxy/src/bkr/labcontroller/default.conf
+++ b/LabController/proxy/src/bkr/labcontroller/default.conf
@@ -13,6 +13,9 @@ QPID_BUS_LOG_FILE = "/var/log/beaker/bus.log"
# How long to sleep between polls.
SLEEP_TIME = 20
+# How often to renew our session on the server
+RENEW_SESSION_INTERVAL = 300
+
# Location of system console logs
CONSOLE_LOGS = "/var/consoles"
diff --git a/LabController/proxy/src/bkr/labcontroller/main.py b/LabController/proxy/src/bkr/labcontroller/main.py
index 064e7d7..fc8ac1c 100644
--- a/LabController/proxy/src/bkr/labcontroller/main.py
+++ b/LabController/proxy/src/bkr/labcontroller/main.py
@@ -12,7 +12,7 @@ import SocketServer
import DocXMLRPCServer
import socket
-from bkr.labcontroller.proxy import Proxy
+from bkr.labcontroller.proxy import Proxy, RepeatTimer
from bkr.labcontroller.config import get_conf
from bkr.labcontroller.utils import add_rotating_file_logger
from kobo.exceptions import ShutdownException
@@ -24,33 +24,6 @@ logger = logging.getLogger(__name__)
set_except_hook()
-
-class Authenticate(Thread):
- def __init__ (self,proxy):
- Thread.__init__(self)
- self.proxy = proxy
- self.__serving = False
-
- def run(self):
- self.__serving = True
- time_of_last_check = 0
- while self.__serving:
- # every minute check that we are logged in.
- now = time.time()
- if now - time_of_last_check > 60:
- time_of_last_check = now
- try:
- self.proxy.hub._login(verbose=self.proxy.hub._conf.get("DEBUG_XMLRPC"))
- except KeyboardInterrupt:
- raise
- except Exception, e:
- logger.exception("Authenticate: Failed to login")
- time.sleep(1)
-
- def stop(self):
- """Stops the thread"""
- self.__serving = False
-
class XMLRPCRequestHandler(DocXMLRPCServer.DocXMLRPCRequestHandler):
rpc_paths = ('/', '/RPC2', '/server')
@@ -103,7 +76,9 @@ def main_loop(conf=None, foreground=False):
sys.stderr.write("Error initializing Proxy: %s\n" % ex)
sys.exit(1)
- login = Authenticate(proxy)
+ login = RepeatTimer(conf['RENEW_SESSION_INTERVAL'], proxy.hub._login,
+ stop_on_exception=False)
+ login.daemon = True
login.start()
server = ForkingXMLRPCServer(("", 8000))
server.register_instance(proxy)
diff --git a/LabController/proxy/src/bkr/labcontroller/proxy.py b/LabController/proxy/src/bkr/labcontroller/proxy.py
index 39e91f7..a353214 100644
--- a/LabController/proxy/src/bkr/labcontroller/proxy.py
+++ b/LabController/proxy/src/bkr/labcontroller/proxy.py
@@ -14,6 +14,7 @@ import tempfile
import xmlrpclib
from cStringIO import StringIO
from socket import gethostname
+from threading import Thread, Event
import kobo.conf
from kobo.client import HubProxy
@@ -618,3 +619,37 @@ class Proxy(ProxyHelper):
distros from the Scheduler/Inventory server.
"""
return self.hub.labcontrollers.removeDistro(distro)
+
+
+class RepeatTimer(Thread):
+
+ def __init__(self, interval, function, stop_on_exception=True, args=[], kwargs={}):
+ Thread.__init__(self)
+ self.interval = interval
+ self.function = function
+ self.args = args
+ self.kwargs = kwargs
+ self.stop_on_exception = stop_on_exception
+ self.finished = Event()
+
+ def stop(self):
+ self.done = True
+ self.finished.set()
+
+ def run(self):
+ self.done = False
+ while True:
+ self.finished.wait(self.interval)
+ if self.done:
+ self.finished.clear()
+ break
+ if not self.finished.is_set():
+ try:
+ self.function(*self.args, **self.kwargs)
+ except Exception, e:
+ # Log it so we don't lose it
+ logger.exception()
+ if self.stop_on_exception:
+ self.finished.clear()
+ raise
+ self.finished.clear()
diff --git a/LabController/proxy/src/bkr/labcontroller/watchdog.py b/LabController/proxy/src/bkr/labcontroller/watchdog.py
index e95ea79..9f171ba 100644
--- a/LabController/proxy/src/bkr/labcontroller/watchdog.py
+++ b/LabController/proxy/src/bkr/labcontroller/watchdog.py
@@ -8,7 +8,7 @@ import socket
import xmlrpclib
from optparse import OptionParser
-from bkr.labcontroller.proxy import Watchdog
+from bkr.labcontroller.proxy import Watchdog, RepeatTimer
from bkr.labcontroller.config import get_conf
from kobo.exceptions import ShutdownException
@@ -58,6 +58,10 @@ def main_loop(conf=None, foreground=False):
"""
if conf['QPID_BUS']:
watchdog.hub._login()
+ auth_renew = RepeatTimer(conf['RENEW_SESSION_INTERVAL'],
+ watchdog.hub._login, stop_on_exception=False)
+ auth_renew.daemon = True
+ auth_renew.start()
lbb = LabBeakerBus(watchdog=watchdog)
active_watchdogs = lbb.rpc.recipes.tasks.watchdogs('active', lbb.lc)
watchdog.active_watchdogs(active_watchdogs, purge=False)
@@ -72,6 +76,7 @@ def main_loop(conf=None, foreground=False):
watchdog.sleep()
except (ShutdownException, KeyboardInterrupt):
# ignore keyboard interrupts and sigterm
+ auth_renew.stop()
signal.signal(signal.SIGINT, signal.SIG_IGN)
signal.signal(signal.SIGTERM, signal.SIG_IGN)
logger.info('Exiting...')