diff options
author | Lucian Petrut <lpetrut@cloudbasesolutions.com> | 2016-09-26 17:58:49 +0300 |
---|---|---|
committer | Lucian Petrut <lpetrut@cloudbasesolutions.com> | 2016-10-05 15:18:18 +0300 |
commit | 62011bca363a49541a5598be63a1e1ec18d57251 (patch) | |
tree | c44cb38564a7714cd8de05687610ec1a5401bfba | |
parent | 5f417f8e9656e097070036daced26d8b0f3728c3 (diff) | |
download | oslo-concurrency-stable/mitaka.tar.gz |
Ignore prlimit argument on Windowsmitaka-eolstable/mitaka
The built in 'resource' module is used in order to apply process
resource limits. This is not available on Windows.
For the moment, we'll ignore this argument and log a warning
message. In the future, we may provide a portable implementation
for this feature.
Change-Id: I6a82916eb68fbf8737b45a65f71cae1f835d12d1
Closes-Bug: #1627766
(cherry picked from commit 9ac99b675eae255b660b03d3a1e61599d09f8316)
-rw-r--r-- | oslo_concurrency/processutils.py | 15 | ||||
-rw-r--r-- | oslo_concurrency/tests/unit/test_processutils.py | 22 |
2 files changed, 32 insertions, 5 deletions
diff --git a/oslo_concurrency/processutils.py b/oslo_concurrency/processutils.py index 1f46221..f3a51c6 100644 --- a/oslo_concurrency/processutils.py +++ b/oslo_concurrency/processutils.py @@ -327,11 +327,16 @@ def execute(*cmd, **kwargs): cmd = [str(c) for c in cmd] if prlimit: - args = [sys.executable, '-m', 'oslo_concurrency.prlimit'] - args.extend(prlimit.prlimit_args()) - args.append('--') - args.extend(cmd) - cmd = args + if os.name == 'nt': + LOG.log(loglevel, + _('Process resource limits are ignored as ' + 'this feature is not supported on Windows.')) + else: + args = [sys.executable, '-m', 'oslo_concurrency.prlimit'] + args.extend(prlimit.prlimit_args()) + args.append('--') + args.extend(cmd) + cmd = args sanitized_cmd = strutils.mask_password(' '.join(cmd)) diff --git a/oslo_concurrency/tests/unit/test_processutils.py b/oslo_concurrency/tests/unit/test_processutils.py index 5c744f5..c058f67 100644 --- a/oslo_concurrency/tests/unit/test_processutils.py +++ b/oslo_concurrency/tests/unit/test_processutils.py @@ -884,3 +884,25 @@ class PrlimitTestCase(test_base.BaseTestCase): self.assertIn(expected, exc.stderr) else: self.fail("ProcessExecutionError not raised") + + @mock.patch.object(os, 'name', 'nt') + @mock.patch.object(processutils.subprocess, "Popen") + def test_prlimit_windows(self, mock_popen): + # We want to ensure that process resource limits are + # ignored on Windows, in which case this feature is not + # supported. We'll just check the command passed to Popen, + # which is expected to be unaltered. + prlimit = self.limit_address_space() + mock_popen.return_value.communicate.return_value = None + + processutils.execute( + *self.SIMPLE_PROGRAM, + prlimit=prlimit, + check_exit_code=False) + + mock_popen.assert_called_once_with( + self.SIMPLE_PROGRAM, + stdin=mock.ANY, stdout=mock.ANY, + stderr=mock.ANY, close_fds=mock.ANY, + preexec_fn=mock.ANY, shell=mock.ANY, + cwd=mock.ANY, env=mock.ANY) |