Replace 'lsb_release -is' with the method 'get_os_distrib'
It helps identify the distribution using method 'get_is_distrib' closes-bug: #1609505 Change-Id: I59f1f521cd82cb8f5ed65c1a82744deb3268ac2d
This commit is contained in:
parent
4427f7698c
commit
047ab5ae99
@ -10,4 +10,4 @@ source = sahara
|
||||
|
||||
[report]
|
||||
ignore_errors = True
|
||||
precision = 3
|
||||
precision = 3
|
@ -22,7 +22,7 @@ def _root(remote, cmd, **kwargs):
|
||||
|
||||
|
||||
def _get_os_distrib(remote):
|
||||
return remote.execute_command('lsb_release -is')[1].strip().lower()
|
||||
return remote.get_os_distrib()
|
||||
|
||||
|
||||
def is_centos_os(remote):
|
||||
|
@ -75,7 +75,7 @@ def get_all():
|
||||
|
||||
def get(instance):
|
||||
with instance.remote() as r:
|
||||
name = r.execute_command('lsb_release -is', run_as_root=True)[1]
|
||||
name = r.get_os_distrib()
|
||||
for d in get_all():
|
||||
if d.name in name:
|
||||
return d
|
||||
|
@ -38,16 +38,12 @@ ntp_opts = [
|
||||
CONF.register_opts(ntp_opts)
|
||||
|
||||
|
||||
def _get_os_distrib(remote):
|
||||
return remote.execute_command('lsb_release -is')[1].strip().lower()
|
||||
|
||||
|
||||
def _sudo(remote, cmd):
|
||||
remote.execute_command(cmd, run_as_root=True)
|
||||
|
||||
|
||||
def _restart_ntp(remote):
|
||||
distrib = _get_os_distrib(remote)
|
||||
distrib = remote.get_os_distrib()
|
||||
cmd = "service %s restart"
|
||||
if distrib == 'ubuntu':
|
||||
cmd = cmd % "ntp"
|
||||
@ -58,7 +54,7 @@ def _restart_ntp(remote):
|
||||
|
||||
|
||||
def _verify_installation(remote):
|
||||
distrib = _get_os_distrib(remote)
|
||||
distrib = remote.get_os_distrib()
|
||||
if distrib == 'ubuntu':
|
||||
return remote.execute_command("dpkg -s ntp")
|
||||
else:
|
||||
|
@ -231,8 +231,7 @@ class _NFSMounter(_ShareHandler):
|
||||
@classmethod
|
||||
def setup_instance(cls, remote):
|
||||
"""Prepares an instance to mount this type of share."""
|
||||
response = remote.execute_command('lsb_release -is')
|
||||
distro = response[1].strip().lower()
|
||||
distro = remote.get_os_distrib()
|
||||
if distro in cls._NFS_CHECKS:
|
||||
command = cls._NFS_CHECKS[distro]
|
||||
remote.execute_command(command, run_as_root=True)
|
||||
|
@ -59,7 +59,7 @@ def _is_xfs_enabled(cluster):
|
||||
|
||||
|
||||
def _get_os_distrib(remote):
|
||||
return remote.execute_command('lsb_release -is')[1].strip().lower()
|
||||
return remote.get_os_distrib()
|
||||
|
||||
|
||||
def _check_installed_xfs(instance):
|
||||
|
@ -45,6 +45,9 @@ class FakeRemote(object):
|
||||
def append_to_file(self, file, text, run_as_root=False):
|
||||
return self.execute_command(file, run_as_root)
|
||||
|
||||
def get_os_distrib(self):
|
||||
return self.execute_command('get_os_distrib')
|
||||
|
||||
|
||||
class FakeInstance(object):
|
||||
def __init__(self, effects, id):
|
||||
|
@ -45,7 +45,7 @@ def _mock_node_group(ips, share_list):
|
||||
# Returns a mocked node group and a list of mocked
|
||||
# execute_command functions for its instances.
|
||||
|
||||
execute_mocks = [mock.Mock(return_value=(None, "centos")) for ip in ips]
|
||||
execute_mocks = [mock.Mock(return_value="centos") for ip in ips]
|
||||
get_id = mock.Mock(return_value=uuid.uuid4())
|
||||
instances = [
|
||||
mock.Mock(
|
||||
@ -54,7 +54,8 @@ def _mock_node_group(ips, share_list):
|
||||
return_value=mock.Mock(
|
||||
__enter__=mock.Mock(
|
||||
return_value=mock.Mock(
|
||||
execute_command=execute_mocks[index])),
|
||||
execute_command=execute_mocks[index],
|
||||
get_os_distrib=execute_mocks[index])),
|
||||
__exit__=mock.Mock())))
|
||||
for index, ip in enumerate(ips)]
|
||||
|
||||
@ -66,7 +67,6 @@ def _mock_node_group(ips, share_list):
|
||||
|
||||
def _setup_calls():
|
||||
return [
|
||||
mock.call('lsb_release -is'),
|
||||
mock.call('rpm -q nfs-utils || yum install -y nfs-utils',
|
||||
run_as_root=True)]
|
||||
|
||||
|
@ -33,11 +33,13 @@ class TestEscapeQuotes(testtools.TestCase):
|
||||
class TestGetOsDistrib(testtools.TestCase):
|
||||
@mock.patch('sahara.utils.ssh_remote._execute_command',
|
||||
return_value=[1, 'Ubuntu'])
|
||||
def test_get_os_distrib(self, p_execute_command):
|
||||
@mock.patch('sahara.utils.ssh_remote.__get_python_to_execute',
|
||||
return_value='python3')
|
||||
def test_get_os_distrib(self, python, p_execute_command):
|
||||
d = ssh_remote._get_os_distrib()
|
||||
p_execute_command.assert_called_once_with(
|
||||
('printf "import platform\nprint(platform.linux_distribution('
|
||||
'full_distribution_name=0)[0])" | python'),
|
||||
'full_distribution_name=0)[0])" | python3'),
|
||||
run_as_root=False)
|
||||
self.assertEqual('ubuntu', d)
|
||||
|
||||
|
@ -354,17 +354,28 @@ def _read_file_from(remote_file, run_as_root=False):
|
||||
'rm %s' % fl, run_as_root=True, raise_when_error=False)
|
||||
|
||||
|
||||
def __get_python_to_execute():
|
||||
try:
|
||||
_execute_command('python3 --version')
|
||||
except Exception:
|
||||
_execute_command('python2 --version')
|
||||
return 'python2'
|
||||
return 'python3'
|
||||
|
||||
|
||||
def _get_os_distrib():
|
||||
python_version = __get_python_to_execute()
|
||||
return _execute_command(
|
||||
('printf "import platform\nprint(platform.linux_distribution('
|
||||
'full_distribution_name=0)[0])" | python'),
|
||||
'full_distribution_name=0)[0])" | {}'.format(python_version)),
|
||||
run_as_root=False)[1].lower().strip()
|
||||
|
||||
|
||||
def _get_os_version():
|
||||
python_version = __get_python_to_execute()
|
||||
return _execute_command(
|
||||
('printf "import platform\nprint(platform.linux_distribution()[1])"'
|
||||
' | python'), run_as_root=False)[1].strip()
|
||||
' | {}'.format(python_version)), run_as_root=False)[1].strip()
|
||||
|
||||
|
||||
def _install_packages(packages):
|
||||
|
Loading…
x
Reference in New Issue
Block a user