Merge "Swap find_executable for which"
This commit is contained in:
commit
5555980fb5
@ -24,7 +24,11 @@ import subprocess
|
|||||||
import re
|
import re
|
||||||
import six
|
import six
|
||||||
import tempfile
|
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.utils import search_tree, remove_file, write_file, readconf
|
||||||
from swift.common.exceptions import InvalidPidFileException
|
from swift.common.exceptions import InvalidPidFileException
|
||||||
@ -204,7 +208,7 @@ def verify_server(server):
|
|||||||
if not server:
|
if not server:
|
||||||
return False
|
return False
|
||||||
_, cmd = format_server_name(server)
|
_, cmd = format_server_name(server)
|
||||||
if find_executable(cmd) is None:
|
if which(cmd) is None:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -308,7 +308,7 @@ class TestManagerModule(unittest.TestCase):
|
|||||||
# pretend that swift-object-server is the only file on path
|
# pretend that swift-object-server is the only file on path
|
||||||
return f if f == 'swift-object-server' else None
|
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):
|
side_effect=mock_find_exe):
|
||||||
# test valid servers
|
# test valid servers
|
||||||
self.assertTrue(manager.verify_server('object'))
|
self.assertTrue(manager.verify_server('object'))
|
||||||
@ -1725,7 +1725,7 @@ class TestManager(unittest.TestCase):
|
|||||||
self.assertTrue(server.server in servers[:2])
|
self.assertTrue(server.server in servers[:2])
|
||||||
|
|
||||||
def test_iter(self):
|
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'])
|
m = manager.Manager(['all'])
|
||||||
self.assertEqual(len(list(m)), len(manager.ALL_SERVERS))
|
self.assertEqual(len(list(m)), len(manager.ALL_SERVERS))
|
||||||
for server in m:
|
for server in m:
|
||||||
@ -2348,7 +2348,7 @@ class TestManager(unittest.TestCase):
|
|||||||
actual_servers.update([server.server for server in m.servers])
|
actual_servers.update([server.server for server in m.servers])
|
||||||
self.assertEqual(expected_servers, actual_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=True)
|
||||||
do_test(graceful=False) # graceful is forced regardless
|
do_test(graceful=False) # graceful is forced regardless
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user