From 0cab4e120fcb1882b8d376833554fe0e8c092bbd Mon Sep 17 00:00:00 2001 From: Cole Higgins Date: Tue, 7 Jan 2025 06:39:52 -0500 Subject: [PATCH] Update set_infrastructure _type for RHCloud (#17196) * Update set infra type rhcloud * update docstring (cherry picked from commit 227ac44a2cc7e8c6d7cf41fdf96bc1754debe81e) --- robottelo/hosts.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/robottelo/hosts.py b/robottelo/hosts.py index 662c6d7a71..d860525f56 100644 --- a/robottelo/hosts.py +++ b/robottelo/hosts.py @@ -1147,19 +1147,27 @@ def unregister_insights(self): raise ContentHostError('Failed to unregister client from Insights through Satellite') def set_infrastructure_type(self, infrastructure_type='physical'): - """Force host to appear as bare-metal orbroker virtual machine in - subscription-manager fact. + """Force host to appear as bare-metal or virtual machine in subscription-manager fact. :param str infrastructure_type: One of 'physical', 'virtual' """ - script_path = '/usr/sbin/virt-what' - self.execute(f'cp -n {script_path} {script_path}.old') + # Remove the custom facts file if it exists + self.execute('rm -f /etc/rhsm/facts/custom.facts') - script_content = ['#!/bin/sh -'] + # Define the path for the physical facts file + script_path = '/etc/rhsm/facts/physical.facts' + + # Prepare facts content based on infrastructure type if infrastructure_type == 'virtual': - script_content.append('echo kvm') - script_content = '\n'.join(script_content) - self.execute(f"echo -e '{script_content}' > {script_path}") + facts_content = '{"virt.is_guest": "true"}' + else: + facts_content = '{"virt.is_guest": "false"}' + + # Create the physical facts file and write the appropriate content + self.execute(f"echo '{facts_content}' > {script_path}") + + # Update subscription manager facts + self.execute('subscription-manager facts --update') def patch_os_release_version(self, distro='rhel7'): """Patch VM OS release version.