Skip to content

Commit

Permalink
Close loop for RFE:2029402 (#11051)
Browse files Browse the repository at this point in the history
Signed-off-by: Adarsh Dubey <[email protected]>
  • Loading branch information
adarshdubey-star authored Apr 5, 2023
1 parent 984c5d4 commit afefffa
Show file tree
Hide file tree
Showing 5 changed files with 196 additions and 129 deletions.
6 changes: 6 additions & 0 deletions robottelo/cli/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ def ansible_roles_assign(cls, options):
cls.command_sub = 'ansible-roles assign'
return cls.execute(cls._construct_command(options), output_format='csv')

@classmethod
def ansible_roles_add(cls, options):
"""Associate an Ansible role"""
cls.command_sub = 'ansible-roles add'
return cls.execute(cls._construct_command(options), output_format='csv')

@classmethod
def ansible_roles_remove(cls, options=None):
"""Remove ansible roles"""
Expand Down
18 changes: 18 additions & 0 deletions robottelo/cli/hostgroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,24 @@ class HostGroup(Base):

command_base = 'hostgroup'

@classmethod
def ansible_roles_assign(cls, options):
"""Assigns Ansible roles to a hostgroup"""
cls.command_sub = 'ansible-roles assign'
return cls.execute(cls._construct_command(options), output_format='csv')

@classmethod
def ansible_roles_remove(cls, options=None):
"""Disassociate an Ansible role"""
cls.command_sub = 'ansible-roles remove'
return cls.execute(cls._construct_command(options), output_format='csv')

@classmethod
def ansible_roles_add(cls, options):
"""Associate an Ansible role"""
cls.command_sub = 'ansible-roles add'
return cls.execute(cls._construct_command(options), output_format='csv')

@classmethod
def sc_params(cls, options=None):
"""List all smart class parameters
Expand Down
65 changes: 61 additions & 4 deletions tests/foreman/cli/test_ansible.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
:Upstream: No
"""
import pytest
from fauxfactory import gen_string

from robottelo.config import settings

Expand Down Expand Up @@ -50,7 +51,8 @@ def test_positive_ansible_e2e(target_sat, module_org, rhel_contenthost):
:CaseImportance: Critical
"""
SELECTED_ROLE = 'RedHatInsights.insights-client'
SELECTED_VAR = 'insights_variable'
SELECTED_ROLE_1 = 'theforeman.foreman_scap_client'
SELECTED_VAR = gen_string('alpha')
if rhel_contenthost.os_version.major <= 7:
rhel_contenthost.create_custom_repos(rhel7=settings.repos.rhel7_os)
assert rhel_contenthost.execute('yum install -y insights-client').status == 0
Expand All @@ -61,9 +63,14 @@ def test_positive_ansible_e2e(target_sat, module_org, rhel_contenthost):
proxy_id = target_sat.nailgun_smart_proxy.id
target_host = rhel_contenthost.nailgun_host

target_sat.cli.Ansible.roles_sync({'role-names': SELECTED_ROLE, 'proxy-id': proxy_id})
target_sat.cli.Ansible.roles_sync(
{'role-names': f'{SELECTED_ROLE},{SELECTED_ROLE_1}', 'proxy-id': proxy_id}
)

target_sat.cli.Host.ansible_roles_assign({'id': target_host.id, 'ansible-roles': SELECTED_ROLE})
result = target_sat.cli.Host.ansible_roles_add(
{'id': target_host.id, 'ansible-role': SELECTED_ROLE}
)
assert 'Ansible role has been associated.' in result[0]['message']

target_sat.cli.Ansible.variables_create(
{'variable': SELECTED_VAR, 'ansible-role': SELECTED_ROLE}
Expand All @@ -72,7 +79,6 @@ def test_positive_ansible_e2e(target_sat, module_org, rhel_contenthost):
assert SELECTED_ROLE, (
SELECTED_VAR in target_sat.cli.Ansible.variables_info({'name': SELECTED_VAR}).stdout
)

template_id = (
target_sat.api.JobTemplate()
.search(query={'search': 'name="Ansible Roles - Ansible Default"'})[0]
Expand All @@ -92,6 +98,11 @@ def test_positive_ansible_e2e(target_sat, module_org, rhel_contenthost):
result = target_sat.api.JobInvocation(id=job['id']).read()
assert result.succeeded == 1

result = target_sat.cli.Host.ansible_roles_assign(
{'id': target_host.id, 'ansible-roles': f'{SELECTED_ROLE},{SELECTED_ROLE_1}'}
)
assert 'Ansible roles were assigned to the host' in result[0]['message']

result = target_sat.cli.Host.ansible_roles_remove(
{'id': target_host.id, 'ansible-role': SELECTED_ROLE}
)
Expand All @@ -103,3 +114,49 @@ def test_positive_ansible_e2e(target_sat, module_org, rhel_contenthost):
assert SELECTED_ROLE, (
SELECTED_VAR not in target_sat.cli.Ansible.variables_info({'name': SELECTED_VAR}).stdout
)


@pytest.mark.e2e
@pytest.mark.tier2
def test_add_and_remove_ansible_role_hostgroup(target_sat):
"""
Test add and remove functionality for ansible roles in hostgroup via cli
:id: 2c6fda14-4cd2-490a-b7ef-7a08f8164fad
:customerscenario: true
:Steps:
1. Create a hostgroup
2. Sync few ansible roles
3. Assign a few ansible roles with the host group
4. Add some ansible role with the host group
5. Remove the added ansible roles from the host group
:expectedresults:
1. Ansible role assign/add/remove functionality should work as expected in cli
:BZ: 2029402
:CaseAutomation: Automated
"""
ROLES = [
'theforeman.foreman_scap_client',
'redhat.satellite.hostgroups',
'RedHatInsights.insights-client',
]
proxy_id = target_sat.nailgun_smart_proxy.id
hg_name = gen_string('alpha')
result = target_sat.cli.HostGroup.create({'name': hg_name})
assert result['name'] == hg_name
target_sat.cli.Ansible.roles_sync({'role-names': ROLES, 'proxy-id': proxy_id})
result = target_sat.cli.HostGroup.ansible_roles_assign(
{'name': hg_name, 'ansible-roles': f'{ROLES[1]},{ROLES[2]}'}
)
assert 'Ansible roles were assigned to the hostgroup' in result[0]['message']
result = target_sat.cli.HostGroup.ansible_roles_add({'name': hg_name, 'ansible-role': ROLES[0]})
assert 'Ansible role has been associated.' in result[0]['message']
result = target_sat.cli.HostGroup.ansible_roles_remove(
{'name': hg_name, 'ansible-role': ROLES[0]}
)
assert 'Ansible role has been disassociated.' in result[0]['message']
111 changes: 111 additions & 0 deletions tests/foreman/ui/test_ansible.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,3 +267,114 @@ def _finalize():
result = target_sat.cli.Ansible.roles_delete({'name': SELECTED_ROLE})
assert f'Ansible role [{SELECTED_ROLE}] was deleted.' in result[0]['message']
target_sat.execute('rm -rvf /etc/ansible/roles/custom_role')


@pytest.mark.tier2
def test_positive_host_role_information(target_sat, function_host):
"""Assign Ansible Role to a Host and verify that the information
in the new UI is displayed correctly
:id: 7da913ef-3b43-4bfa-9a45-d895431c8b56
:CaseLevel: System
:Steps:
1. Register a RHEL host to Satellite.
2. Import all roles available by default.
3. Assign one role to the RHEL host.
4. Navigate to the new UI for the given Host.
5. Select the 'Ansible' tab, then the 'Inventory' sub-tab.
:expectedresults: Roles assigned directly to the Host are visible on the subtab.
"""
SELECTED_ROLE = 'RedHatInsights.insights-client'

location = function_host.location.read()
organization = function_host.organization.read()
proxy_id = target_sat.nailgun_smart_proxy.id
target_sat.api.AnsibleRoles().sync(data={'proxy_id': proxy_id, 'role_names': [SELECTED_ROLE]})
target_sat.cli.Host.ansible_roles_assign(
{'id': function_host.id, 'ansible-roles': SELECTED_ROLE}
)
host_roles = function_host.list_ansible_roles()
assert host_roles[0]['name'] == SELECTED_ROLE
with target_sat.ui_session() as session:
session.location.select(location.name)
session.organization.select(organization.name)
ansible_roles_table = session.host_new.get_ansible_roles(function_host.name)
assert ansible_roles_table[0]["Name"] == SELECTED_ROLE
all_assigned_roles_table = session.host_new.get_ansible_roles_modal(function_host.name)
assert all_assigned_roles_table[0]["Name"] == SELECTED_ROLE


@pytest.mark.stubbed
@pytest.mark.tier2
def test_positive_role_variable_information(self):
"""Create and assign variables to an Ansible Role and verify that the information in
the new UI is displayed correctly
:id: 4ab2813a-6b83-4907-b104-0473465814f5
:CaseLevel: System
:Steps:
1. Register a RHEL host to Satellite.
2. Import all roles available by default.
3. Create a host group and assign one of the Ansible roles to the host group.
4. Assign the host to the host group.
5. Assign one roles to the RHEL host.
6. Create a variable and associate it with the role assigned to the Host.
7. Create a variable and associate it with the role assigned to the Hostgroup.
8. Navigate to the new UI for the given Host.
9. Select the 'Ansible' tab, then the 'Variables' sub-tab.
:expectedresults: The variables information for the given Host is visible.
"""


@pytest.mark.stubbed
@pytest.mark.tier2
def test_positive_assign_role_in_new_ui(self):
"""Using the new Host UI, assign a role to a Host
:id: 044f38b4-cff2-4ddc-b93c-7e9f2826d00d
:CaseLevel: System
:Steps:
1. Register a RHEL host to Satellite.
2. Import all roles available by default.
3. Navigate to the new UI for the given Host.
4. Select the 'Ansible' tab
5. Click the 'Assign Ansible Roles' button.
6. Using the popup, assign a role to the Host.
:expectedresults: The Role is successfully assigned to the Host, and shows up on the UI
"""


@pytest.mark.stubbed
@pytest.mark.tier2
def test_positive_remove_role_in_new_ui(self):
"""Using the new Host UI, remove the role(s) of a Host
:id: d6de5130-45f6-4349-b490-fbde2aed082c
:CaseLevel: System
:Steps:
1. Register a RHEL host to Satellite.
2. Import all roles available by default.
3. Assign a role to the host.
4. Navigate to the new UI for the given Host.
5. Select the 'Ansible' tab
6. Click the 'Edit Ansible roles' button.
7. Using the popup, remove the assigned role from the Host.
:expectedresults: The Role is successfully removed from the Host, and no longer shows
up on the UI
"""
125 changes: 0 additions & 125 deletions tests/foreman/ui/test_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -2489,131 +2489,6 @@ def test_positive_set_multi_line_and_with_spaces_parameter_value(
assert host_parameters[param_name] == param_value


@pytest.mark.tier2
def test_positive_host_role_information(target_sat, function_host):
"""Assign Ansible Role to a Host and verify that the information
in the new UI is displayed correctly
:id: 7da913ef-3b43-4bfa-9a45-d895431c8b56
:caseComponent: Ansible
:Team: Rocket
:CaseLevel: System
:Steps:
1. Register a RHEL host to Satellite.
2. Import all roles available by default.
3. Assign one role to the RHEL host.
4. Navigate to the new UI for the given Host.
5. Select the 'Ansible' tab, then the 'Inventory' sub-tab.
:expectedresults: Roles assigned directly to the Host are visible on the subtab.
"""
SELECTED_ROLE = 'RedHatInsights.insights-client'

location = function_host.location.read()
organization = function_host.organization.read()
proxy_id = target_sat.nailgun_smart_proxy.id
target_sat.api.AnsibleRoles().sync(data={'proxy_id': proxy_id, 'role_names': [SELECTED_ROLE]})
function_host.assign_ansible_roles(data={'ansible_role_ids': [1]})
host_roles = function_host.list_ansible_roles()
assert host_roles[0]['name'] == SELECTED_ROLE
with target_sat.ui_session() as session:
session.location.select(location.name)
session.organization.select(organization.name)
ansible_roles_table = session.host_new.get_ansible_roles(function_host.name)
assert ansible_roles_table[0]["Name"] == SELECTED_ROLE
all_assigned_roles_table = session.host_new.get_ansible_roles_modal(function_host.name)
assert all_assigned_roles_table[0]["Name"] == SELECTED_ROLE


@pytest.mark.stubbed
@pytest.mark.tier2
def test_positive_role_variable_information(self):
"""Create and assign variables to an Ansible Role and verify that the information in
the new UI is displayed correctly
:id: 4ab2813a-6b83-4907-b104-0473465814f5
:caseComponent: Ansible
:Team: Rocket
:CaseLevel: System
:Steps:
1. Register a RHEL host to Satellite.
2. Import all roles available by default.
3. Create a host group and assign one of the Ansible roles to the host group.
4. Assign the host to the host group.
5. Assign one roles to the RHEL host.
6. Create a variable and associate it with the role assigned to the Host.
7. Create a variable and associate it with the role assigned to the Hostgroup.
8. Navigate to the new UI for the given Host.
9. Select the 'Ansible' tab, then the 'Variables' sub-tab.
:expectedresults: The variables information for the given Host is visible.
"""


@pytest.mark.stubbed
@pytest.mark.tier2
def test_positive_assign_role_in_new_ui(self):
"""Using the new Host UI, assign a role to a Host
:id: 044f38b4-cff2-4ddc-b93c-7e9f2826d00d
:caseComponent: Ansible
:Team: Rocket
:CaseLevel: System
:Steps:
1. Register a RHEL host to Satellite.
2. Import all roles available by default.
3. Navigate to the new UI for the given Host.
4. Select the 'Ansible' tab
5. Click the 'Assign Ansible Roles' button.
6. Using the popup, assign a role to the Host.
:expectedresults: The Role is successfully assigned to the Host, and shows up on the UI
"""


@pytest.mark.stubbed
@pytest.mark.tier2
def test_positive_remove_role_in_new_ui(self):
"""Using the new Host UI, remove the role(s) of a Host
:id: d6de5130-45f6-4349-b490-fbde2aed082c
:caseComponent: Ansible
:Team: Rocket
:CaseLevel: System
:Steps:
1. Register a RHEL host to Satellite.
2. Import all roles available by default.
3. Assign a role to the host.
4. Navigate to the new UI for the given Host.
5. Select the 'Ansible' tab
6. Click the 'Edit Ansible roles' button.
7. Using the popup, remove the assigned role from the Host.
:expectedresults: The Role is successfully removed from the Host, and no longer shows
up on the UI
"""


@pytest.mark.tier2
@pytest.mark.rhel_ver_match('[^6].*')
def test_positive_tracer_enable_reload(tracer_install_host, target_sat):
Expand Down

0 comments on commit afefffa

Please sign in to comment.