From a216f096613dda49c48b5dc598ce7b571e539b40 Mon Sep 17 00:00:00 2001 From: Anja Strunk Date: Fri, 26 Apr 2024 09:01:07 +0200 Subject: [PATCH] Fix unit tests Signed-off-by: Anja Strunk --- .gitignore | 1 + config/config.yaml | 2 +- cli.py => generator/cli.py | 2 +- generator/common/const.py | 25 +++++++++-------- .../openstack/vm_images_discovery.py | 28 +++++++++---------- generator/wallet/filesystem_wallet.py | 1 + tests/test_cli.py | 2 +- 7 files changed, 32 insertions(+), 29 deletions(-) rename cli.py => generator/cli.py (98%) diff --git a/.gitignore b/.gitignore index 500c242..dacab84 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ __pycache__/ devops/logs/ devops/plugins/ node_modules +.gx-credentials/ *.tar.gz # Make sure credentials not push to the repo os_secret diff --git a/config/config.yaml b/config/config.yaml index 6c343c7..5d851e3 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -10,7 +10,7 @@ wallet: path: /etc/gaia-x/wallet/ Gaia-X: -# DO NOT change, unless you will override default settings for Gaia-X mandatory attributes +# DO NOT change these values, unless you want to override default settings for Gaia-X mandatory attributes software resources: Alpine Linux: copyright owner: "Alpine Linux" diff --git a/cli.py b/generator/cli.py similarity index 98% rename from cli.py rename to generator/cli.py index 6764be2..3873f6e 100755 --- a/cli.py +++ b/generator/cli.py @@ -81,7 +81,7 @@ def openstack(cloud, timeout, config): os_cloud = OsCloud(conn, Config(config_dict)) # init wallet - if config_dict["wallet"] == const.CONFIG_WALLETS: + if config_dict["wallet"] == const.CONFIG_WALLET: wallet = FileSystemWallet(config_dict["wallet"]) # run discovery diff --git a/generator/common/const.py b/generator/common/const.py index 04ba5ff..cf886c1 100644 --- a/generator/common/const.py +++ b/generator/common/const.py @@ -2,14 +2,23 @@ Constants used by SCS GX Credential Generator. """ +# general configuration keys DEFAULT_RESOURCE_POLICY = "default: allow intent" -DEFAULT_FIRMWARE_TYPE = "other" +#DEFAULT_FIRMWARE_TYPE = "other" DEFAULT_WATCHDOG_ACTION = "none" +CONFIG_FILE = "config/config.yaml" +CONFIG_WALLET = "wallet" + +# Wallet keys +CONFIG_FILESYSTEM_WALLET = "filesystem" +CONFIG_XFSC_WALLET = "xfsc" +# Metrics UNIT_MB = "https://qudt.org/vocab/unit/MegaBYTE" UNIT_GB = "https://qudt.org/vocab/unit/GigaBYTE" UNIT_GHZ = "https://qudt.org/vocab/unit/GigaHZ" +# Config keys for DID management CONFIG_DID = "DIDs" CONFIG_CPS_DID = "csp_did" CONFIG_IAAS_DID = "iaas_did" @@ -17,6 +26,7 @@ CONFIG_GAX = "Gaia-X" CONFIG_SOFTWARE = "software resources" + CONFIG_VM_IMAGE = "vm image" CONFIG_RESOURCE_POLICY = "resource policy" CONFIG_LICENSE = "license" @@ -28,10 +38,9 @@ CONFIG_DEFAULT = "default" CONFIG_CLOUD_RESOURCES = "cloud resources:" -CONFIG_FILESYSTEM_WALLET = "filesystem" -CONFIG_XFSC_WALLET = "xfsc" +# Operating System types offered by Gaia-X CONFIG_OS_ALP = "Alpine Linux" CONFIG_OS_ARCH = "Arch Linux" CONFIG_OS_CENTOS = "CentOS Linux" @@ -57,6 +66,7 @@ CONFIG_OS_CIRROS = "CirrOS" CONFIG_OS_ALMA_LINUX = "AlmaLinux" +# Hypervisor types offered by Gaia-X CONFIG_HV_KVM = "KVM" CONFIG_HV_QUEMU = "quemu" CONFIG_HV_XEN = "Xen" @@ -65,12 +75,3 @@ CONFIG_HV_VMW = "vmware" CONFIG_HV_HYV = "hyper-v" -CONFIG_HV_KVM = "KVM" -CONFIG_HV_QUEMU = "quemu" -CONFIG_HV_XEN = "Xen" -CONFIG_HV_ESXI = "ESXi" -CONFIG_HV_CH = "Cloud Hypervisor" -CONFIG_HV_VMW = "vmware" -CONFIG_HV_HYV = "hyper-v" - -CONFIG_FILE = "config/config.yaml" diff --git a/generator/discovery/openstack/vm_images_discovery.py b/generator/discovery/openstack/vm_images_discovery.py index 4b74ac4..637a4fb 100644 --- a/generator/discovery/openstack/vm_images_discovery.py +++ b/generator/discovery/openstack/vm_images_discovery.py @@ -306,7 +306,7 @@ def _get_operation_system(self, os_image: OS_Image) -> OperatingSystem: resourcePolicy=self.conf.get_resource_policy(const.CONFIG_OS_ARCH), copyrightOwnedBy=self.conf.get_copyright_owner(const.CONFIG_OS_ARCH), license=self._get_license_list( - self.self.conf.get_license(const.CONFIG_OS_ARCH) + self.conf.get_license(const.CONFIG_OS_ARCH) ), ) elif os_image.os_distro.lower() == "centos": @@ -430,7 +430,7 @@ def _get_operation_system(self, os_image: OS_Image) -> OperatingSystem: const.CONFIG_OS_NETBSD ), license=self._get_license_list( - self.self.conf.get_license(const.CONFIG_OS_NETBSD) + self.conf.get_license(const.CONFIG_OS_NETBSD) ), ) elif os_image.os_distro.lower() == "netware": @@ -491,13 +491,12 @@ def _get_operation_system(self, os_image: OS_Image) -> OperatingSystem: return OperatingSystem( version=os_image.os_version, osDistribution=const.CONFIG_OS_SUSE, - resourcePolicy=self._get_resource_policy_for_os(const.CONFIG_OS_SUSE), - copyrightOwnedBy=self._get_copyright_owner_for_os( + resourcePolicy=self.conf.get_resource_policy(const.CONFIG_OS_SUSE), + copyrightOwnedBy=self.conf.get_copyright_owner( const.CONFIG_OS_OPEN_SUSE ), - license=self._get_license_list( - self._get_license_for_os(const.CONFIG_OS_SUSE) - ), + license=self._get_license_list( self.conf.get_license(const.CONFIG_OS_SUSE) + ) ) elif os_image.os_distro.lower() == "rocky": return OperatingSystem( @@ -573,23 +572,24 @@ def _get_operation_system(self, os_image: OS_Image) -> OperatingSystem: elif os_image.os_distro.lower() == "almalinux": return OperatingSystem( version=os_image.os_version, - osDistribution=const.CONFIG_OS_ALMALINUX, - resourcePolicy=self.conf.get_resource_policy(const.CONFIG_OS_ALMALINUX + osDistribution=const.CONFIG_OS_ALMA_LINUX, + resourcePolicy=self.conf.get_resource_policy(const.CONFIG_OS_ALMA_LINUX ), copyrightOwnedBy=self.conf.get_copyright_owner( - const.CONFIG_OS_ALMALINUX + const.CONFIG_OS_ALMA_LINUX + ), license=self._get_license_list( self.conf.get_license(const.CONFIG_OS_ALMA_LINUX) - ), + ) ) elif os_image.os_distro.lower() == "alpinelinux": return OperatingSystem( version=os_image.os_version, osDistribution=const.CONFIG_OS_ALP, - resourcePolicy=self._get_resource_policy_for_os(const.CONFIG_OS_ALP), - copyrightOwnedBy=self._get_copyright_owner_for_os(const.CONFIG_OS_ALP), + resourcePolicy=self.conf.get_resource_policy(const.CONFIG_OS_ALP), + copyrightOwnedBy=self.conf.get_copyright_owner(const.CONFIG_OS_ALP), license=self._get_license_list( - self.conf.get_license(const.CONFIG_OS_ALMALINUX) + self.conf.get_license(const.CONFIG_OS_ALP) ), ) else: diff --git a/generator/wallet/filesystem_wallet.py b/generator/wallet/filesystem_wallet.py index db3c573..a6270a8 100644 --- a/generator/wallet/filesystem_wallet.py +++ b/generator/wallet/filesystem_wallet.py @@ -63,6 +63,7 @@ def _filter_graph_by_subject(self, graph: Graph, subject: str) -> Graph: for s, p, o in graph: if s == subject: # geht das auch mit einer Sparql Anfrage + pass diff --git a/tests/test_cli.py b/tests/test_cli.py index 6aad2c9..22eec8b 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -6,7 +6,7 @@ from openstack.compute.v2.flavor import Flavor as OS_Flavor from openstack.image.v2.image import Image as OS_Image -import cli +from generator import cli from generator.common import const from tests.common import MockConnection, get_absolute_path