From 655378f8dde1c6f8c2acde3cef02f5c2deadfbf8 Mon Sep 17 00:00:00 2001 From: shwsingh Date: Thu, 2 May 2024 11:51:15 +0530 Subject: [PATCH] Add tests for Facts component --- tests/foreman/cli/test_fact.py | 76 +++++++++++++++++++++++++++++++++- 1 file changed, 75 insertions(+), 1 deletion(-) diff --git a/tests/foreman/cli/test_fact.py b/tests/foreman/cli/test_fact.py index 7913d68287c..27310c9dbf5 100644 --- a/tests/foreman/cli/test_fact.py +++ b/tests/foreman/cli/test_fact.py @@ -12,7 +12,7 @@ """ -from fauxfactory import gen_string +from fauxfactory import gen_ipaddr, gen_mac, gen_string import pytest pytestmark = [pytest.mark.tier1] @@ -61,3 +61,77 @@ def test_negative_list_by_name(module_target_sat): assert ( module_target_sat.cli.Fact().list(options={'search': f'fact={gen_string("alpha")}'}) == [] ) + + +@pytest.mark.no_containers +def test_positive_update_client_facts( + module_target_sat, rhel8_contenthost, module_org, module_location, module_activation_key +): + """Update client facts and verify the facts are updated on Satellite. + + :id: ea94ccb7-a125-4be3-932a-bfcb035d3604 + + :steps: + 1. Add another interface to the host. + 2. Update the facts on the Satellite. + 3. Verify that the facts are updated on the Satellite. + + :expectedresults: Facts are successfully updated on the Satellite. + """ + client = rhel8_contenthost + mac_address = gen_mac(multicast=False) + ip = gen_ipaddr() + # Create eth1 interface on the host + add_interface_command = f'ip link add eth1 type dummy;ifconfig eth1 hw ether {mac_address};ip addr add {ip}/24 brd + dev eth1 label eth1:1;ip link set dev eth1 up' + result = client.execute(add_interface_command) + assert result.status == 0 + command = module_target_sat.api.RegistrationCommand( + organization=module_org, + location=module_location, + activation_keys=[module_activation_key.name], + update_packages=True, + remote_execution_interface='eth1', + ).create() + result = client.execute(command) + assert result.status == 0, f'Failed to register host: {result.stderr}' + facts = module_target_sat.cli.Fact().list() + assert ip in facts + + +@pytest.mark.rhel_ver_match('8') +@pytest.mark.no_containers +def test_positive_upload_host_facts( + module_target_sat, + rhel_contenthost, + module_sca_manifest_org, + module_location, + module_activation_key, +): + """Verify Facts option is available on UI and it is successfully updated on Satellite after registeration + + :id: f32093d2-4088-4025-9623-adb3141bd770 + + :steps: + 1. Register host to Satellite. + 2. Navigate to the Host page and click on side caret. + 3. Verify that the facts option is available and should be updated on Satellite. + + :expectedresults: Facts option should be available to Host UI and all the facts of the host are updated on Satellite. + + :BZ: 2001552 + + :customerscenario: true + """ + with module_target_sat.ui_session() as session: + session.organization.select(module_sca_manifest_org.name) + session.location.select(module_location.name) + cmd = session.host.get_register_command( + { + 'general.activation_keys': module_activation_key.name, + 'general.insecure': True, + } + ) + result = rhel_contenthost.execute(cmd) + assert result.status == 0, f'Failed to register host: {result.stderr}' + host_facts = session.host_new.read_host_facts(rhel_contenthost.hostname) + assert host_facts is not None