From d43cb246ccf736428a468b5d95c44743ca3d46cc Mon Sep 17 00:00:00 2001 From: Bala Raman <1273137+srbala@users.noreply.github.com> Date: Thu, 2 Dec 2021 05:34:11 -0500 Subject: [PATCH 1/2] Add Almalinux OS support (#1) * Update __init__.py * Update mappers.py * Update test_namespaces.py * Update utils.py * Update test_distro_mapping.py * Update test_mappers.py Signed-off-by: Bala Raman --- anchore_engine/services/policy_engine/__init__.py | 1 + .../services/policy_engine/engine/vulns/mappers.py | 3 +++ .../services/policy_engine/db/test_distro_mapping.py | 5 +++++ .../services/policy_engine/test_namespaces.py | 10 +++++++++- tests/integration/services/policy_engine/utils.py | 1 + .../policy_engine/engine/vulns/test_mappers.py | 1 + 6 files changed, 20 insertions(+), 1 deletion(-) diff --git a/anchore_engine/services/policy_engine/__init__.py b/anchore_engine/services/policy_engine/__init__.py index 7b9022a48..8f990d1ad 100644 --- a/anchore_engine/services/policy_engine/__init__.py +++ b/anchore_engine/services/policy_engine/__init__.py @@ -138,6 +138,7 @@ def _init_distro_mappings(): from_distro="sles", to_distro="sles", flavor="RHEL" ), # RHEL since it uses RPMs for version checks DistroMapping(from_distro="rocky", to_distro="rhel", flavor="RHEL"), + DistroMapping(from_distro="almalinux", to_distro="rhel", flavor="RHEL"), ] # set up any data necessary at system init diff --git a/anchore_engine/services/policy_engine/engine/vulns/mappers.py b/anchore_engine/services/policy_engine/engine/vulns/mappers.py index 0fe8ba08b..8863a2c2d 100644 --- a/anchore_engine/services/policy_engine/engine/vulns/mappers.py +++ b/anchore_engine/services/policy_engine/engine/vulns/mappers.py @@ -698,6 +698,9 @@ def grype_to_engine_image_vulnerability( "rocky": DistroMapper( engine_distro="rocky", grype_os="rockylinux", grype_like_os="fedora" ), + "almalinux": DistroMapper( + engine_distro="almalinux", grype_os="almalinux", grype_like_os="fedora" + ), } diff --git a/tests/integration/services/policy_engine/db/test_distro_mapping.py b/tests/integration/services/policy_engine/db/test_distro_mapping.py index ebc59fe3d..46158efd4 100644 --- a/tests/integration/services/policy_engine/db/test_distro_mapping.py +++ b/tests/integration/services/policy_engine/db/test_distro_mapping.py @@ -80,5 +80,10 @@ def test_distro_from(anchore_db): logger.info("Distros for rocky 8 (rhel) = {}".format(distros)) assert distros is not None assert len(distros) == 1 + + distros = DistroMapping.distros_for("almalinux", "8", "rhel") + logger.info("Distros for almalinux 8 (rhel) = {}".format(distros)) + assert distros is not None + assert len(distros) == 1 finally: session.commit() diff --git a/tests/integration/services/policy_engine/test_namespaces.py b/tests/integration/services/policy_engine/test_namespaces.py index 5dfbedb2c..91f624c37 100644 --- a/tests/integration/services/policy_engine/test_namespaces.py +++ b/tests/integration/services/policy_engine/test_namespaces.py @@ -231,13 +231,17 @@ def test_distromappings(initialized_mappings): assert c7.like_namespace_names == ["rhel:7"] r7 = DistroNamespace(name="rhel", version="7", like_distro="rhel") - assert set(r7.mapped_names()) == {"centos", "fedora", "rhel", "redhat", "rocky"} + assert set(r7.mapped_names()) == {"centos", "fedora", "rhel", "redhat", "rocky", "almalinux"} assert r7.like_namespace_names == ["rhel:7"] rocky7 = DistroNamespace(name="rocky", version="7", like_distro="rhel") assert rocky7.mapped_names() == [] assert rocky7.like_namespace_names == ["rhel:7"] + almalinux7 = DistroNamespace(name="almalinux", version="7", like_distro="rhel") + assert almalinux7.mapped_names() == [] + assert almalinux7.like_namespace_names == ["rhel:7"] + assert sorted(DistroMapping.distros_mapped_to("rhel", "7")) == sorted( [ DistroTuple("redhat", "7", "RHEL"), @@ -245,6 +249,7 @@ def test_distromappings(initialized_mappings): DistroTuple("centos", "7", "RHEL"), DistroTuple("fedora", "7", "RHEL"), DistroTuple("rocky", "7", "RHEL"), + DistroTuple("almalinux", "7", "RHEL"), ] ) @@ -259,3 +264,6 @@ def test_mapped_distros(initialized_mappings): assert DistroMapping.distros_for("rocky", "8", "rhel") == [ DistroTuple("rhel", "8", "RHEL") ] + assert DistroMapping.distros_for("almalinux", "8", "rhel") == [ + DistroTuple("rhel", "8", "RHEL") + ] diff --git a/tests/integration/services/policy_engine/utils.py b/tests/integration/services/policy_engine/utils.py index 2ff7f2b00..1c71cc9f6 100644 --- a/tests/integration/services/policy_engine/utils.py +++ b/tests/integration/services/policy_engine/utils.py @@ -42,6 +42,7 @@ def init_distro_mappings(): DistroMapping(from_distro="rhel", to_distro="centos", flavor="RHEL"), DistroMapping(from_distro="ubuntu", to_distro="ubuntu", flavor="DEB"), DistroMapping(from_distro="rocky", to_distro="rhel", flavor="RHEL"), + DistroMapping(from_distro="almalinux", to_distro="rhel", flavor="RHEL"), ] # set up any data necessary at system init diff --git a/tests/unit/anchore_engine/services/policy_engine/engine/vulns/test_mappers.py b/tests/unit/anchore_engine/services/policy_engine/engine/vulns/test_mappers.py index 54f1aaeed..44fe91491 100644 --- a/tests/unit/anchore_engine/services/policy_engine/engine/vulns/test_mappers.py +++ b/tests/unit/anchore_engine/services/policy_engine/engine/vulns/test_mappers.py @@ -24,6 +24,7 @@ pytest.param("sles", "sles", "sles", id="sles"), pytest.param("windows", "windows", "", id="windows"), pytest.param("rocky", "rockylinux", "fedora", id="rocky"), + pytest.param("almalinux", "almalinux", "fedora", id="almalinux"), ], ) def test_engine_distro_mappers(test_distro, expected_os, expected_like_os): From 4ebc0eda6a77edbeb28876360bf09cac7467c073 Mon Sep 17 00:00:00 2001 From: Bala Raman <1273137+srbala@users.noreply.github.com> Date: Sun, 12 Dec 2021 00:24:08 -0500 Subject: [PATCH 2/2] Update test_distro_mapping.py - Fix CircleCI lint errors * Update test_distro_mapping.py * Update test_namespaces.py fix pythong lint Signed-off-by: Bala Raman --- .../services/policy_engine/db/test_distro_mapping.py | 2 +- tests/integration/services/policy_engine/test_namespaces.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/integration/services/policy_engine/db/test_distro_mapping.py b/tests/integration/services/policy_engine/db/test_distro_mapping.py index 46158efd4..17cd24525 100644 --- a/tests/integration/services/policy_engine/db/test_distro_mapping.py +++ b/tests/integration/services/policy_engine/db/test_distro_mapping.py @@ -80,7 +80,7 @@ def test_distro_from(anchore_db): logger.info("Distros for rocky 8 (rhel) = {}".format(distros)) assert distros is not None assert len(distros) == 1 - + distros = DistroMapping.distros_for("almalinux", "8", "rhel") logger.info("Distros for almalinux 8 (rhel) = {}".format(distros)) assert distros is not None diff --git a/tests/integration/services/policy_engine/test_namespaces.py b/tests/integration/services/policy_engine/test_namespaces.py index 91f624c37..983f51250 100644 --- a/tests/integration/services/policy_engine/test_namespaces.py +++ b/tests/integration/services/policy_engine/test_namespaces.py @@ -241,7 +241,7 @@ def test_distromappings(initialized_mappings): almalinux7 = DistroNamespace(name="almalinux", version="7", like_distro="rhel") assert almalinux7.mapped_names() == [] assert almalinux7.like_namespace_names == ["rhel:7"] - + assert sorted(DistroMapping.distros_mapped_to("rhel", "7")) == sorted( [ DistroTuple("redhat", "7", "RHEL"), @@ -266,4 +266,4 @@ def test_mapped_distros(initialized_mappings): ] assert DistroMapping.distros_for("almalinux", "8", "rhel") == [ DistroTuple("rhel", "8", "RHEL") - ] + ]