Skip to content

Commit

Permalink
feat: Add option to run smoke tests with fake IMDS servers.
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jirihnidek authored and m-horky committed Jun 5, 2024
1 parent 0de0c38 commit b6fad11
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/cloud_what/providers/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down
8 changes: 8 additions & 0 deletions src/cloud_what/providers/azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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()
Expand Down
5 changes: 5 additions & 0 deletions src/cloud_what/providers/gcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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()
Expand Down

0 comments on commit b6fad11

Please sign in to comment.