From 55b319aa619ca0f7310ef3f7a544e04251ea20a4 Mon Sep 17 00:00:00 2001 From: Gaurav Talreja Date: Tue, 12 Sep 2023 20:50:18 +0530 Subject: [PATCH] Add automation for BZ 2024175 Signed-off-by: Gaurav Talreja (cherry picked from commit 59980dd3a970b00e4a24573c894c863c47d40d9f) --- .../foreman/api/test_provisioningtemplate.py | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/tests/foreman/api/test_provisioningtemplate.py b/tests/foreman/api/test_provisioningtemplate.py index cf8225bb933..fb7a9de3b1c 100644 --- a/tests/foreman/api/test_provisioningtemplate.py +++ b/tests/foreman/api/test_provisioningtemplate.py @@ -23,6 +23,7 @@ import pytest from fauxfactory import gen_choice +from fauxfactory import gen_integer from fauxfactory import gen_mac from fauxfactory import gen_string from nailgun import client @@ -474,3 +475,60 @@ def test_positive_template_subnet_with_boot_mode( for template in pxe_templates: rendered = host.read_template(data={'template_kind': f'{template}'})['template'] assert f'ks={ks_param}' in rendered + + @pytest.mark.parametrize('module_sync_kickstart_content', [8], indirect=True) + def test_positive_template_check_aap_snippet( + self, + module_sync_kickstart_content, + module_target_sat, + module_sca_manifest_org, + module_location, + module_default_org_view, + module_lce_library, + default_architecture, + default_partitiontable, + ): + """Read the kickstart default template and verify ansible_provisioning_callback + snippet is rendered correctly + + :id: 065ef48f-bec5-4535-8be7-d8527fa21564 + + :expectedresults: Rendered template should contain values set for AAP snippet + host parameter for respective rhel hosts. + + :BZ: 2024175 + + :customerscenario: true + """ + aap_fqdn = 'env-aap.example.com' + template_id = gen_integer(1, 10) + extra_vars_dict = '{"package_install": "zsh"}' + config_key = gen_string('alpha') + host_params = [ + {'name': 'ansible_tower_provisioning', 'value': 'true', 'parameter_type': 'boolean'}, + {'name': 'ansible_tower_fqdn', 'value': aap_fqdn, 'parameter_type': 'string'}, + {'name': 'ansible_host_config_key', 'value': config_key, 'parameter_type': 'string'}, + {'name': 'ansible_job_template_id', 'value': template_id, 'parameter_type': 'integer'}, + {'name': 'ansible_extra_vars', 'value': extra_vars_dict, 'parameter_type': 'string'}, + ] + host = module_target_sat.api.Host( + organization=module_sca_manifest_org, + location=module_location, + name=gen_string('alpha').lower(), + operatingsystem=module_sync_kickstart_content.os, + architecture=default_architecture, + domain=module_sync_kickstart_content.domain, + root_pass=settings.provisioning.host_root_password, + ptable=default_partitiontable, + content_facet_attributes={ + 'content_source_id': module_target_sat.nailgun_smart_proxy.id, + 'content_view_id': module_default_org_view.id, + 'lifecycle_environment_id': module_lce_library.id, + }, + host_parameters_attributes=host_params, + ).create() + render = host.read_template(data={'template_kind': 'provision'})['template'] + assert f'https://{aap_fqdn}/api/v2/job_templates/{template_id}/callback/' in render + assert 'systemctl enable ansible-callback' in render + assert f'"host_config_key":"{config_key}"' in render + assert '{"package_install": "zsh"}' in render