Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions coriolis/osmorphing/amazon.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ def enable_repos(self, repo_names):
# Determine package manager based on version
# Amazon Linux 2 has version "2", AL2023 has version "2023"
try:
major_version = int(str(self._version).split('.')[0])
except (ValueError, AttributeError):
major_version = self._parse_version_util(self._version).major
except ValueError:
# Fallback to yum if version parsing fails
major_version = 2

Expand Down
16 changes: 16 additions & 0 deletions coriolis/osmorphing/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
from six import with_metaclass
import yaml

from packaging.version import InvalidVersion
from packaging.version import Version

from coriolis import exception
from coriolis.osmorphing.netpreserver import factory
from coriolis import utils
Expand Down Expand Up @@ -334,6 +337,19 @@ def _version_supported_util(cls, version, minimum, maximum=None):

return True

@classmethod
def _parse_version_util(cls, version: str) -> Version:
if not version:
raise ValueError(f"Empty or missing version: {version!r}")

try:
return Version(str(version))
except InvalidVersion as exc:
raise ValueError(
f"Could not parse version from release string: "
f"{version!r}"
) from exc

def get_packages(self):
k_add = [h for h in self._packages.keys() if
h is None or h == self._hypervisor]
Expand Down
2 changes: 1 addition & 1 deletion coriolis/osmorphing/centos.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def enable_repos(self, repo_names):
return

# Determine package manager based on version
major_version = int(str(self._version).split('.')[0])
major_version = self._parse_version_util(self._version).major
if major_version >= 8:
# CentOS 8+ uses dnf
config_manager = 'dnf config-manager'
Expand Down
2 changes: 1 addition & 1 deletion coriolis/osmorphing/oracle.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def enable_repos(self, repo_names):
return

# Determine package manager based on version
major_version = int(str(self._version).split('.')[0])
major_version = self._parse_version_util(self._version).major
if major_version >= 8:
# OL8+ uses dnf
config_manager = 'dnf config-manager'
Expand Down
28 changes: 28 additions & 0 deletions coriolis/tests/osmorphing/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from unittest import mock

import ddt
from packaging.version import Version

from coriolis import exception
from coriolis.osmorphing import base
Expand Down Expand Up @@ -180,6 +181,33 @@ def test_version_supported_util_warnings_no_match(self):
version, minimum)
self.assertFalse(result)

@ddt.data(
("8", 8),
("8.0", 8),
("8.10", 8),
("9", 9),
("9.4", 9),
("10", 10),
("10.0", 10),
("10.10", 10),
)
@ddt.unpack
def test__parse_version_util(self, version, expected_major):
result = self.os_morphing_tools._parse_version_util(version)
self.assertIsInstance(result, Version)
self.assertEqual(result.major, expected_major)

@ddt.data(
"",
None,
"abc",
"x10",
)
def test__parse_version_util_invalid(self, version):
self.assertRaises(
ValueError,
self.os_morphing_tools._parse_version_util, version)

def test_get_packages(self):
self.os_morphing_tools._packages = {
None: [('pkg1', False), ('pkg2', True)],
Expand Down
34 changes: 21 additions & 13 deletions coriolis/tests/osmorphing/test_centos.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,32 @@ def setUp(self):
mock.sentinel.event_manager, self.detected_os_info,
mock.sentinel.osmorphing_parameters)

def test_check_os_supported(self):
@ddt.data(
(centos.CENTOS_DISTRO_IDENTIFIER, '6', True),
(centos.CENTOS_DISTRO_IDENTIFIER, '7', True),
(centos.CENTOS_DISTRO_IDENTIFIER, '8', True),
(centos.CENTOS_DISTRO_IDENTIFIER, '9', True),
(centos.CENTOS_DISTRO_IDENTIFIER, '10', True),
(centos.CENTOS_DISTRO_IDENTIFIER, '10.0', True),
(centos.CENTOS_STREAM_DISTRO_IDENTIFIER, '8', True),
(centos.CENTOS_STREAM_DISTRO_IDENTIFIER, '9', True),
(centos.CENTOS_STREAM_DISTRO_IDENTIFIER, '10', True),
('unsupported', '8', False),
(centos.CENTOS_DISTRO_IDENTIFIER, '5', False),
(centos.CENTOS_DISTRO_IDENTIFIER, 'abc', False),
)
@ddt.unpack
def test_check_os_supported(self, distribution_name, release_version,
expected):
detected_os_info = {
"distribution_name": centos.CENTOS_DISTRO_IDENTIFIER,
"release_version": "6"
"distribution_name": distribution_name,
"release_version": release_version
}

result = centos.BaseCentOSMorphingTools.check_os_supported(
detected_os_info)

self.assertTrue(result)

def test_check_os_not_supported(self):
detected_os_info = {
"distribution_name": 'unsupported',
}
result = centos.BaseCentOSMorphingTools.check_os_supported(
detected_os_info)

self.assertFalse(result)
self.assertEqual(expected, result)

@ddt.data(
# CentOS 7 and earlier use yum-config-manager.
Expand All @@ -58,6 +65,7 @@ def test_check_os_not_supported(self):
# CentOS 8+ uses dnf config-manager.
('8', 'dnf config-manager --set-enabled'),
('9', 'dnf config-manager --set-enabled'),
('10', 'dnf config-manager --set-enabled'),
)
@ddt.unpack
@mock.patch.object(base.BaseLinuxOSMorphingTools, '_exec_cmd_chroot')
Expand Down
20 changes: 18 additions & 2 deletions coriolis/tests/osmorphing/test_oracle.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,25 @@ def setUp(self):
mock.sentinel.event_manager, self.detected_os_info,
mock.sentinel.osmorphing_parameters)

def test_check_os_supported(self):
@ddt.data(
('6', True),
('7', True),
('8', True),
('9', True),
('9.4', True),
('10', True),
('10.0', True),
('11', True),
('5', False),
('abc', False),
)
@ddt.unpack
def test_check_os_supported(self, release_version, expected):
self.detected_os_info['release_version'] = release_version
result = oracle.BaseOracleMorphingTools.check_os_supported(
self.detected_os_info)

self.assertTrue(result)
self.assertEqual(expected, result)

def test_check_os_not_supported(self):
self.detected_os_info['distribution_name'] = 'unsupported'
Expand All @@ -52,6 +66,8 @@ def test_check_os_not_supported(self):
('7', 'yum-config-manager --enable'),
# OL8+ uses dnf config-manager.
('8', 'dnf config-manager --set-enabled'),
('9', 'dnf config-manager --set-enabled'),
('10', 'dnf config-manager --set-enabled'),
)
@ddt.unpack
@mock.patch.object(base.BaseLinuxOSMorphingTools, '_exec_cmd_chroot')
Expand Down
21 changes: 18 additions & 3 deletions coriolis/tests/osmorphing/test_redhat.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,26 @@ def setUp(self):
mock.sentinel.operation_timeout)
self.morphing_tools._os_root_dir = '/root'

def test_check_os_supported(self):
@ddt.data(
('6', True),
('7', True),
('8', True),
('9', True),
('9.4', True),
('10', True),
('10.0', True),
('11', True),
('5', False),
('abc', False),
('', False),
)
@ddt.unpack
def test_check_os_supported_release_version(
self, release_version, expected):
self.detected_os_info['release_version'] = release_version
result = redhat.BaseRedHatMorphingTools.check_os_supported(
self.detected_os_info)

self.assertTrue(result)
self.assertEqual(expected, result)

def test_check_os_not_supported(self):
self.detected_os_info['distribution_name'] = 'unsupported'
Expand Down
21 changes: 18 additions & 3 deletions coriolis/tests/osmorphing/test_rocky.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
import logging
from unittest import mock

import ddt

from coriolis import exception
from coriolis.osmorphing import base
from coriolis.osmorphing import rocky
from coriolis.tests import test_base


@ddt.ddt
class BaseRockyLinuxMorphingToolsTestCase(test_base.CoriolisBaseTestCase):
"""Test suite for the BaseRockyLinuxMorphingTools class."""

Expand All @@ -28,16 +31,28 @@ def setUp(self):
mock.sentinel.event_manager, self.detected_os_info,
mock.sentinel.osmorphing_parameters)

def test_check_os_supported(self):
@ddt.data(
('8', True),
('8.4', True),
('9', True),
('9.4', True),
('10', True),
('10.0', True),
('11', True),
('7', False),
('abc', False),
)
@ddt.unpack
def test_check_os_supported(self, release_version, expected):
detected_os_info = {
"distribution_name": rocky.ROCKY_LINUX_DISTRO_IDENTIFIER,
"release_version": "8"
"release_version": release_version
}
result = rocky.BaseRockyLinuxMorphingTools.check_os_supported(
detected_os_info
)

self.assertTrue(result)
self.assertEqual(expected, result)

def test_check_os_not_supported(self):
detected_os_info = {
Expand Down
Loading