From 7171984aab11cb28af92435bfea264d7faf643fd Mon Sep 17 00:00:00 2001 From: Lucian Petrut Date: Fri, 7 Mar 2014 17:09:33 +0200 Subject: [PATCH] Fixes cinder-volume service startup on Windows The Windows service fails due to missing non-blocking IO features in eventlet. This fix adds a conditional path on Windows to execute the service accordingly. This bug had already been fixed by this this commit: https://review.openstack.org/#/c/44744/ but it had been reverted here, causing the Windows service to fail again https://review.openstack.org/67031 Fixes bug: #1219896 Change-Id: I46c6b332e614b6a84ec8372dbec3ee9fb09336de --- bin/cinder-volume | 5 +---- cinder/service.py | 17 +++++++++++++++++ cinder/tests/test_service.py | 25 +++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 4 deletions(-) mode change 100644 => 100755 cinder/service.py mode change 100644 => 100755 cinder/tests/test_service.py diff --git a/bin/cinder-volume b/bin/cinder-volume index e9af49cf3..9a0999439 100755 --- a/bin/cinder-volume +++ b/bin/cinder-volume @@ -59,10 +59,7 @@ if __name__ == '__main__': version=version.version_string()) logging.setup("cinder") utils.monkey_patch() - # Note(zhiteng): Since Windows (os='nt') has already ignored monkey - # patching 'os' module, there is no need to treat it differently - # when creating launcher. - launcher = service.process_launcher() + launcher = service.get_launcher() if CONF.enabled_backends: for backend in CONF.enabled_backends: host = "%s@%s" % (CONF.host, backend) diff --git a/cinder/service.py b/cinder/service.py old mode 100644 new mode 100755 index 1091729cc..763ad47eb --- a/cinder/service.py +++ b/cinder/service.py @@ -389,3 +389,20 @@ def wait(): except KeyboardInterrupt: _launcher.stop() rpc.cleanup() + + +class Launcher(object): + def __init__(self): + self.launch_service = serve + self.wait = wait + + +def get_launcher(): + # Note(lpetrut): ProcessLauncher uses green pipes which fail on Windows + # due to missing support of non-blocking I/O pipes. For this reason, the + # service must be spawned differently on Windows, using the ServiceLauncher + # class instead. + if os.name == 'nt': + return Launcher() + else: + return process_launcher() diff --git a/cinder/tests/test_service.py b/cinder/tests/test_service.py old mode 100644 new mode 100755 index 0f34a5232..9ed0c1675 --- a/cinder/tests/test_service.py +++ b/cinder/tests/test_service.py @@ -20,6 +20,7 @@ Unit Tests for remote procedure calls using queue """ +import mock import mox from oslo.config import cfg @@ -215,3 +216,27 @@ class TestWSGIService(test.TestCase): test_service.start() self.assertNotEqual(0, test_service.port) test_service.stop() + + +class OSCompatibilityTestCase(test.TestCase): + def _test_service_launcher(self, fake_os): + # Note(lpetrut): The cinder-volume service needs to be spawned + # differently on Windows due to an eventlet bug. For this reason, + # we must check the process launcher used. + fake_process_launcher = mock.MagicMock() + with mock.patch('os.name', fake_os): + with mock.patch('cinder.service.process_launcher', + fake_process_launcher): + launcher = service.get_launcher() + if fake_os == 'nt': + self.assertEqual(type(launcher), + service.Launcher) + else: + self.assertEqual(launcher, + fake_process_launcher()) + + def test_process_launcher_on_windows(self): + self._test_service_launcher('nt') + + def test_process_launcher_on_linux(self): + self._test_service_launcher('posix') -- 2.45.2