From 2794c36371ada110070424c8843fad9f0250f7f8 Mon Sep 17 00:00:00 2001 From: Shubham Ganar Date: Wed, 20 Mar 2024 22:46:32 +0530 Subject: [PATCH] Add closed loop BZ#2250397 Signed-off-by: Shubham Ganar --- tests/foreman/cli/test_registration.py | 43 +++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/tests/foreman/cli/test_registration.py b/tests/foreman/cli/test_registration.py index e3bc35fa58b..f16f13013be 100644 --- a/tests/foreman/cli/test_registration.py +++ b/tests/foreman/cli/test_registration.py @@ -11,9 +11,11 @@ :Team: Rocket """ +import json import re +from tempfile import mkstemp -from fauxfactory import gen_string +from fauxfactory import gen_mac, gen_string import pytest from robottelo.config import settings @@ -224,3 +226,42 @@ def test_negative_global_registration_without_ak(module_target_sat): 'Failed to generate registration command:\n Missing activation key!' in context.value.message ) + + +def test_positive_custom_facts_for_host_registration( + module_sca_manifest_org, + module_location, + module_target_sat, + rhel8_contenthost, + module_activation_key, +): + """Attempt to register a host and check all the interfaces are created from the custom facts + + :id: db73c146-4557-4bf4-a8e2-950ecba31620 + + :steps: + 1. Register the host. + 2. Check the host is registered and all the interfaces are created successfully. + + :expectedresults: Host registered successfully with all interfaces created from the custom facts. + + :BZ: 2250397 + + :customerscenario: true + """ + facts = { + f"net.interface.{gen_string('alphanumeric')}.mac_address": gen_mac(), + f"net.interface.{gen_string('alpha')}.{gen_string('numeric')}.mac_address": gen_mac(), + f"net.interface.{gen_string('alpha')}.{gen_string('numeric')}.mac_address": gen_mac(), + } + _, facts_file = mkstemp(suffix='.facts') + with open(facts_file, "w") as f: + json.dump(facts, f, indent=4) + rhel8_contenthost.put(facts_file, '/etc/rhsm/facts/') + org = module_sca_manifest_org + result = rhel8_contenthost.register( + org, module_location, [module_activation_key.name], module_target_sat + ) + assert result.status == 0, f'Failed to register host: {result.stderr}' + host_info = module_target_sat.cli.Host.info({'name': rhel8_contenthost.hostname}) + assert len(list(facts)) == len(host_info['network-interfaces'])