summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Smith <code@term.ie>2010-10-15 19:27:39 +0900
committerAndy Smith <code@term.ie>2010-10-15 19:27:39 +0900
commit8b2d1143f53bb029941a770e2611bb58a064c492 (patch)
treec0a80e4d3a40a443dbf0bbb03a991f94ac0a8393
parent38a4e415ef7e903e3c63bd584df8e4fee0163512 (diff)
make --help work for twistd-based services
-rw-r--r--nova/tests/twistd_unittest.py53
-rw-r--r--nova/twistd.py6
-rw-r--r--run_tests.py1
3 files changed, 60 insertions, 0 deletions
diff --git a/nova/tests/twistd_unittest.py b/nova/tests/twistd_unittest.py
new file mode 100644
index 000000000..75007b9c8
--- /dev/null
+++ b/nova/tests/twistd_unittest.py
@@ -0,0 +1,53 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright 2010 United States Government as represented by the
+# Administrator of the National Aeronautics and Space Administration.
+# All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+import StringIO
+import sys
+
+from nova import twistd
+from nova import exception
+from nova import flags
+from nova import test
+
+
+FLAGS = flags.FLAGS
+
+
+class TwistdTestCase(test.TrialTestCase):
+ def setUp(self):
+ super(TwistdTestCase, self).setUp()
+ self.Options = twistd.WrapTwistedOptions(twistd.TwistdServerOptions)
+ sys.stdout = StringIO.StringIO()
+
+ def tearDown(self):
+ super(TwistdTestCase, self).tearDown()
+ sys.stdout = sys.__stdout__
+
+ def test_basic(self):
+ options = self.Options()
+ argv = options.parseOptions()
+
+ def test_logfile(self):
+ options = self.Options()
+ argv = options.parseOptions(['--logfile=foo'])
+ self.assertEqual(FLAGS.logfile, 'foo')
+
+ def test_help(self):
+ options = self.Options()
+ self.assertRaises(SystemExit, options.parseOptions, ['--help'])
+ self.assert_('pidfile' in sys.stdout.getvalue())
diff --git a/nova/twistd.py b/nova/twistd.py
index 9511c231c..df75b603e 100644
--- a/nova/twistd.py
+++ b/nova/twistd.py
@@ -51,6 +51,8 @@ class TwistdServerOptions(ServerOptions):
class FlagParser(object):
+ # this is a required attribute for gflags
+ syntactic_help = ''
def __init__(self, parser):
self.parser = parser
@@ -81,6 +83,8 @@ def WrapTwistedOptions(wrapped):
reflect.accumulateClassList(self.__class__, 'optFlags', twistd_flags)
for flag in twistd_flags:
key = flag[0].replace('-', '_')
+ if hasattr(FLAGS, key):
+ continue
flags.DEFINE_boolean(key, None, str(flag[-1]))
def _absorbParameters(self):
@@ -88,6 +92,8 @@ def WrapTwistedOptions(wrapped):
reflect.accumulateClassList(self.__class__, 'optParameters', twistd_params)
for param in twistd_params:
key = param[0].replace('-', '_')
+ if hasattr(FLAGS, key):
+ continue
if len(param) > 4:
flags.DEFINE(FlagParser(param[4]),
key, param[2], str(param[3]),
diff --git a/run_tests.py b/run_tests.py
index 0b27ec6cf..225dcac17 100644
--- a/run_tests.py
+++ b/run_tests.py
@@ -62,6 +62,7 @@ from nova.tests.quota_unittest import *
from nova.tests.rpc_unittest import *
from nova.tests.scheduler_unittest import *
from nova.tests.service_unittest import *
+from nova.tests.twistd_unittest import *
from nova.tests.validator_unittest import *
from nova.tests.virt_unittest import *
from nova.tests.volume_unittest import *