Merge "Use sys.executable instead of 'python'"

This commit is contained in:
Zuul 2020-02-12 14:45:19 +00:00 committed by Gerrit Code Review
commit a026b39617
5 changed files with 26 additions and 19 deletions

View File

@ -170,7 +170,7 @@ class Daemon(object):
Usage: subclass the Daemon class and override the run() method
"""
def __init__(self, pidfile, stdin=DEVNULL, stdout=DEVNULL,
stderr=DEVNULL, procname='python', uuid=None,
stderr=DEVNULL, procname=sys.executable, uuid=None,
user=None, group=None):
"""Note: pidfile may be None."""
self.stdin = stdin

View File

@ -13,6 +13,7 @@
# under the License.
import os
import sys
from oslo_config import cfg
from six import moves
@ -48,7 +49,7 @@ class BaseTestProcessMonitor(base.BaseLoggingTestCase):
def _make_cmdline_callback(self, uuid):
def _cmdline_callback(pidfile):
cmdline = ["python", simple_daemon.__file__,
cmdline = [sys.executable, simple_daemon.__file__,
"--uuid=%s" % uuid,
"--pid_file=%s" % pidfile]
return cmdline

View File

@ -14,6 +14,7 @@
# under the License.
import os
import sys
import eventlet
import mock
@ -110,19 +111,20 @@ class NetnsCleanupTest(base.BaseSudoTestCase):
to test the cleanup functionality which will issue a SIGKILL
to all remaining processes after the SIGTERM attempt
"""
commands = [['python', process_spawn.__file__,
python_exec = os.path.basename(sys.executable)
commands = [[python_exec, process_spawn.__file__,
'-n', NUM_SUBPROCESSES,
'-f', n_const.IPv4,
'-p', n_const.PROTO_NAME_TCP,
'--noignore_sigterm',
'--parent_listen'],
['python', process_spawn.__file__,
[python_exec, process_spawn.__file__,
'-n', NUM_SUBPROCESSES,
'-f', process_spawn.UNIX_FAMILY,
'-p', n_const.PROTO_NAME_TCP,
'--noignore_sigterm',
'--noparent_listen'],
['python', process_spawn.__file__,
[python_exec, process_spawn.__file__,
'-n', NUM_SUBPROCESSES,
'-f', n_const.IPv4,
'-p', n_const.PROTO_NAME_UDP,

View File

@ -13,6 +13,7 @@
# under the License.
import signal
import sys
import eventlet.event
from eventlet.green import subprocess
@ -319,7 +320,7 @@ class TestFailingAsyncProcess(base.BaseTestCase):
def setUp(self):
super(TestFailingAsyncProcess, self).setUp()
path = self.get_temp_file_path('async.tmp', self.get_new_temp_dir())
self.process = async_process.AsyncProcess(['python3',
self.process = async_process.AsyncProcess([sys.executable,
failing_process.__file__,
path],
respawn_interval=0)

View File

@ -153,7 +153,7 @@ class TestPidfile(base.BaseTestCase):
self.os.O_CREAT = os.O_CREAT
self.os.O_RDWR = os.O_RDWR
daemon.Pidfile('thefile', 'python')
daemon.Pidfile('thefile', sys.executable)
self.os.open.assert_called_once_with('thefile', os.O_CREAT | os.O_RDWR)
self.fcntl.flock.assert_called_once_with(FAKE_FD, self.fcntl.LOCK_EX |
self.fcntl.LOCK_NB)
@ -163,14 +163,14 @@ class TestPidfile(base.BaseTestCase):
with mock.patch.object(daemon.sys, 'stderr'):
with testtools.ExpectedException(SystemExit):
daemon.Pidfile('thefile', 'python')
daemon.Pidfile('thefile', sys.executable)
sys.assert_has_calls([
mock.call.stderr.write(mock.ANY),
mock.call.exit(1)]
)
def test_unlock(self):
p = daemon.Pidfile('thefile', 'python')
p = daemon.Pidfile('thefile', sys.executable)
p.unlock()
self.fcntl.flock.assert_has_calls([
mock.call(FAKE_FD, self.fcntl.LOCK_EX | self.fcntl.LOCK_NB),
@ -178,7 +178,7 @@ class TestPidfile(base.BaseTestCase):
)
def test_write(self):
p = daemon.Pidfile('thefile', 'python')
p = daemon.Pidfile('thefile', sys.executable)
p.write(34)
self.os.assert_has_calls([
@ -189,13 +189,14 @@ class TestPidfile(base.BaseTestCase):
def test_read(self):
self.os.read.return_value = '34'
p = daemon.Pidfile('thefile', 'python')
p = daemon.Pidfile('thefile', sys.executable)
self.assertEqual(34, p.read())
def test_is_running(self):
mock_open = self.useFixture(
lib_fixtures.OpenFixture('/proc/34/cmdline', 'python')).mock_open
p = daemon.Pidfile('thefile', 'python')
lib_fixtures.OpenFixture('/proc/34/cmdline',
sys.executable)).mock_open
p = daemon.Pidfile('thefile', sys.executable)
with mock.patch.object(p, 'read') as read:
read.return_value = 34
@ -206,8 +207,9 @@ class TestPidfile(base.BaseTestCase):
def test_is_running_uuid_true(self):
mock_open = self.useFixture(
lib_fixtures.OpenFixture(
'/proc/34/cmdline', 'python 1234')).mock_open
p = daemon.Pidfile('thefile', 'python', uuid='1234')
'/proc/34/cmdline', '{} 1234'.format(
sys.executable))).mock_open
p = daemon.Pidfile('thefile', sys.executable, uuid='1234')
with mock.patch.object(p, 'read') as read:
read.return_value = 34
@ -218,8 +220,9 @@ class TestPidfile(base.BaseTestCase):
def test_is_running_uuid_false(self):
mock_open = self.useFixture(
lib_fixtures.OpenFixture(
'/proc/34/cmdline', 'python 1234')).mock_open
p = daemon.Pidfile('thefile', 'python', uuid='6789')
'/proc/34/cmdline', '{} 1234'.format(
sys.executable))).mock_open
p = daemon.Pidfile('thefile', sys.executable, uuid='6789')
with mock.patch.object(p, 'read') as read:
read.return_value = 34
@ -239,11 +242,11 @@ class TestDaemon(base.BaseTestCase):
def test_init(self):
d = daemon.Daemon('pidfile')
self.assertEqual(d.procname, 'python')
self.assertEqual(d.procname, sys.executable)
def test_init_nopidfile(self):
d = daemon.Daemon(pidfile=None)
self.assertEqual(d.procname, 'python')
self.assertEqual(d.procname, sys.executable)
self.assertFalse(self.pidfile.called)
def test_fork_parent(self):