From c17c73b3d0f07046c677711853e1b93768526e47 Mon Sep 17 00:00:00 2001 From: Brian Lamar Date: Tue, 21 Jun 2011 00:21:33 -0400 Subject: [PATCH] Tests for WSGI/Launcher --- bin/nova-api | 4 ++-- nova/service.py | 4 +--- nova/tests/test_service.py | 30 ++++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/bin/nova-api b/bin/nova-api index 563d7c09058a..20ad4bfa5a4a 100755 --- a/bin/nova-api +++ b/bin/nova-api @@ -38,12 +38,12 @@ def main(): launcher = nova.service.Launcher(sys.argv) launcher.launch_service(ec2) launcher.launch_service(osapi) - + try: launcher.wait() except KeyboardInterrupt: launcher.stop() - + if __name__ == '__main__': sys.exit(main()) diff --git a/nova/service.py b/nova/service.py index d896de1fe768..08071e80c4c1 100644 --- a/nova/service.py +++ b/nova/service.py @@ -69,9 +69,8 @@ class Launcher(object): self._version = version.version_string_with_vcs() logging.setup() logging.audit(_("Nova Version (%(_version)s)") % self.__dict__) - FLAGS(_flags) utils.default_flagfile() - + FLAGS(_flags or []) @staticmethod def run_service(service): @@ -120,7 +119,6 @@ class Launcher(object): logging.info("Process exited with %d" % service.exitcode) - class Service(object): """Base class for workers that run on hosts.""" diff --git a/nova/tests/test_service.py b/nova/tests/test_service.py index d1cc8bd61a1a..70ef80147617 100644 --- a/nova/tests/test_service.py +++ b/nova/tests/test_service.py @@ -21,6 +21,7 @@ Unit Tests for remote procedure calls using queue """ import mox +import unittest2 as unittest from nova import context from nova import db @@ -30,6 +31,7 @@ from nova import rpc from nova import test from nova import service from nova import manager +from nova import wsgi from nova.compute import manager as compute_manager FLAGS = flags.FLAGS @@ -349,3 +351,31 @@ class ServiceTestCase(test.TestCase): serv.stop() db.service_destroy(ctxt, service_ref['id']) + + +class TestWSGIService(test.TestCase): + + def setUp(self): + super(TestWSGIService, self).setUp() + self.stubs.Set(wsgi.Loader, "load_app", mox.MockAnything()) + + def test_service_random_port(self): + test_service = service.WSGIService("test_service") + self.assertEquals(0, test_service.port) + test_service.start() + self.assertNotEqual(0, test_service.port) + test_service.stop() + +class TestLauncher(test.TestCase): + + def setUp(self): + super(TestLauncher, self).setUp() + self.stubs.Set(wsgi.Loader, "load_app", mox.MockAnything()) + self.service = service.WSGIService("test_service") + + def test_launch_app(self): + self.assertEquals(0, self.service.port) + launcher = service.Launcher() + launcher.launch_service(self.service) + self.assertEquals(0, self.service.port) + launcher.stop()