Merge "Add new Galera Cluster bootstraping method"
This commit is contained in:
commit
6aa86cfaf4
@ -102,6 +102,26 @@ def exists(path, is_directory=False, as_root=False):
|
|||||||
return found
|
return found
|
||||||
|
|
||||||
|
|
||||||
|
def find_executable(executable, path=None):
|
||||||
|
"""Finds a location of an executable in the locations listed in 'path'
|
||||||
|
|
||||||
|
:param executable File to search.
|
||||||
|
:type executable string
|
||||||
|
|
||||||
|
:param path Lookup directories separated by a path
|
||||||
|
separartor.
|
||||||
|
:type path string
|
||||||
|
"""
|
||||||
|
if path is None:
|
||||||
|
path = os.environ.get('PATH', os.defpath)
|
||||||
|
dirs = path.split(os.pathsep)
|
||||||
|
for directory in dirs:
|
||||||
|
exec_path = os.path.join(directory, executable)
|
||||||
|
if os.path.isfile(exec_path) and os.access(exec_path, os.X_OK):
|
||||||
|
return exec_path
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def _read_file_as_root(path, open_flag, convert_func):
|
def _read_file_as_root(path, open_flag, convert_func):
|
||||||
"""Read a file as root.
|
"""Read a file as root.
|
||||||
|
|
||||||
|
@ -49,10 +49,13 @@ class MariaDBApp(galera_service.GaleraApp):
|
|||||||
"sudo service %s bootstrap"
|
"sudo service %s bootstrap"
|
||||||
% result['service'])
|
% result['service'])
|
||||||
elif result['type'] == 'systemd':
|
elif result['type'] == 'systemd':
|
||||||
# TODO(mwj 2016/01/28): determine RHEL start for MariaDB Cluster
|
if operating_system.find_executable('galera_new_cluster'):
|
||||||
result['cmd_bootstrap_galera_cluster'] = (
|
result['cmd_bootstrap_galera_cluster'] = (
|
||||||
"sudo systemctl start %s@bootstrap.service"
|
"sudo galera_new_cluster")
|
||||||
% result['service'])
|
else:
|
||||||
|
result['cmd_bootstrap_galera_cluster'] = (
|
||||||
|
"sudo systemctl start %s@bootstrap.service"
|
||||||
|
% result['service'])
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -984,6 +984,75 @@ class TestOperatingSystem(trove_testtools.TestCase):
|
|||||||
"Got unknown keyword args: {'_unknown_kw': 0}"),
|
"Got unknown keyword args: {'_unknown_kw': 0}"),
|
||||||
'path', _unknown_kw=0)
|
'path', _unknown_kw=0)
|
||||||
|
|
||||||
|
def test_find_executable_without_path(self):
|
||||||
|
command = "command"
|
||||||
|
self._delegate_assert_find_executable(command=command,
|
||||||
|
path=None,
|
||||||
|
isfile=True,
|
||||||
|
access=True,
|
||||||
|
expected_return_value=(
|
||||||
|
"/usr/bin/command"))
|
||||||
|
self._delegate_assert_find_executable(command=command,
|
||||||
|
path=None,
|
||||||
|
isfile=True,
|
||||||
|
access=False,
|
||||||
|
expected_return_value=None)
|
||||||
|
self._delegate_assert_find_executable(command=command,
|
||||||
|
path=None,
|
||||||
|
isfile=False,
|
||||||
|
access=True,
|
||||||
|
expected_return_value=None)
|
||||||
|
self._delegate_assert_find_executable(command=command,
|
||||||
|
path=None,
|
||||||
|
isfile=False,
|
||||||
|
access=False,
|
||||||
|
expected_return_value=None)
|
||||||
|
|
||||||
|
def test_find_executable_with_path(self):
|
||||||
|
command = "command"
|
||||||
|
path = "/home"
|
||||||
|
self._delegate_assert_find_executable(command=command,
|
||||||
|
path=path,
|
||||||
|
isfile=True,
|
||||||
|
access=True,
|
||||||
|
expected_return_value=(
|
||||||
|
"/home/command"))
|
||||||
|
self._delegate_assert_find_executable(command=command,
|
||||||
|
path=path,
|
||||||
|
isfile=True,
|
||||||
|
access=False,
|
||||||
|
expected_return_value=None)
|
||||||
|
self._delegate_assert_find_executable(command=command,
|
||||||
|
path=path,
|
||||||
|
isfile=False,
|
||||||
|
access=True,
|
||||||
|
expected_return_value=None)
|
||||||
|
self._delegate_assert_find_executable(command=command,
|
||||||
|
path=path,
|
||||||
|
isfile=False,
|
||||||
|
access=False,
|
||||||
|
expected_return_value=None)
|
||||||
|
|
||||||
|
def _delegate_assert_find_executable(self, command, path, isfile,
|
||||||
|
access, expected_return_value):
|
||||||
|
self._assert_find_executable(command, path, isfile, access,
|
||||||
|
expected_return_value)
|
||||||
|
|
||||||
|
@patch.object(os, 'access')
|
||||||
|
@patch.object(os.path, 'isfile')
|
||||||
|
@patch.object(os.environ, 'get', return_value="/usr/bin")
|
||||||
|
def _assert_find_executable(self, command, path, isfile, access,
|
||||||
|
expected_return_value, mock_environ,
|
||||||
|
mock_isfile, mock_access):
|
||||||
|
mock_access.return_value = access
|
||||||
|
mock_isfile.return_value = isfile
|
||||||
|
actual_result = operating_system.find_executable(command, path)
|
||||||
|
self.assertEqual(expected_return_value, actual_result)
|
||||||
|
if path is None:
|
||||||
|
mock_environ.assert_called_once()
|
||||||
|
else:
|
||||||
|
mock_environ.assert_not_called()
|
||||||
|
|
||||||
def test_exists(self):
|
def test_exists(self):
|
||||||
self.assertFalse(
|
self.assertFalse(
|
||||||
operating_system.exists(tempfile.gettempdir(), is_directory=False))
|
operating_system.exists(tempfile.gettempdir(), is_directory=False))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user