Merge "Helper method to use dnf instead of yum on fedora >=22"
This commit is contained in:
commit
91cafcb9d2
|
@ -42,9 +42,11 @@ class TestGetOsDistrib(testtools.TestCase):
|
||||||
|
|
||||||
|
|
||||||
class TestInstallPackages(testtools.TestCase):
|
class TestInstallPackages(testtools.TestCase):
|
||||||
|
@mock.patch('sahara.utils.ssh_remote._get_os_version')
|
||||||
@mock.patch('sahara.utils.ssh_remote._get_os_distrib')
|
@mock.patch('sahara.utils.ssh_remote._get_os_distrib')
|
||||||
@mock.patch('sahara.utils.ssh_remote._execute_command')
|
@mock.patch('sahara.utils.ssh_remote._execute_command')
|
||||||
def test_install_packages(self, p_execute_command, p_get_os_distrib):
|
def test_install_packages(self, p_execute_command, p_get_os_distrib,
|
||||||
|
p_get_os_version):
|
||||||
packages = ('git', 'emacs', 'tree')
|
packages = ('git', 'emacs', 'tree')
|
||||||
|
|
||||||
# test ubuntu
|
# test ubuntu
|
||||||
|
@ -60,13 +62,22 @@ class TestInstallPackages(testtools.TestCase):
|
||||||
'yum install -y git emacs tree',
|
'yum install -y git emacs tree',
|
||||||
run_as_root=True)
|
run_as_root=True)
|
||||||
|
|
||||||
# test fedora
|
# test fedora < 22
|
||||||
p_get_os_distrib.return_value = 'fedora'
|
p_get_os_distrib.return_value = 'fedora'
|
||||||
|
p_get_os_version.return_value = 20
|
||||||
ssh_remote._install_packages(packages)
|
ssh_remote._install_packages(packages)
|
||||||
p_execute_command.assert_called_with(
|
p_execute_command.assert_called_with(
|
||||||
'yum install -y git emacs tree',
|
'yum install -y git emacs tree',
|
||||||
run_as_root=True)
|
run_as_root=True)
|
||||||
|
|
||||||
|
# test fedora >=22
|
||||||
|
p_get_os_distrib.return_value = 'fedora'
|
||||||
|
p_get_os_version.return_value = 23
|
||||||
|
ssh_remote._install_packages(packages)
|
||||||
|
p_execute_command.assert_called_with(
|
||||||
|
'dnf install -y git emacs tree',
|
||||||
|
run_as_root=True)
|
||||||
|
|
||||||
# test redhat
|
# test redhat
|
||||||
p_get_os_distrib.return_value = 'redhat'
|
p_get_os_distrib.return_value = 'redhat'
|
||||||
ssh_remote._install_packages(packages)
|
ssh_remote._install_packages(packages)
|
||||||
|
@ -84,9 +95,11 @@ class TestInstallPackages(testtools.TestCase):
|
||||||
|
|
||||||
|
|
||||||
class TestUpdateRepository(testtools.TestCase):
|
class TestUpdateRepository(testtools.TestCase):
|
||||||
|
@mock.patch('sahara.utils.ssh_remote._get_os_version')
|
||||||
@mock.patch('sahara.utils.ssh_remote._get_os_distrib')
|
@mock.patch('sahara.utils.ssh_remote._get_os_distrib')
|
||||||
@mock.patch('sahara.utils.ssh_remote._execute_command')
|
@mock.patch('sahara.utils.ssh_remote._execute_command')
|
||||||
def test_update_repository(self, p_execute_command, p_get_os_distrib):
|
def test_update_repository(self, p_execute_command, p_get_os_distrib,
|
||||||
|
p_get_os_version):
|
||||||
# test ubuntu
|
# test ubuntu
|
||||||
p_get_os_distrib.return_value = 'ubuntu'
|
p_get_os_distrib.return_value = 'ubuntu'
|
||||||
ssh_remote._update_repository()
|
ssh_remote._update_repository()
|
||||||
|
@ -99,12 +112,19 @@ class TestUpdateRepository(testtools.TestCase):
|
||||||
p_execute_command.assert_called_with(
|
p_execute_command.assert_called_with(
|
||||||
'yum clean all', run_as_root=True)
|
'yum clean all', run_as_root=True)
|
||||||
|
|
||||||
# test fedora
|
# test fedora < 22
|
||||||
p_get_os_distrib.return_value = 'fedora'
|
p_get_os_distrib.return_value = 'fedora'
|
||||||
|
p_get_os_version.return_value = 20
|
||||||
ssh_remote._update_repository()
|
ssh_remote._update_repository()
|
||||||
p_execute_command.assert_called_with(
|
p_execute_command.assert_called_with(
|
||||||
'yum clean all', run_as_root=True)
|
'yum clean all', run_as_root=True)
|
||||||
|
|
||||||
|
# test fedora >=22
|
||||||
|
p_get_os_distrib.return_value = 'fedora'
|
||||||
|
p_get_os_version.return_value = 23
|
||||||
|
ssh_remote._update_repository()
|
||||||
|
p_execute_command.assert_called_with(
|
||||||
|
'dnf clean all', run_as_root=True)
|
||||||
# test redhat
|
# test redhat
|
||||||
p_get_os_distrib.return_value = 'redhat'
|
p_get_os_distrib.return_value = 'redhat'
|
||||||
ssh_remote._update_repository()
|
ssh_remote._update_repository()
|
||||||
|
|
|
@ -360,11 +360,23 @@ def _get_os_distrib():
|
||||||
run_as_root=False)[1].lower()
|
run_as_root=False)[1].lower()
|
||||||
|
|
||||||
|
|
||||||
|
def _get_os_version():
|
||||||
|
return _execute_command(
|
||||||
|
('printf "import platform\nprint(platform.linux_distribution()[1])"'
|
||||||
|
' | python'), run_as_root=False)
|
||||||
|
|
||||||
|
|
||||||
def _install_packages(packages):
|
def _install_packages(packages):
|
||||||
distrib = _get_os_distrib()
|
distrib = _get_os_distrib()
|
||||||
if distrib == 'ubuntu':
|
if distrib == 'ubuntu':
|
||||||
cmd = 'RUNLEVEL=1 apt-get install -y %(pkgs)s'
|
cmd = 'RUNLEVEL=1 apt-get install -y %(pkgs)s'
|
||||||
elif distrib in ('redhat', 'centos', 'fedora'):
|
elif distrib == 'fedora':
|
||||||
|
fversion = _get_os_version()
|
||||||
|
if fversion >= 22:
|
||||||
|
cmd = 'dnf install -y %(pkgs)s'
|
||||||
|
else:
|
||||||
|
cmd = 'yum install -y %(pkgs)s'
|
||||||
|
elif distrib in ('redhat', 'centos'):
|
||||||
cmd = 'yum install -y %(pkgs)s'
|
cmd = 'yum install -y %(pkgs)s'
|
||||||
else:
|
else:
|
||||||
raise ex.NotImplementedException(
|
raise ex.NotImplementedException(
|
||||||
|
@ -379,7 +391,13 @@ def _update_repository():
|
||||||
distrib = _get_os_distrib()
|
distrib = _get_os_distrib()
|
||||||
if distrib == 'ubuntu':
|
if distrib == 'ubuntu':
|
||||||
cmd = 'apt-get update'
|
cmd = 'apt-get update'
|
||||||
elif distrib in ('redhat', 'centos', 'fedora'):
|
elif distrib == 'fedora':
|
||||||
|
fversion = _get_os_version()
|
||||||
|
if fversion >= 22:
|
||||||
|
cmd = 'dnf clean all'
|
||||||
|
else:
|
||||||
|
cmd = 'yum clean all'
|
||||||
|
elif distrib in ('redhat', 'centos'):
|
||||||
cmd = 'yum clean all'
|
cmd = 'yum clean all'
|
||||||
else:
|
else:
|
||||||
raise ex.NotImplementedException(
|
raise ex.NotImplementedException(
|
||||||
|
|
Loading…
Reference in New Issue