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

Commit

Permalink
Merge pull request #9599 from mshriver/add-function-scope-ansible-fix…
Browse files Browse the repository at this point in the history
…ture

[RFR] Add function scoped ansible cat item fixture
  • Loading branch information
mshriver authored Nov 12, 2019
2 parents 15e3a36 + 0fa407c commit 0f7f360
Showing 1 changed file with 75 additions and 42 deletions.
117 changes: 75 additions & 42 deletions cfme/tests/ansible/test_embedded_ansible_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,45 @@
]


@pytest.fixture(scope="function")
def local_ansible_catalog_item(appliance, ansible_repository):
"""override global ansible_catalog_item for function scope
as these tests modify the catalog item
"""
collection = appliance.collections.catalog_items
cat_item = collection.create(
collection.ANSIBLE_PLAYBOOK,
fauxfactory.gen_alphanumeric(),
fauxfactory.gen_alphanumeric(),
display_in_catalog=True,
provisioning={
"repository": ansible_repository.name,
"playbook": "dump_all_variables.yml",
"machine_credential": "CFME Default Credential",
"create_new": True,
"provisioning_dialog_name": fauxfactory.gen_alphanumeric(),
"extra_vars": [("some_var", "some_value")]
},
retirement={
"repository": ansible_repository.name,
"playbook": "dump_all_variables.yml",
"machine_credential": "CFME Default Credential",
"extra_vars": [("some_var", "some_value")]
}
)
yield cat_item

cat_item.delete_if_exists()


@pytest.fixture()
def ansible_linked_vm_action(appliance, ansible_catalog_item, new_vm):
with update(ansible_catalog_item):
ansible_catalog_item.provisioning = {"playbook": "add_single_vm_to_service.yml"}
def ansible_linked_vm_action(appliance, local_ansible_catalog_item, new_vm):
with update(local_ansible_catalog_item):
local_ansible_catalog_item.provisioning = {"playbook": "add_single_vm_to_service.yml"}

action_values = {
"run_ansible_playbook": {
"playbook_catalog_item": ansible_catalog_item.name,
"playbook_catalog_item": local_ansible_catalog_item.name,
"inventory": {"specific_hosts": True, "hosts": new_vm.ip_address},
}
}
Expand Down Expand Up @@ -147,15 +178,15 @@ def ansible_credential(appliance):


@pytest.fixture
def custom_service_button(appliance, ansible_catalog_item):
def custom_service_button(appliance, local_ansible_catalog_item):
buttongroup = appliance.collections.button_groups.create(
text=fauxfactory.gen_alphanumeric(),
hover="btn_desc_{}".format(fauxfactory.gen_alphanumeric()),
type=appliance.collections.button_groups.SERVICE)
button = buttongroup.buttons.create(
text=fauxfactory.gen_alphanumeric(),
hover="btn_hvr_{}".format(fauxfactory.gen_alphanumeric()),
dialog=ansible_catalog_item.provisioning["provisioning_dialog_name"],
dialog=local_ansible_catalog_item.provisioning["provisioning_dialog_name"],
system="Request",
request="Order_Ansible_Playbook",
)
Expand Down Expand Up @@ -471,7 +502,7 @@ def test_service_ansible_playbook_plays_table(

@pytest.mark.tier(3)
def test_service_ansible_playbook_order_credentials(
ansible_catalog_item, ansible_credential, ansible_service_catalog
local_ansible_catalog_item, ansible_credential, ansible_service_catalog
):
"""Test if credentials avaialable in the dropdown in ordering ansible playbook service
screen.
Expand All @@ -483,8 +514,8 @@ def test_service_ansible_playbook_order_credentials(
initialEstimate: 1/6h
tags: ansible_embed
"""
with update(ansible_catalog_item):
ansible_catalog_item.provisioning = {
with update(local_ansible_catalog_item):
local_ansible_catalog_item.provisioning = {
"machine_credential": ansible_credential.name
}
view = navigate_to(ansible_service_catalog, "Order")
Expand Down Expand Up @@ -528,7 +559,7 @@ def test_service_ansible_playbook_pass_extra_vars(
def test_service_ansible_execution_ttl(
request,
ansible_service_catalog,
ansible_catalog_item,
local_ansible_catalog_item,
ansible_service,
ansible_service_request,
):
Expand All @@ -547,15 +578,15 @@ def test_service_ansible_execution_ttl(
1519275
1515841
"""
with update(ansible_catalog_item):
ansible_catalog_item.provisioning = {
with update(local_ansible_catalog_item):
local_ansible_catalog_item.provisioning = {
"playbook": "long_running_playbook.yml",
"max_ttl": 200
}

def _revert():
with update(ansible_catalog_item):
ansible_catalog_item.provisioning = {
with update(local_ansible_catalog_item):
local_ansible_catalog_item.provisioning = {
"playbook": "dump_all_variables.yml",
"max_ttl": "",
}
Expand Down Expand Up @@ -654,7 +685,7 @@ def test_ansible_group_id_in_payload(
def test_embed_tower_exec_play_against(
appliance,
request,
ansible_catalog_item,
local_ansible_catalog_item,
ansible_service,
ansible_service_catalog,
credential,
Expand All @@ -669,22 +700,22 @@ def test_embed_tower_exec_play_against(
tags: ansible_embed
"""
playbook = credential[2]
with update(ansible_catalog_item):
ansible_catalog_item.provisioning = {
with update(local_ansible_catalog_item):
local_ansible_catalog_item.provisioning = {
"playbook": playbook,
"cloud_type": provider_credentials.credential_type,
"cloud_credential": provider_credentials.name,
}

@request.addfinalizer
def _revert():
with update(ansible_catalog_item):
ansible_catalog_item.provisioning = {
with update(local_ansible_catalog_item):
local_ansible_catalog_item.provisioning = {
"playbook": "dump_all_variables.yml",
"cloud_type": "<Choose>",
}

service = MyService(appliance, ansible_catalog_item.name)
service = MyService(appliance, local_ansible_catalog_item.name)
if service_request.exists():
service_request.wait_for_request()
appliance.rest_api.collections.service_requests.action.delete(id=service_id.id)
Expand All @@ -693,7 +724,8 @@ def _revert():

service_request = ansible_service_catalog.order()
service_request.wait_for_request(num_sec=300, delay=20)
request_descr = "Provisioning Service [{0}] from [{0}]".format(ansible_catalog_item.name)
request_descr = (f"Provisioning Service [{local_ansible_catalog_item.name}] "
f"from [{local_ansible_catalog_item.name}]")
service_request = appliance.collections.requests.instantiate(description=request_descr)
service_id = appliance.rest_api.collections.service_requests.get(description=request_descr)

Expand All @@ -717,7 +749,7 @@ def _revert():
def test_service_ansible_verbosity(
appliance,
request,
ansible_catalog_item,
local_ansible_catalog_item,
ansible_service_catalog,
ansible_service_request,
ansible_service,
Expand All @@ -736,17 +768,17 @@ def test_service_ansible_verbosity(
"""
# Adding index 0 which will give pattern for e.g. pattern = "verbosity"=>0.
pattern = '"verbosity"=>{}'.format(verbosity[0])
with update(ansible_catalog_item):
ansible_catalog_item.provisioning = {"verbosity": verbosity}
ansible_catalog_item.retirement = {"verbosity": verbosity}
with update(local_ansible_catalog_item):
local_ansible_catalog_item.provisioning = {"verbosity": verbosity}
local_ansible_catalog_item.retirement = {"verbosity": verbosity}
# Log Validator
log = LogValidator("/var/www/miq/vmdb/log/evm.log", matched_patterns=[pattern])
# Start Log check or given pattern
log.start_monitoring()

@request.addfinalizer
def _revert():
service = MyService(appliance, ansible_catalog_item.name)
service = MyService(appliance, local_ansible_catalog_item.name)
if ansible_service_request.exists():
ansible_service_request.wait_for_request()
appliance.rest_api.collections.service_requests.action.delete(
Expand All @@ -759,7 +791,8 @@ def _revert():
ansible_service_request.wait_for_request()
# 'request_descr' and 'service_request' being used in finalizer to remove
# first service request
request_descr = "Provisioning Service [{0}] from [{0}]".format(ansible_catalog_item.name)
request_descr = (f"Provisioning Service [{local_ansible_catalog_item.name}] "
f"from [{local_ansible_catalog_item.name}]")
service_request = appliance.rest_api.collections.service_requests.get(
description=request_descr
)
Expand Down Expand Up @@ -808,7 +841,7 @@ def test_ansible_service_linked_vm(
def test_ansible_service_order_vault_credentials(
appliance,
request,
ansible_catalog_item,
local_ansible_catalog_item,
ansible_service_catalog,
ansible_service_request,
ansible_service,
Expand All @@ -828,16 +861,16 @@ def test_ansible_service_order_vault_credentials(
"Vault_Credentials_{}".format(fauxfactory.gen_alpha()), "Vault", **creds_dict
)

with update(ansible_catalog_item):
ansible_catalog_item.provisioning = {
with update(local_ansible_catalog_item):
local_ansible_catalog_item.provisioning = {
"playbook": "dump_secret_variable_from_vault.yml",
"vault_credential": vault_creds.name,
}

@request.addfinalizer
def _revert():
with update(ansible_catalog_item):
ansible_catalog_item.provisioning = {
with update(local_ansible_catalog_item):
local_ansible_catalog_item.provisioning = {
"playbook": "dump_all_variables.yml",
"vault_credential": "<Choose>",
}
Expand Down Expand Up @@ -869,15 +902,15 @@ def test_ansible_service_ansible_galaxy_role(appliance, request, ansible_catalog
tags: ansible_embed
"""
old_playbook_value = ansible_catalog_item.provisioning
with update(ansible_catalog_item):
ansible_catalog_item.provisioning = {
with update(local_ansible_catalog_item):
local_ansible_catalog_item.provisioning = {
"playbook": "ansible_galaxy_role_users.yaml"
}

@request.addfinalizer
def _revert():
with update(ansible_catalog_item):
ansible_catalog_item.provisioning["playbook"] = old_playbook_value["playbook"]
with update(local_ansible_catalog_item):
local_ansible_catalog_item.provisioning["playbook"] = old_playbook_value["playbook"]

service_request = ansible_service_catalog.order()
service_request.wait_for_request(num_sec=300, delay=20)
Expand Down Expand Up @@ -925,7 +958,7 @@ def test_ansible_service_with_operations_role_disabled(appliance, ansible_catalo
reason='Credential type not valid for parametrized provider'
)
@pytest.mark.tier(3)
def test_ansible_service_cloud_credentials(appliance, request, ansible_catalog_item,
def test_ansible_service_cloud_credentials(appliance, request, local_ansible_catalog_item,
ansible_service_catalog, credential, provider_credentials, ansible_service_funcscope,
ansible_service_request_funcscope):
"""
Expand All @@ -943,19 +976,19 @@ def test_ansible_service_cloud_credentials(appliance, request, ansible_catalog_i
tags: ansible_embed
"""
# TODO: Include all providers once all playbooks are in place.
old_playbook_value = ansible_catalog_item.provisioning
old_playbook_value = local_ansible_catalog_item.provisioning
playbook = credential[2]
with update(ansible_catalog_item):
ansible_catalog_item.provisioning = {
with update(local_ansible_catalog_item):
local_ansible_catalog_item.provisioning = {
"playbook": playbook,
"cloud_type": provider_credentials.credential_type,
"cloud_credential": provider_credentials.name,
}

@request.addfinalizer
def _revert():
with update(ansible_catalog_item):
ansible_catalog_item.provisioning["playbook"] = old_playbook_value["playbook"]
with update(local_ansible_catalog_item):
local_ansible_catalog_item.provisioning["playbook"] = old_playbook_value["playbook"]

service_request = ansible_service_catalog.order()
service_request.wait_for_request(num_sec=300, delay=20)
Expand Down

0 comments on commit 0f7f360

Please sign in to comment.