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)
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()
"""
+import mock
import mox
from oslo.config import cfg
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')