Skip to content

Commit

Permalink
Merge pull request ComplianceAsCode#11111 from jan-cerny/fix_sles_aut…
Browse files Browse the repository at this point in the history
…omatus

Fix Automatus traceback
  • Loading branch information
ggbecker authored Sep 13, 2023
2 parents f93f87d + 6d0a593 commit 0cc8001
Showing 1 changed file with 31 additions and 16 deletions.
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

0 comments on commit 0cc8001

Please sign in to comment.