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 Automatus traceback #11111

Merged
merged 3 commits into from
Sep 13, 2023
Merged
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
47 changes: 31 additions & 16 deletions tests/ssg_test_suite/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,7 @@ def get_cpe_of_tested_os(test_env, log_file):
rhel7=("yum", "install", "-y"),
rhel8=("yum", "install", "-y"),
rhel9=("yum", "install", "-y"),
sles=("zypper", "install", "-y"),
ubuntu=("DEBIAN_FRONTEND=noninteractive", "apt", "install", "-y"),
)

Expand All @@ -601,24 +602,38 @@ def install_packages(test_env, packages):
"Couldn't install required packages: {packages}".format(packages=",".join(packages)))


def _match_rhel_version(cpe):
rhel_cpe = {
"redhat:enterprise_linux": r":enterprise_linux:([^:]+):",
"centos:centos": r"centos:centos:([0-9]+)"}
for cpe_item in rhel_cpe.keys():
if cpe_item in cpe:
match = re.search(rhel_cpe.get(cpe_item), cpe)
if match:
major_version = match.groups()[0].split(".")[0]
return "rhel" + major_version


def cpe_to_platform(cpe):
trivials = ["fedora", "sles", "ubuntu"]
for platform in trivials:
if platform in cpe:
return platform
rhel_version = _match_rhel_version(cpe)
if rhel_version is not None:
return rhel_version
if "oracle:linux" in cpe:
match = re.search(r":linux:([^:]+):", cpe)
if match:
major_version = match.groups()[0]
return "ol" + major_version


def cpes_to_platform(cpes):
rhel_cpe = {"redhat:enterprise_linux": r":enterprise_linux:([^:]+):", "centos:centos": r"centos:centos:([0-9]+)"}
for cpe in cpes:
if "fedora" in cpe:
return "fedora"
for cpe_item in rhel_cpe.keys():
if cpe_item in cpe:
match = re.search(rhel_cpe.get(cpe_item), cpe)
if match:
major_version = match.groups()[0].split(".")[0]
return "rhel" + major_version
if "ubuntu" in cpe:
return "ubuntu"
if "oracle:linux" in cpe:
match = re.search(r":linux:([^:]+):", cpe)
if match:
major_version = match.groups()[0]
return "ol" + major_version
platform = cpe_to_platform(cpe)
if platform is not None:
return platform
msg = "Unable to deduce a platform from these CPEs: {cpes}".format(cpes=cpes)
raise ValueError(msg)

Expand Down
Loading