daemons: handle arguments correctly and uniformly
authorIustin Pop <iustin@google.com>
Tue, 29 Dec 2009 16:05:23 +0000 (17:05 +0100)
committerIustin Pop <iustin@google.com>
Mon, 4 Jan 2010 09:16:52 +0000 (10:16 +0100)
Of all daemons, only rapi did abort when given argument. None of our
daemons use any arguments, but they accepted them blindly. This is a
very bad experience for the user.

This patch adds checking and exiting in all daemons, in a uniform way.
One other option would have been to add a flag to GenericMain
(noargs=True).

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Olivier Tharan <olive@google.com>

daemons/ganeti-confd
daemons/ganeti-masterd
daemons/ganeti-noded
daemons/ganeti-rapi
daemons/ganeti-watcher

index de12700..27b11a4 100755 (executable)
@@ -329,6 +329,10 @@ def CheckConfd(options, args):
   """Initial checks whether to run exit with a failure.
 
   """
+  if args: # confd doesn't take any arguments
+    print >> sys.stderr, ("Usage: %s [-f] [-d] [-b ADDRESS]" % sys.argv[0])
+    sys.exit(constants.EXIT_FAILURE)
+
   # TODO: collapse HMAC daemons handling in daemons GenericMain, when we'll
   # have more than one.
   if not os.path.isfile(constants.HMAC_CLUSTER_KEY):
index 2951410..81becca 100755 (executable)
@@ -538,6 +538,10 @@ def CheckMasterd(options, args):
   """Initial checks whether to run or exit with a failure.
 
   """
+  if args: # masterd doesn't take any arguments
+    print >> sys.stderr, ("Usage: %s [-f] [-d]" % sys.argv[0])
+    sys.exit(constants.EXIT_FAILURE)
+
   ssconf.CheckMaster(options.debug)
 
   # If CheckMaster didn't fail we believe we are the master, but we have to
index 4e24224..9aa7187 100755 (executable)
@@ -787,6 +787,16 @@ class NodeHttpServer(http.server.HttpServer): # pylint: disable-msg=R0904
     return backend.ValidateHVParams(hvname, hvparams)
 
 
+def CheckNoded(_, args):
+  """Initial checks whether to run or exit with a failure.
+
+  """
+  if args: # noded doesn't take any arguments
+    print >> sys.stderr, ("Usage: %s [-f] [-d] [-p port] [-b ADDRESS]" %
+                          sys.argv[0])
+    sys.exit(constants.EXIT_FAILURE)
+
+
 def ExecNoded(options, args):
   """Main node daemon function, executed with the PID file held.
 
@@ -824,7 +834,7 @@ def main():
   dirs = [(val, constants.RUN_DIRS_MODE) for val in constants.SUB_RUN_DIRS]
   dirs.append((constants.LOG_OS_DIR, 0750))
   dirs.append((constants.LOCK_DIR, 1777))
-  daemon.GenericMain(constants.NODED, parser, dirs, None, ExecNoded)
+  daemon.GenericMain(constants.NODED, parser, dirs, CheckNoded, ExecNoded)
 
 
 if __name__ == '__main__':
index 48816c1..8fd5265 100755 (executable)
@@ -187,9 +187,9 @@ def CheckRapi(options, args):
   """Initial checks whether to run or exit with a failure.
 
   """
-  if len(args) != 0:
-    print >> sys.stderr, "Usage: %s [-f] [-d] [-p port] [-b ADDRESS]" % \
-        sys.argv[0]
+  if args: # rapi doesn't take any arguments
+    print >> sys.stderr, ("Usage: %s [-f] [-d] [-p port] [-b ADDRESS]" %
+                          sys.argv[0])
     sys.exit(constants.EXIT_FAILURE)
 
   ssconf.CheckMaster(options.debug)
index d82b8ba..6c97d40 100755 (executable)
@@ -470,7 +470,11 @@ def main():
   """
   global client # pylint: disable-msg=W0603
 
-  options, _ = ParseOptions()
+  options, args = ParseOptions()
+
+  if args: # watcher doesn't take any arguments
+    print >> sys.stderr, ("Usage: %s [-f] " % sys.argv[0])
+    sys.exit(constants.EXIT_FAILURE)
 
   utils.SetupLogging(constants.LOG_WATCHER, debug=options.debug,
                      stderr_logging=options.debug)