Commit 7f4072b6 authored by Nicolas Wavrant's avatar Nicolas Wavrant

equeue: do not create lists for options expecting a single value

to simplify the code
parent a57c27c9
...@@ -93,10 +93,10 @@ class EqueueServer(socketserver.ThreadingUnixStreamServer): ...@@ -93,10 +93,10 @@ class EqueueServer(socketserver.ThreadingUnixStreamServer):
RequestHandlerClass=None, RequestHandlerClass=None,
*args, **kw) *args, **kw)
# Equeue Specific elements # Equeue Specific elements
self.setLogger(self.options.logfile[0], self.options.loglevel[0]) self.setLogger(self.options.logfile, self.options.loglevel)
self.setDB(self.options.database[0]) self.setDB(self.options.database)
if getattr(self.options, 'takeover_triggered_file_path', None): if getattr(self.options, 'takeover_triggered_file_path', None):
self.takeover_triggered_file_path = self.options.takeover_triggered_file_path[0] self.takeover_triggered_file_path = self.options.takeover_triggered_file_path
# Lock to only have one command running at the time # Lock to only have one command running at the time
self.thread_lock = threading.Lock() self.thread_lock = threading.Lock()
# Lockfile is used by other commands to know if an import is ongoing. # Lockfile is used by other commands to know if an import is ongoing.
...@@ -197,20 +197,20 @@ def remove_existing_file(path): ...@@ -197,20 +197,20 @@ def remove_existing_file(path):
def main(): def main():
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description="Run a single threaded execution queue.") description="Run a single threaded execution queue.")
parser.add_argument('--database', nargs=1, required=True, parser.add_argument('--database', required=True,
help="Path to the database where the last " help="Path to the database where the last "
"calls are stored") "calls are stored")
parser.add_argument('--loglevel', nargs=1, parser.add_argument('--loglevel',
default='INFO', default='INFO',
choices=logging_choices, choices=logging_choices,
required=False) required=False)
parser.add_argument('-l', '--logfile', nargs=1, required=True, parser.add_argument('-l', '--logfile', required=True,
help="Path to the log file.") help="Path to the log file.")
parser.add_argument('-t', '--timeout', nargs=1, required=False, parser.add_argument('-t', '--timeout', required=False,
dest='timeout', type=int, default=3) dest='timeout', type=int, default=3)
parser.add_argument('--lockfile', parser.add_argument('--lockfile',
help="Path to the lock file created when a command is run") help="Path to the lock file created when a command is run")
parser.add_argument('--takeover-triggered-file-path', nargs=1, required=False, parser.add_argument('--takeover-triggered-file-path', required=False,
help="Path to the file created by takeover script to state that it has been triggered.") help="Path to the file created by takeover script to state that it has been triggered.")
parser.add_argument('socket', help="Path to the unix socket") parser.add_argument('socket', help="Path to the unix socket")
......
...@@ -10,10 +10,10 @@ from slapos.equeue import EqueueServer ...@@ -10,10 +10,10 @@ from slapos.equeue import EqueueServer
class Options: class Options:
def __init__(self, logfile, loglevel, database, takeover_triggered_file_path, lockfile, timeout): def __init__(self, logfile, loglevel, database, takeover_triggered_file_path, lockfile, timeout):
self.logfile = [logfile] self.logfile = logfile
self.loglevel = [loglevel] self.loglevel = loglevel
self.database = [database] self.database = database
self.takeover_triggered_file_path = [takeover_triggered_file_path] self.takeover_triggered_file_path = takeover_triggered_file_path
self.lockfile = lockfile self.lockfile = lockfile
self.timeout = timeout self.timeout = timeout
...@@ -59,7 +59,7 @@ class TestEqueue(unittest.TestCase): ...@@ -59,7 +59,7 @@ class TestEqueue(unittest.TestCase):
server_process = multiprocessing.Process(target=self.equeue_server.serve_forever) server_process = multiprocessing.Process(target=self.equeue_server.serve_forever)
server_process.start() server_process.start()
self.assertTrue(os.path.exists(self.options.database[0])) self.assertTrue(os.path.exists(self.options.database))
self.assertTrue(os.path.exists(self.socket)) self.assertTrue(os.path.exists(self.socket))
# Prepare 2 requests, the first one including a delay. # Prepare 2 requests, the first one including a delay.
...@@ -95,7 +95,7 @@ class TestEqueue(unittest.TestCase): ...@@ -95,7 +95,7 @@ class TestEqueue(unittest.TestCase):
server_process = multiprocessing.Process(target=self.equeue_server.serve_forever) server_process = multiprocessing.Process(target=self.equeue_server.serve_forever)
server_process.start() server_process.start()
self.assertTrue(os.path.exists(self.options.database[0])) self.assertTrue(os.path.exists(self.options.database))
self.assertTrue(os.path.exists(self.socket)) self.assertTrue(os.path.exists(self.socket))
# Run 2 times the same command (bash), but with different # Run 2 times the same command (bash), but with different
...@@ -130,7 +130,7 @@ class TestEqueue(unittest.TestCase): ...@@ -130,7 +130,7 @@ class TestEqueue(unittest.TestCase):
server_process = multiprocessing.Process(target=self.equeue_server.serve_forever) server_process = multiprocessing.Process(target=self.equeue_server.serve_forever)
server_process.start() server_process.start()
self.assertTrue(os.path.exists(self.options.database[0])) self.assertTrue(os.path.exists(self.options.database))
self.assertTrue(os.path.exists(self.socket)) self.assertTrue(os.path.exists(self.socket))
# Create takeover file # Create takeover file
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment