Skip to content
This repository has been archived by the owner on Apr 7, 2022. It is now read-only.

[RFR] Parametrize Tower tests on API version #9888

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions cfme/fixtures/ansible_tower.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from urllib.parse import urlparse

import fauxfactory
import pytest

from cfme.rest.gen_data import _creating_skeleton
from cfme.utils.blockers import GH
from cfme.utils.update import update


def ansible_tower_dialog_rest(request, appliance):
Expand Down Expand Up @@ -124,3 +127,30 @@ def ansible_tower_dialog(request, appliance):

if appliance.version < '5.11' or not GH(8836).blocks:
service_dialog.delete_if_exists()


@pytest.fixture
def ansible_api_version_change(provider, ansible_api_version):
"""Fixture to update Tower url to /api/v2 so that API v2 can be tested.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌 Thanks for the thorough docblock!


API version defaults to v1. So, if no version is specified, v1 is used except for things
which don't exist on v1.
If v2 is specified, v2 is used for everything.

Ansible Tower 3.4, 3.5 support both API v1 and v2.
API v1 has been fully deprecated in Ansible Tower 3.6 and Tower 3.6 supports API v2 only.

"""
parsed = urlparse(provider.url)

if ansible_api_version == 'v2':
updated_url = f'{parsed.scheme}://{parsed.netloc}/api/{ansible_api_version}'
original_url = provider.url
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, but I would do two things here:

  1. move this assignment of original_url outside of the logic blocks, so that we don't hit any UnboundLocals
  2. Make the url update regardless of ansible_api_version, so that its always explicitly set to what the test parameter is.

If we're not explicitly setting it, we risk running into situations where fixture/parameter scope, or the URL defined for the provider in the yaml, will result in the provider's configuration not matching the parametrized value for API.

This way we can remove the logic here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

with update(provider, validate_credentials=True):
provider.url = updated_url

yield

if ansible_api_version != 'v1':
with update(provider, validate_credentials=True):
provider.url = original_url
2 changes: 1 addition & 1 deletion cfme/infrastructure/config_management/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ def update(self, updates, cancel=False, validate_credentials=False):
else:
view.entities.save.click()
view.flash.assert_success_message(
'{} Provider "{}" was updated'.format(self.ui_type, updates['name'] or self.name))
'{} Provider "{}" was updated'.format(self.ui_type, self.name))
self.__dict__.update(**updates)

def delete(self, cancel=False, wait_deleted=True, force=False):
Expand Down
13 changes: 8 additions & 5 deletions cfme/tests/services/test_ansible_workflow_servicecatalogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
pytest.mark.tier(2),
pytest.mark.provider([AnsibleTowerProvider], scope='module'),
pytest.mark.usefixtures('setup_provider'),
pytest.mark.parametrize('workflow_type', ['multiple_job_workflow', 'inventory_sync_workflow'],
ids=['multiple_job_workflow', 'inventory_sync_workflow'],
scope='module'),
pytest.mark.parametrize('ansible_api_version', ['v1', 'v2']),
pytest.mark.ignore_stream('upstream')
]

Expand All @@ -41,8 +39,11 @@ def ansible_workflow_catitem(appliance, provider, dialog, catalog, workflow_type
catalog_item.delete_if_exists()


@pytest.mark.parametrize('workflow_type', ['multiple_job_workflow', 'inventory_sync_workflow'],
ids=['multiple_job_workflow', 'inventory_sync_workflow'], scope='module')
@pytest.mark.meta(automates=[BZ(1719051)])
def test_tower_workflow_item(appliance, ansible_workflow_catitem):
def test_tower_workflow_item(appliance, ansible_workflow_catitem, workflow_type,
ansible_api_version_change):
"""Tests ordering of catalog items for Ansible Workflow templates
Metadata:
test_flag: provision
Expand All @@ -68,7 +69,9 @@ def test_tower_workflow_item(appliance, ansible_workflow_catitem):
)


def test_retire_ansible_workflow(appliance, ansible_workflow_catitem):
@pytest.mark.parametrize('workflow_type', ['multiple_job_workflow'], ids=['multiple_job_workflow'])
def test_retire_ansible_workflow(appliance, ansible_workflow_catitem, workflow_type,
ansible_api_version_change):
"""Tests retiring of catalog items for Ansible Workflow templates
Metadata:
test_flag: provision
Expand Down
18 changes: 11 additions & 7 deletions cfme/tests/services/test_config_provider_servicecatalogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@
pytest.mark.provider([AnsibleTowerProvider], scope='module'),
pytest.mark.usefixtures('setup_provider'),
pytest.mark.tier(2),
pytest.mark.parametrize('job_type', ['template', 'template_limit', 'template_survey',
'textarea_survey'],
ids=['template_job', 'template_limit_job', 'template_survey_job', 'textarea_survey_job'],
scope='module'),
pytest.mark.ignore_stream('upstream'),
pytest.mark.parametrize('ansible_api_version', ['v1', 'v2']),
pytest.mark.ignore_stream('upstream')
]


Expand All @@ -39,9 +36,14 @@ def catalog_item(appliance, request, provider, ansible_tower_dialog, catalog, jo
return catalog_item


@pytest.mark.parametrize('job_type', ['template', 'template_limit', 'template_survey',
'textarea_survey'],
ids=['template_job', 'template_limit_job', 'template_survey_job', 'textarea_survey_job'],
scope='module')
@pytest.mark.meta(automates=[BZ(1717500)])
# The 'textarea_survey' job type automates BZ 1717500
def test_order_tower_catalog_item(appliance, provider, catalog_item, request, job_type):
def test_order_tower_catalog_item(appliance, provider, catalog_item, request, job_type,
ansible_api_version_change):
"""Tests ordering of catalog items for Ansible Template and Workflow jobs
Metadata:
test_flag: provision
Expand Down Expand Up @@ -74,7 +76,9 @@ def test_order_tower_catalog_item(appliance, provider, catalog_item, request, jo
'List View')


def test_retire_ansible_service(appliance, catalog_item, request, job_type):
@pytest.mark.parametrize('job_type', ['template'], ids=['template_job'])
def test_retire_ansible_service(appliance, catalog_item, request, job_type,
ansible_api_version_change):
"""Tests retiring of catalog items for Ansible Template and Workflow jobs
Metadata:
test_flag: provision
Expand Down