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 Usage: subclass the Daemon class and override the run() method
""" """
def __init__(self, pidfile, stdin=DEVNULL, stdout=DEVNULL, 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): user=None, group=None):
"""Note: pidfile may be None.""" """Note: pidfile may be None."""
self.stdin = stdin self.stdin = stdin

View File

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

View File

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

View File

@ -13,6 +13,7 @@
# under the License. # under the License.
import signal import signal
import sys
import eventlet.event import eventlet.event
from eventlet.green import subprocess from eventlet.green import subprocess
@ -319,7 +320,7 @@ class TestFailingAsyncProcess(base.BaseTestCase):
def setUp(self): def setUp(self):
super(TestFailingAsyncProcess, self).setUp() super(TestFailingAsyncProcess, self).setUp()
path = self.get_temp_file_path('async.tmp', self.get_new_temp_dir()) 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__, failing_process.__file__,
path], path],
respawn_interval=0) respawn_interval=0)

View File

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