-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Verify a variable created and added to the host #14477
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -275,6 +275,81 @@ def test_positive_host_role_information(target_sat, function_host): | |
assert all_assigned_roles_table[0]["Name"] == SELECTED_ROLE | ||
|
||
|
||
@pytest.mark.rhel_ver_match('8') | ||
def test_positive_assign_ansible_role_variable_on_host( | ||
target_sat, rhel_contenthost, module_activation_key, module_org, module_location, request | ||
): | ||
"""Verify ansible variable is added to the role and attached to the host. | ||
:id: 7ec4fe19-5a08-4b10-bb4e-7327dd68699a | ||
:BZ: 2170727 | ||
:customerscenario: true | ||
:steps: | ||
1. Create an Ansible variable with array type and set the default value. | ||
2. Enable both 'Merge Overrides' and 'Merge Default'. | ||
3. Add the variable to a role and attach the role to the host. | ||
4. Verify that ansible role and variable is added to the host. | ||
:expectedresults: The role and variable is successfully added to the host. | ||
""" | ||
|
||
@request.addfinalizer | ||
def _finalize(): | ||
result = target_sat.cli.Ansible.roles_delete({'name': SELECTED_ROLE}) | ||
assert f'Ansible role [{SELECTED_ROLE}] was deleted.' in result[0]['message'] | ||
|
||
key = gen_string('alpha') | ||
SELECTED_ROLE = 'redhat.satellite.activation_keys' | ||
proxy_id = target_sat.nailgun_smart_proxy.id | ||
target_sat.api.AnsibleRoles().sync(data={'proxy_id': proxy_id, 'role_names': [SELECTED_ROLE]}) | ||
command = target_sat.api.RegistrationCommand( | ||
organization=module_org, | ||
location=module_location, | ||
activation_keys=[module_activation_key.name], | ||
).create() | ||
result = rhel_contenthost.execute(command) | ||
assert result.status == 0, f'Failed to register host: {result.stderr}' | ||
target_host = rhel_contenthost.nailgun_host | ||
default_value = '[\"test\"]' | ||
parameter_type = 'array' | ||
with target_sat.ui_session() as session: | ||
session.organization.select(org_name=module_org.name) | ||
session.location.select(loc_name=module_location.name) | ||
session.ansiblevariables.create_with_overrides( | ||
{ | ||
'key': key, | ||
'ansible_role': SELECTED_ROLE, | ||
'override': 'true', | ||
Gauravtalreja1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
'parameter_type': parameter_type, | ||
'default_value': default_value, | ||
'validator_type': None, | ||
'attribute_order': 'domain \n fqdn \n hostgroup \n os', | ||
'merge_default': 'true', | ||
'merge_overrides': 'true', | ||
'matcher_section.params': [ | ||
{ | ||
'attribute_type': {'matcher_key': 'os', 'matcher_value': 'fedora'}, | ||
'value': '[\'13\']', | ||
} | ||
], | ||
} | ||
) | ||
result = target_sat.cli.Host.ansible_roles_assign( | ||
{'id': target_host.id, 'ansible-roles': SELECTED_ROLE} | ||
) | ||
assert 'Ansible roles were assigned' in result[0]['message'] | ||
values = session.host_new.get_details(rhel_contenthost.hostname, 'ansible')['ansible'][ | ||
'variables' | ||
]['table'] | ||
Comment on lines
+345
to
+347
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add a check for verifying the assigned role here first on host then variable? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We already have the test for it test_positive_host_role_information, so if you agree on this we can combine this too and remove the existing test? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't matter here. But I can surely add it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. well, you're asserting for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am verifying the role has been assigned to the variable which is needed for the this test. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. its a good thing to check, but its fine, we can skip this check for now |
||
assert (key, SELECTED_ROLE, default_value, parameter_type) in [ | ||
(var['Name'], var['Ansible role'], var['Value'], var['Type']) for var in values | ||
] | ||
|
||
|
||
Gauravtalreja1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@pytest.mark.stubbed | ||
@pytest.mark.tier2 | ||
def test_positive_role_variable_information(self): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you're not using the host here, so you could skip the rhel_contenthost and its registration, instead create a fake host without registration and assign the role directly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to use the actual host here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either way, this should be setup.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, it is part of setup, but we're using fake hosts everywhere for such tests for Ansible component, also this will make the execution faster and will save time for unnecessary checkout of actual host
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is using container so it doesn't take much time.