Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the condition for eligible releases #42

Merged
merged 2 commits into from
Nov 29, 2023
Merged
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 scripts/conversion_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def get_system_distro_version():
return distribution_id, version_id


def is_non_eligible_releases(release):
def is_eligible_releases(release):
eligible_releases = "7.9"
return release == eligible_releases if release else False

Expand Down Expand Up @@ -576,7 +576,7 @@ def main():
try:
# Exit if not CentOS 7.9
dist, version = get_system_distro_version()
if dist != "centos" or is_non_eligible_releases(version):
if dist != "centos" or not is_eligible_releases(version):
raise ProcessError(
message="Conversion is only supported on CentOS 7.9 distributions.",
report='Exiting because distribution="%s" and version="%s"'
Expand Down
4 changes: 2 additions & 2 deletions scripts/preconversion_assessment_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def get_system_distro_version():
return distribution_id, version_id


def is_non_eligible_releases(release):
def is_eligible_releases(release):
eligible_releases = "7.9"
return release == eligible_releases if release else False

Expand Down Expand Up @@ -552,7 +552,7 @@ def main():
try:
# Exit if not CentOS 7.9
dist, version = get_system_distro_version()
if dist != "centos" or is_non_eligible_releases(version):
if dist != "centos" or not is_eligible_releases(version):
raise ProcessError(
message="Pre-conversion analysis is only supported on CentOS 7.9 distributions.",
report='Exiting because distribution="%s" and version="%s"'
Expand Down
9 changes: 9 additions & 0 deletions tests/conversion_script/test_eligible_release.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import pytest
from scripts.conversion_script import is_eligible_releases


@pytest.mark.parametrize(
("release", "expected"), (("6.10", False), ("7.9", True), ("8.9", False))
)
def test_is_eligible_releases(release, expected):
assert is_eligible_releases(release) == expected
53 changes: 25 additions & 28 deletions tests/conversion_script/test_main.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
# pylint: disable=too-many-arguments

from mock import patch, mock_open, Mock
from mock import patch, Mock

from scripts.conversion_script import main, ProcessError, OutputCollector


@patch(
"scripts.conversion_script.get_system_distro_version", return_value=("centos", "7")
)
@patch("scripts.conversion_script.is_non_eligible_releases", return_value=True)
@patch("scripts.conversion_script.cleanup")
@patch("scripts.conversion_script.OutputCollector")
@patch("scripts.conversion_script.archive_analysis_report", side_effect=Mock())
Expand All @@ -18,15 +17,13 @@ def test_main_non_eligible_release(
mock_archive_analysis_report,
mock_output_collector,
mock_cleanup,
mock_is_non_eligible_releases,
mock_get_system_distro_version,
):
mock_output_collector.return_value = OutputCollector(entries=["non-empty"])

main()

mock_get_system_distro_version.assert_called_once()
mock_is_non_eligible_releases.assert_called_once()
mock_output_collector.assert_called()
mock_cleanup.assert_called_once()
assert mock_archive_analysis_report.call_count == 0
Expand All @@ -48,14 +45,14 @@ def test_main_non_eligible_release(
@patch("os.path.exists", return_value=False)
@patch("scripts.conversion_script._create_or_restore_backup_file", side_effect=Mock())
@patch("scripts.conversion_script.run_subprocess", return_value=("", 1))
@patch("scripts.conversion_script.get_system_distro_version", return_value=("centos", "7"))
@patch("scripts.conversion_script.is_non_eligible_releases", return_value=False)
@patch("scripts.conversion_script.get_system_distro_version", return_value=("centos", "7.9"))
@patch("scripts.conversion_script.is_eligible_releases", return_value=True)
@patch("scripts.conversion_script.archive_analysis_report", side_effect=Mock())
# fmt: on
# pylint: disable=too-many-locals
def test_main_success_c2r_installed(
mock_archive_analysis_report,
mock_is_non_eligible_releases,
mock_is_eligible_releases,
mock_get_system_distro_version,
mock_cleanup_pkg_call,
mock_cleanup_file_restore_call,
Expand All @@ -75,7 +72,7 @@ def test_main_success_c2r_installed(

assert mock_archive_analysis_report.call_count == 0
assert mock_get_system_distro_version.call_count == 1
assert mock_is_non_eligible_releases.call_count == 1
assert mock_is_eligible_releases.call_count == 1
assert mock_setup_convert2rhel.call_count == 1
assert mock_inhibitor_check.call_count == 1
assert mock_install_convert2rhel.call_count == 1
Expand Down Expand Up @@ -109,11 +106,11 @@ def test_main_success_c2r_installed(
@patch("os.path.exists", return_value=False)
@patch("scripts.conversion_script._create_or_restore_backup_file", side_effect=Mock())
@patch("scripts.conversion_script.run_subprocess", return_value=("", 1))
@patch("scripts.conversion_script.get_system_distro_version", return_value=("centos", "7"))
@patch("scripts.conversion_script.is_non_eligible_releases", return_value=False)
@patch("scripts.conversion_script.get_system_distro_version", return_value=("centos", "7.9"))
@patch("scripts.conversion_script.is_eligible_releases", return_value=True)
# fmt: on
def test_main_inhibited_c2r_installed(
mock_is_non_eligible_releases,
mock_is_eligible_releases,
mock_get_system_distro_version,
mock_cleanup_pkg_call,
mock_cleanup_file_restore_call,
Expand All @@ -132,7 +129,7 @@ def test_main_inhibited_c2r_installed(
main()

assert mock_get_system_distro_version.call_count == 1
assert mock_is_non_eligible_releases.call_count == 1
assert mock_is_eligible_releases.call_count == 1
assert mock_inhibitor_check.call_count == 1
assert mock_setup_convert2rhel.call_count == 1
assert mock_install_convert2rhel.call_count == 1
Expand All @@ -159,15 +156,15 @@ def test_main_inhibited_c2r_installed(
@patch("scripts.conversion_script.gather_textual_report", side_effect=Mock(return_value=""))
@patch("scripts.conversion_script.generate_report_message", side_effect=Mock(return_value=("failed", False)))
@patch("scripts.conversion_script.cleanup", side_effect=Mock())
@patch("scripts.conversion_script.get_system_distro_version", return_value=("centos", "7"))
@patch("scripts.conversion_script.is_non_eligible_releases", return_value=False)
@patch("scripts.conversion_script.get_system_distro_version", return_value=("centos", "7.9"))
@patch("scripts.conversion_script.is_eligible_releases", return_value=True)
@patch("scripts.conversion_script.archive_analysis_report", side_effect=Mock())
@patch("scripts.conversion_script.update_insights_inventory", side_effect=Mock())
# fmt: on
def test_main_process_error(
mock_update_insights_inventory,
mock_archive_analysis_report,
mock_is_non_eligible_releases,
mock_is_eligible_releases,
mock_get_system_distro_version,
mock_cleanup,
mock_generate_report_message,
Expand All @@ -184,7 +181,7 @@ def test_main_process_error(
# Zero because os.path.exists is not mocked and reports do not exist
assert mock_archive_analysis_report.call_count == 0
assert mock_get_system_distro_version.call_count == 1
assert mock_is_non_eligible_releases.call_count == 1
assert mock_is_eligible_releases.call_count == 1
assert mock_setup_convert2rhel.call_count == 1
assert mock_inhibitor_check.call_count == 1
assert mock_install_convert2rhel.call_count == 1
Expand All @@ -206,15 +203,15 @@ def test_main_process_error(
@patch("scripts.conversion_script.gather_textual_report", side_effect=Mock(return_value="failed"))
@patch("scripts.conversion_script.generate_report_message", side_effect=Mock(return_value=("", False)))
@patch("scripts.conversion_script.cleanup", side_effect=Mock())
@patch("scripts.conversion_script.get_system_distro_version", return_value=("centos", "7"))
@patch("scripts.conversion_script.is_non_eligible_releases", return_value=False)
@patch("scripts.conversion_script.get_system_distro_version", return_value=("centos", "7.9"))
@patch("scripts.conversion_script.is_eligible_releases", return_value=True)
@patch("scripts.conversion_script.archive_analysis_report", side_effect=Mock())
@patch("scripts.conversion_script.update_insights_inventory", side_effect=Mock())
# fmt: on
def test_main_general_exception(
mock_update_insights_inventory,
mock_archive_analysis_report,
mock_is_non_eligible_releases,
mock_is_eligible_releases,
mock_get_system_distro_version,
mock_cleanup,
mock_generate_report_message,
Expand All @@ -230,7 +227,7 @@ def test_main_general_exception(
# Zero because os.path.exists is not mocked and reports do not exist
assert mock_archive_analysis_report.call_count == 0
assert mock_get_system_distro_version.call_count == 1
assert mock_is_non_eligible_releases.call_count == 1
assert mock_is_eligible_releases.call_count == 1
assert mock_setup_convert2rhel.call_count == 1
assert mock_inhibitor_check.call_count == 1
assert mock_install_convert2rhel.call_count == 1
Expand All @@ -252,15 +249,15 @@ def test_main_general_exception(
@patch("scripts.conversion_script.gather_textual_report", side_effect=Mock(return_value=""))
@patch("scripts.conversion_script.generate_report_message", side_effect=Mock(return_value=("", False)))
@patch("scripts.conversion_script.cleanup", side_effect=Mock())
@patch("scripts.conversion_script.get_system_distro_version", return_value=("centos", "7"))
@patch("scripts.conversion_script.is_non_eligible_releases", return_value=False)
@patch("scripts.conversion_script.get_system_distro_version", return_value=("centos", "7.9"))
@patch("scripts.conversion_script.is_eligible_releases", return_value=True)
@patch("scripts.conversion_script.archive_analysis_report", side_effect=Mock())
@patch("scripts.conversion_script.update_insights_inventory", side_effect=Mock())
# fmt: on
def test_main_inhibited_ini_modified(
mock_update_insights_inventory,
mock_archive_analysis_report,
mock_is_non_eligible_releases,
mock_is_eligible_releases,
mock_get_system_distro_version,
mock_cleanup,
mock_generate_report_message,
Expand All @@ -276,7 +273,7 @@ def test_main_inhibited_ini_modified(

assert mock_archive_analysis_report.call_count == 0
assert mock_get_system_distro_version.call_count == 1
assert mock_is_non_eligible_releases.call_count == 1
assert mock_is_eligible_releases.call_count == 1
assert mock_setup_convert2rhel.call_count == 1
assert mock_custom_ini.call_count == 1
# 2x for archive check + 1 inside in inhibitor check + 1 gather json
Expand All @@ -300,15 +297,15 @@ def test_main_inhibited_ini_modified(
@patch("scripts.conversion_script.gather_textual_report", side_effect=Mock(return_value=""))
@patch("scripts.conversion_script.generate_report_message", side_effect=Mock(return_value=("", False)))
@patch("scripts.conversion_script.cleanup", side_effect=Mock())
@patch("scripts.conversion_script.get_system_distro_version", return_value=("centos", "7"))
@patch("scripts.conversion_script.is_non_eligible_releases", return_value=False)
@patch("scripts.conversion_script.get_system_distro_version", return_value=("centos", "7.9"))
@patch("scripts.conversion_script.is_eligible_releases", return_value=True)
@patch("scripts.conversion_script.archive_analysis_report", side_effect=Mock())
@patch("scripts.conversion_script.update_insights_inventory", side_effect=Mock())
# fmt: on
def test_main_inhibited_custom_ini(
mock_update_insights_inventory,
mock_archive_analysis_report,
mock_is_non_eligible_releases,
mock_is_eligible_releases,
mock_get_system_distro_version,
mock_cleanup,
mock_generate_report_message,
Expand All @@ -324,7 +321,7 @@ def test_main_inhibited_custom_ini(

assert mock_archive_analysis_report.call_count == 2
assert mock_get_system_distro_version.call_count == 1
assert mock_is_non_eligible_releases.call_count == 1
assert mock_is_eligible_releases.call_count == 1
assert mock_setup_convert2rhel.call_count == 1
# Twice for archiving reports + 1 inside inhibitor check
assert mock_os_exists.call_count == 3
Expand Down
9 changes: 0 additions & 9 deletions tests/conversion_script/test_non_eligible_release.py

This file was deleted.

9 changes: 9 additions & 0 deletions tests/preconversion_assessment/test_eligible_release.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import pytest
from scripts.preconversion_assessment_script import is_eligible_releases


@pytest.mark.parametrize(
("release", "expected"), (("6.10", False), ("7.9", True), ("8.9", False))
)
def test_is_eligible_releases(release, expected):
assert is_eligible_releases(release) == expected
Loading