Skip to content

Commit

Permalink
tests/hotfix/Remove parsing .env in conftest (#838)
Browse files Browse the repository at this point in the history
* we do not have any .env file in the repository, the line is redundant

Signed-off-by: Daniel Diblik <[email protected]>

Modify tests

* use `CONVERT2RHEL_SKIP_KERNEL_CURRENCY_CHECK` instead of deprecated `CONVERT2RHEL_UNSUPPORTED_SKIP_KERNEL_CURRENCY_CHECK`

Signed-off-by: Daniel Diblik <[email protected]>

Revised checks.py and checks_test.py

* After Rebasing some of the code changed, and added in code not from
  this PR.
* In checks.py the log message was edited and the rest of the code.
* In checks_test.py edited is_loaded_kernel_latet_unsupported_skip, and
  added is_loaded_kernel_latet_unsupported_skip_env_var
* Use `CONVERT2RHEL_SKIP_KERNEL_CURRENCY_CHECK` instead of deprecated `CONVERT2RHEL_UNSUPPORTED_SKIP_KERNEL_CURRENCY_CHECK`

Signed-off-by: Daniel Diblik <[email protected]>

Use the deprecated envar in latest_kernel_check_skip

Signed-off-by: Daniel Diblik <[email protected]>
  • Loading branch information
danmyway authored and Andrew-ang9 committed Aug 16, 2023
1 parent 6e1be4a commit 14d1e05
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 50 deletions.
24 changes: 19 additions & 5 deletions convert2rhel/actions/system_checks/is_loaded_kernel_latest.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,26 @@ def run(self): # pylint: disable= too-many-return-statements
# Append the package name as the last item on the list
cmd.append(package_to_check)

unsupported_skip = os.environ.get("CONVERT2RHEL_UNSUPPORTED_SKIP_KERNEL_CURRENCY_CHECK", None)
# Repoquery failed to detected any kernel or kernel-core packages in it's repositories
# we allow the user to provide a environment variable to override the functionality and proceed
# with the conversion, otherwise, we just throw an critical logging to them.
allow_older_envvar_names = (
"CONVERT2RHEL_SKIP_KERNEL_CURRENCY_CHECK",
"CONVERT2RHEL_UNSUPPORTED_SKIP_KERNEL_CURRENCY_CHECK",
)
# This check is to see which environment variable is set, To allow users in the next version
# to adjust their environmental variable names. This check will be removed in the future and
# will only have the 'CONVERT2RHEL_SKIP_KERNEL_CURRENCY_CHECK' environment variable
if any(envvar in os.environ for envvar in allow_older_envvar_names):
if "CONVERT2RHEL_UNSUPPORTED_SKIP_KERNEL_CURRENCY_CHECK" in os.environ:
logger.warning(
"You are using the deprecated 'CONVERT2RHEL_UNSUPPORTED_SKIP_KERNEL_CURRENCY_CHECK'"
" environment variable. Please switch to 'CONVERT2RHEL_SKIP_KERNEL_CURRENCY_CHECK'"
" instead."
)

# Skip the kernel package check and print a warning if the user used the special environment variable for it
if unsupported_skip:
logger.warning(
"Detected 'CONVERT2RHEL_UNSUPPORTED_SKIP_KERNEL_CURRENCY_CHECK' environment variable, we will skip "
"Detected 'CONVERT2RHEL_SKIP_KERNEL_CURRENCY_CHECK' environment variable, we will skip "
"the %s comparison.\n"
"Beware, this could leave your system in a broken state." % package_to_check
)
Expand Down Expand Up @@ -124,7 +138,7 @@ def run(self): # pylint: disable= too-many-return-statements
"Could not find any %s from repositories to compare against the loaded kernel.\n"
"Please, check if you have any vendor repositories enabled to proceed with the conversion.\n"
"If you wish to ignore this message, set the environment variable "
"'CONVERT2RHEL_UNSUPPORTED_SKIP_KERNEL_CURRENCY_CHECK' to 1." % package_to_check
"'CONVERT2RHEL_SKIP_KERNEL_CURRENCY_CHECK' to 1." % package_to_check
),
)
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ def test_is_loaded_kernel_latest_eus_system_no_connection(
"",
0,
"1",
"Detected 'CONVERT2RHEL_UNSUPPORTED_SKIP_KERNEL_CURRENCY_CHECK' environment variable",
"Detected 'CONVERT2RHEL_SKIP_KERNEL_CURRENCY_CHECK' environment variable",
id="Unsupported skip with environment var set to 1",
),
pytest.param(
Expand Down Expand Up @@ -389,11 +389,12 @@ def test_is_loaded_kernel_latest_unsupported_skip_warnings(
"run_subprocess",
value=run_subprocess_mocked,
)
monkeypatch.setattr(
os,
"environ",
{"CONVERT2RHEL_UNSUPPORTED_SKIP_KERNEL_CURRENCY_CHECK": unsupported_skip},
)
if unsupported_skip:
monkeypatch.setattr(
os,
"environ",
{"CONVERT2RHEL_SKIP_KERNEL_CURRENCY_CHECK": unsupported_skip},
)

is_loaded_kernel_latest_action.run()

Expand Down
60 changes: 30 additions & 30 deletions plans/tier1.fmf
Original file line number Diff line number Diff line change
Expand Up @@ -277,33 +277,33 @@ description+: |
how: ansible
playbook: tests/ansible_collections/roles/reboot/main.yml

/latest_kernel_check_skip:
#TODO(danmyway) merge under system_not_updated in #757
enabled: false
adjust+:
- enabled: true
when: distro == centos-7, oraclelinux-7
environment+:
CONVERT2RHEL_UNSUPPORTED_SKIP_KERNEL_CURRENCY_CHECK: 1
# Since we are removing all the repositories other than rhel-7-server-rpms
# we need pass CONVERT2RHEL_UNSUPPORTED_INCOMPLETE_ROLLBACK due to the inability
# to download and backup packages
CONVERT2RHEL_UNSUPPORTED_INCOMPLETE_ROLLBACK: 1
# Unavailable kmods may be present on the system due to the kernel package
# not being updated. Mitigate the issues by exporting CONVERT2RHEL_ALLOW_UNAVAILABLE_KMODS.
CONVERT2RHEL_ALLOW_UNAVAILABLE_KMODS: 1
discover+:
filter: tag:checks-after-conversion
prepare+:
- name: prepare non latest kernel
how: shell
script: pytest -svv tests/integration/*/destructive/system-up-to-date/install_non_latest_kernel.py
- name: add custom repos
how: ansible
playbook: tests/ansible_collections/roles/add-custom-repos/main.yml
- name: reboot machine
how: ansible
playbook: tests/ansible_collections/roles/reboot/main.yml
- name: main conversion
how: shell
script: pytest -svv tests/integration/*/destructive/kernel-check-skip/test_latest_kernel_check_skip.py
/latest_kernel_check_skip:
#TODO(danmyway) merge under system_not_updated in #757
enabled: false
adjust+:
- enabled: true
when: distro == centos-7, oraclelinux-7
environment+:
CONVERT2RHEL_UNSUPPORTED_SKIP_KERNEL_CURRENCY_CHECK: 1
# Since we are removing all the repositories other than rhel-7-server-rpms
# we need pass CONVERT2RHEL_UNSUPPORTED_INCOMPLETE_ROLLBACK due to the inability
# to download and backup packages
CONVERT2RHEL_UNSUPPORTED_INCOMPLETE_ROLLBACK: 1
# Unavailable kmods may be present on the system due to the kernel package
# not being updated. Mitigate the issues by exporting CONVERT2RHEL_ALLOW_UNAVAILABLE_KMODS.
CONVERT2RHEL_ALLOW_UNAVAILABLE_KMODS: 1
discover+:
filter: tag:checks-after-conversion
prepare+:
- name: prepare non latest kernel
how: shell
script: pytest -svv tests/integration/tier1/system-up-to-date/install_non_latest_kernel.py
- name: add custom repos
how: ansible
playbook: tests/ansible_collections/roles/add-custom-repos/main.yml
- name: reboot machine
how: ansible
playbook: tests/ansible_collections/roles/reboot/main.yml
- name: main conversion
how: shell
script: pytest -svv tests/integration/tier1/kernel-check-skip/test_latest_kernel_check_skip.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ tag+:
description+: |
Install subscription-manager and katello package from the Satellite.
Remove all repositories from the system.
Set the "CONVERT2RHEL_UNSUPPORTED_SKIP_KERNEL_CURRENCY_CHECK" envar to bypass kernel check.
Set the "CONVERT2RHEL_SKIP_KERNEL_CURRENCY_CHECK" envar to bypass kernel check.
Verify that the /etc/os-release file is restored after the rollback.
/backup_os_release_no_envar:
summary+: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ def kernel_check_envar(shell):
to skip the kernel currency check.
"""
# Since we are moving all repos away, we need to bypass kernel check
os.environ["CONVERT2RHEL_UNSUPPORTED_SKIP_KERNEL_CURRENCY_CHECK"] = "1"
os.environ["CONVERT2RHEL_SKIP_KERNEL_CURRENCY_CHECK"] = "1"

yield

# Remove the envar skipping the kernel check
del os.environ["CONVERT2RHEL_UNSUPPORTED_SKIP_KERNEL_CURRENCY_CHECK"]
del os.environ["CONVERT2RHEL_SKIP_KERNEL_CURRENCY_CHECK"]


@pytest.mark.test_unsuccessful_satellite_registration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description+: |
Verify that it's possible to run the full conversion with older kernel,
than available in the RHEL repositories.
1/ Install older kernel on the system
2/ Make sure the `CONVERT2RHEL_UNSUPPORTED_SKIP_KERNEL_CURRENCY_CHECK` is in place
2/ Make sure the `CONVERT2RHEL_SKIP_KERNEL_CURRENCY_CHECK` is in place
* doing that we also verify, the deprecated envar is still allowed
3/ Enable *just* the rhel-7-server-rpms repository
4/ Run conversion verifying the conversion is not inhibited and completes successfully
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ def test_skip_kernel_check(shell, convert2rhel):
)
) as c2r:
# Verify that using the deprecated environment variable is still allowed and continues the conversion
# TODO(danmyway) uncomment in #684
# assert c2r.expect("You are using the deprecated 'CONVERT2RHEL_UNSUPPORTED_SKIP_KERNEL_CURRENCY_CHECK'") == 0
assert c2r.expect("You are using the deprecated 'CONVERT2RHEL_UNSUPPORTED_SKIP_KERNEL_CURRENCY_CHECK'") == 0
# Make sure the kernel comparison is skipped
c2r_expect_index = c2r.expect(
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_run_conversion_using_custom_repos(shell, convert2rhel):
shell("rm /etc/yum.repos.d/copr_build-convert2rhel-1.repo")

os.environ["CONVERT2RHEL_UNSUPPORTED_INCOMPLETE_ROLLBACK"] = "1"
os.environ["CONVERT2RHEL_UNSUPPORTED_SKIP_KERNEL_CURRENCY_CHECK"] = "1"
os.environ["CONVERT2RHEL_SKIP_KERNEL_CURRENCY_CHECK"] = "1"
# Unavailable kmods may be present on the system due to the kernel package
# not being updated. Mitigate the issues by exporting CONVERT2RHEL_ALLOW_UNAVAILABLE_KMODS.
os.environ["CONVERT2RHEL_ALLOW_UNAVAILABLE_KMODS"] = "1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_skip_kernel_check(shell, convert2rhel):
c2r.expect("Could not find any kernel-core from repositories to compare against the loaded kernel.")
assert c2r.exitstatus != 0

os.environ["CONVERT2RHEL_UNSUPPORTED_SKIP_KERNEL_CURRENCY_CHECK"] = "1"
os.environ["CONVERT2RHEL_SKIP_KERNEL_CURRENCY_CHECK"] = "1"

with convert2rhel(
"--no-rpm-va --serverurl {} --username {} --password {} --pool {} --debug".format(
Expand All @@ -48,7 +48,7 @@ def test_skip_kernel_check(shell, convert2rhel):
c2r.expect("Continue with the system conversion?")
c2r.sendline("y")

c2r.expect("Detected 'CONVERT2RHEL_UNSUPPORTED_SKIP_KERNEL_CURRENCY_CHECK' environment variable")
c2r.expect("Detected 'CONVERT2RHEL_SKIP_KERNEL_CURRENCY_CHECK' environment variable")
c2r.sendcontrol("c")
assert c2r.exitstatus != 0

Expand Down

0 comments on commit 14d1e05

Please sign in to comment.