diff --git a/swift/common/manager.py b/swift/common/manager.py index 03a87bbbd1..a512cd0d39 100644 --- a/swift/common/manager.py +++ b/swift/common/manager.py @@ -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 diff --git a/test/unit/common/test_manager.py b/test/unit/common/test_manager.py index f1784fc7fc..674f312dd0 100644 --- a/test/unit/common/test_manager.py +++ b/test/unit/common/test_manager.py @@ -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