Merge "Swap find_executable for which"

This commit is contained in:
Zuul 2023-09-27 23:50:47 +00:00 committed by Gerrit Code Review
commit 5555980fb5
2 changed files with 9 additions and 5 deletions

View File

@ -24,7 +24,11 @@ import subprocess
import re
import six
import tempfile
from distutils.spawn import find_executable
try:
from shutil import which
except ImportError:
# py2
from distutils.spawn import find_executable as which
from swift.common.utils import search_tree, remove_file, write_file, readconf
from swift.common.exceptions import InvalidPidFileException
@ -204,7 +208,7 @@ def verify_server(server):
if not server:
return False
_, cmd = format_server_name(server)
if find_executable(cmd) is None:
if which(cmd) is None:
return False
return True

View File

@ -308,7 +308,7 @@ class TestManagerModule(unittest.TestCase):
# pretend that swift-object-server is the only file on path
return f if f == 'swift-object-server' else None
with mock.patch('swift.common.manager.find_executable',
with mock.patch('swift.common.manager.which',
side_effect=mock_find_exe):
# test valid servers
self.assertTrue(manager.verify_server('object'))
@ -1725,7 +1725,7 @@ class TestManager(unittest.TestCase):
self.assertTrue(server.server in servers[:2])
def test_iter(self):
with mock.patch.object(manager, 'find_executable', lambda x: x):
with mock.patch.object(manager, 'which', lambda x: x):
m = manager.Manager(['all'])
self.assertEqual(len(list(m)), len(manager.ALL_SERVERS))
for server in m:
@ -2348,7 +2348,7 @@ class TestManager(unittest.TestCase):
actual_servers.update([server.server for server in m.servers])
self.assertEqual(expected_servers, actual_servers)
with mock.patch.object(manager, 'find_executable', lambda x: x):
with mock.patch.object(manager, 'which', lambda x: x):
do_test(graceful=True)
do_test(graceful=False) # graceful is forced regardless