PrivContext: Sets client_mode to False on Windows
oslo.privsep is not currently supported on Windows, as it uses Linux-specific functionality (os.fork, socker.AF_UNIX). The client_mode should be set to False on Windows. Change-Id: I545caa5528e629da477615f7e14d10602ad96abd Closes-Bug: #1591122
This commit is contained in:
parent
be46f78fc3
commit
ecabeaff2f
|
@ -16,13 +16,14 @@
|
|||
import enum
|
||||
import functools
|
||||
import logging
|
||||
import sys
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_config import types
|
||||
|
||||
from oslo_privsep import capabilities
|
||||
from oslo_privsep import daemon
|
||||
from oslo_privsep._i18n import _, _LW
|
||||
from oslo_privsep._i18n import _, _LW, _LE
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
@ -81,7 +82,11 @@ class PrivContext(object):
|
|||
self.pypath = pypath
|
||||
self.prefix = prefix
|
||||
self.cfg_section = cfg_section
|
||||
self.client_mode = True
|
||||
|
||||
# NOTE(claudiub): oslo.privsep is not currently supported on Windows,
|
||||
# as it uses Linux-specific functionality (os.fork, socker.AF_UNIX).
|
||||
# The client_mode should be set to False on Windows.
|
||||
self.client_mode = sys.platform != 'win32'
|
||||
self.channel = None
|
||||
|
||||
cfg.CONF.register_opts(OPTS, group=cfg_section)
|
||||
|
@ -99,6 +104,10 @@ class PrivContext(object):
|
|||
return 'PrivContext(cfg_section=%s)' % self.cfg_section
|
||||
|
||||
def set_client_mode(self, enabled):
|
||||
if enabled and sys.platform == 'win32':
|
||||
raise RuntimeError(
|
||||
_LE("Enabling the client_mode is not currently "
|
||||
"supported on Windows."))
|
||||
self.client_mode = enabled
|
||||
|
||||
def entrypoint(self, func):
|
||||
|
|
|
@ -19,6 +19,7 @@ import pipes
|
|||
import platform
|
||||
import sys
|
||||
|
||||
import mock
|
||||
import testtools
|
||||
|
||||
from oslo_privsep import daemon
|
||||
|
@ -56,6 +57,30 @@ def fail(custom=False):
|
|||
raise RuntimeError("I can't let you do that Dave")
|
||||
|
||||
|
||||
@testtools.skipIf(platform.system() != 'Linux',
|
||||
'works only on Linux platform.')
|
||||
class TestPrivContext(testctx.TestContextTestCase):
|
||||
|
||||
@mock.patch.object(priv_context, 'sys')
|
||||
def test_init_windows(self, mock_sys):
|
||||
mock_sys.platform = 'win32'
|
||||
|
||||
context = priv_context.PrivContext('test', capabilities=[])
|
||||
self.assertFalse(context.client_mode)
|
||||
|
||||
@mock.patch.object(priv_context, 'sys')
|
||||
def test_set_client_mode(self, mock_sys):
|
||||
context = priv_context.PrivContext('test', capabilities=[])
|
||||
self.assertTrue(context.client_mode)
|
||||
|
||||
context.set_client_mode(False)
|
||||
self.assertFalse(context.client_mode)
|
||||
|
||||
# client_mode should remain to False on win32.
|
||||
mock_sys.platform = 'win32'
|
||||
self.assertRaises(RuntimeError, context.set_client_mode, True)
|
||||
|
||||
|
||||
@testtools.skipIf(platform.system() != 'Linux',
|
||||
'works only on Linux platform.')
|
||||
class TestSeparation(testctx.TestContextTestCase):
|
||||
|
|
Loading…
Reference in New Issue