Skip to content

Commit

Permalink
Made changes to how the unit test gets the temp file
Browse files Browse the repository at this point in the history
* Edited log messages typo
  • Loading branch information
Andrew-ang9 committed Mar 31, 2022
1 parent 2120314 commit e091971
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions convert2rhel/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import os
import re
import sys
import tempfile

import rpm

Expand Down Expand Up @@ -77,15 +78,19 @@ def check_convert2rhel_latest():
"repoquery",
"--releasever=%s" % system_info.version.major,
]
repo_dir = os.path.join(utils.TMP_DIR, "convert2rhel_repo")
# repo_dir = os.path.join(utils.TMP_DIR, "convert2rhel_repo")
repo_dir = tempfile.mkdtemp(prefix="convert2rhel_repo.", dir=utils.TMP_DIR)
utils.mkdir_p(repo_dir)
repo_path = os.path.join(repo_dir, "convert2rhel.repo")
store_content_to_file(filename=repo_path, content=repo_content)

cmd.append("--setopt=reposdir=%s" % repo_dir)
cmd.append("convert2rhel")

raw_output_convert2rhel_versions, _ = run_subprocess(cmd, print_output=False)
raw_output_convert2rhel_versions, return_code = run_subprocess(cmd, print_output=False)

if return_code != 0:
logger.warning("Couldn't check if this is the latest version of convert2rhel")

PKG_NEVR = r"\b(\S+)-(?:([0-9]+):)?(\S+)-(\S+)\b"
convert2rhel_versions = re.findall(PKG_NEVR, raw_output_convert2rhel_versions, re.MULTILINE)
Expand All @@ -97,11 +102,11 @@ def check_convert2rhel_latest():

ver_compare = rpm.labelCompare(package_version[1:], latest_version)

ver_compare = rpm.labelCompare(("0", convert2rhel_version, "0"), ("0", latest_version[1], "0"))
ver_compare = rpm.labelCompare(("0", convert2rhel_version, "0"), latest_version)
if ver_compare == -1:
if system_info.version.major <= 6:
logger.warning(
"You are currently running %s, the latest version of convert2rhel is %s.\n"
"You are currently running %s and the latest version of convert2rhel is %s.\n"
"Only the latest version is supported for conversion. If you want to ignore"
" this you can set 'CONVERT2RHEL_UNSUPPORTED_VERSION' to continue"
% (convert2rhel_version, latest_version)
Expand All @@ -110,20 +115,20 @@ def check_convert2rhel_latest():
else:
if "CONVERT2RHEL_UNSUPPORTED_VERSION" in os.environ:
logger.warning(
"You are currently running %s, the latest version of convert2rhel is %s.\n"
"You are currently running %s and the latest version of convert2rhel is %s.\n"
"'CONVERT2RHEL_UNSUPPORTED_VERSION' environment detected, continuing conversion"
% (convert2rhel_version, latest_version)
)

else:
logger.critical(
"You are currently running %s, the latest version of convert2rhel is %s.\n"
"You are currently running %s and the latest version of convert2rhel is %s.\n"
"Continuing conversion." % (convert2rhel_version, latest_version)
)

else:
logger.info(
"You are currently running %s, the latest version of convert2rhel is %s.\n"
"You are currently running %s and the latest version of convert2rhel is %s.\n"
"Continuing conversion." % (convert2rhel_version, latest_version)
)

Expand Down

0 comments on commit e091971

Please sign in to comment.