From b6fad11e7783ae414fe88fdecee57d8db5c8e292 Mon Sep 17 00:00:00 2001 From: Jiri Hnidek Date: Fri, 2 Feb 2024 11:43:42 +0100 Subject: [PATCH] feat: Add option to run smoke tests with fake IMDS servers. * This change allow to run smoke tests of cloud provider with custom facts. Examples of custom facts are described in comments for each cloud provider --- src/cloud_what/providers/aws.py | 10 ++++++++++ src/cloud_what/providers/azure.py | 8 ++++++++ src/cloud_what/providers/gcp.py | 5 +++++ 3 files changed, 23 insertions(+) diff --git a/src/cloud_what/providers/aws.py b/src/cloud_what/providers/aws.py index 261b364534..53275154ab 100644 --- a/src/cloud_what/providers/aws.py +++ b/src/cloud_what/providers/aws.py @@ -383,6 +383,7 @@ def _smoke_tests(): """ # Gather only information about hardware and virtualization from rhsmlib.facts.host_collector import HostCollector + from rhsmlib.facts.custom import CustomFactsCollector import sys root = logging.getLogger() @@ -396,6 +397,15 @@ def _smoke_tests(): facts = {} facts.update(HostCollector().get_all()) + # To test AWS cloud provider on localhost create following file + # /etc/rhsm/facts/aws.facts + # { + # "virt.is_guest": true, + # "dmi.bios.version": "amazon", + # "dmi.bios.vendor": "Amazon EC2", + # "virt.host_type": "aws" + # } + facts.update(CustomFactsCollector().get_all()) aws_cloud_provider = AWSCloudProvider(facts) result = aws_cloud_provider.is_running_on_cloud() probability = aws_cloud_provider.is_likely_running_on_cloud() diff --git a/src/cloud_what/providers/azure.py b/src/cloud_what/providers/azure.py index a02bb9b18e..cb0bf6d06e 100644 --- a/src/cloud_what/providers/azure.py +++ b/src/cloud_what/providers/azure.py @@ -259,6 +259,7 @@ def _smoke_tests(): """ # Gather only information about hardware and virtualization from rhsmlib.facts.host_collector import HostCollector + from rhsmlib.facts.custom import CustomFactsCollector import sys @@ -273,6 +274,13 @@ def _smoke_tests(): facts = {} facts.update(HostCollector().get_all()) + # To test Azure cloud provider on localhost create following file + # /etc/rhsm/facts/azure.facts + # { + # "virt.is_guest": true, + # "dmi.chassis.asset_tag": "7783-7084-3265-9085-8269-3286-77" + # } + facts.update(CustomFactsCollector().get_all()) azure_cloud_provider = AzureCloudProvider(facts) result = azure_cloud_provider.is_running_on_cloud() probability = azure_cloud_provider.is_likely_running_on_cloud() diff --git a/src/cloud_what/providers/gcp.py b/src/cloud_what/providers/gcp.py index 54a38f004d..4f5e26bb8d 100644 --- a/src/cloud_what/providers/gcp.py +++ b/src/cloud_what/providers/gcp.py @@ -349,6 +349,7 @@ def _smoke_test(): """ # Gather only information about hardware and virtualization from rhsmlib.facts.host_collector import HostCollector + from rhsmlib.facts.custom import CustomFactsCollector import sys @@ -363,6 +364,10 @@ def _smoke_test(): facts = {} facts.update(HostCollector().get_all()) + # To test Azure cloud provider on localhost create following file + # /etc/rhsm/facts/gcp.facts + # + facts.update(CustomFactsCollector().get_all()) gcp_cloud_provider = GCPCloudProvider(facts) result = gcp_cloud_provider.is_running_on_cloud() probability = gcp_cloud_provider.is_likely_running_on_cloud()