Skip to content

Commit

Permalink
Conditionalize integration tests if the cred is present
Browse files Browse the repository at this point in the history
  • Loading branch information
thedoubl3j committed Jan 14, 2025
1 parent 5ab445e commit 817f19b
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 53 deletions.
27 changes: 10 additions & 17 deletions awx_collection/tests/integration/targets/credential/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,19 @@
tower_cred_name1: "AWX-Collection-tests-credential-tower-cred1-{{ test_id }}"

- name: Get current Credential Types available
ansible.builtin.uri:
url: "https://localhost:8043/api/v2/credential_types/"
force_basic_auth: true
user: admin
password: password
method: GET
return_content: yes
validate_certs: false
register: credentials
ansible.builtin.set_fact:
credentials: "{{ lookup('awx.awx.controller_api', 'credential_types') }}"

- name: Register Credentials found
set_fact:
aws_found: "{{ 'Amazon Web Services' in credentials.json.results | map(attribute='name') | list }}"
vmware_found: "{{ 'VMware vCenter' in credentials.json.results | map(attribute='name') | list }}"
azure_found: "{{ 'Microsoft Azure Resource Manager' in credentials.json.results | map(attribute='name') | list }}"
gce_found: "{{ 'Google Compute Engine' in credentials.json.results | map(attribute='name') | list }}"
insights_found: "{{ 'Red Hat Insights' in credentials.json.results | map(attribute='name') | list }}"
satellite_found: "{{ 'Red Hat Satellite 6' in credentials.json.results | map(attribute='name') | list }}"
openstack_found: "{{ 'OpenStack' in credentials.json.results | map(attribute='name') | list }}"
rhv_found: "{{ 'Red Hat Virtualization' in credentials.json.results | map(attribute='name') | list }}"
aws_found: "{{ 'Amazon Web Services' in credentials | map(attribute='name') | list }}"
vmware_found: "{{ 'VMware vCenter' in credentials | map(attribute='name') | list }}"
azure_found: "{{ 'Microsoft Azure Resource Manager' in credentials | map(attribute='name') | list }}"
gce_found: "{{ 'Google Compute Engine' in credentials | map(attribute='name') | list }}"
insights_found: "{{ 'Red Hat Insights' in credentials | map(attribute='name') | list }}"
satellite_found: "{{ 'Red Hat Satellite 6' in credentials | map(attribute='name') | list }}"
openstack_found: "{{ 'OpenStack' in credentials | map(attribute='name') | list }}"
rhv_found: "{{ 'Red Hat Virtualization' in credentials | map(attribute='name') | list }}"

- name: create a tempdir for an SSH key
local_action: shell mktemp -d
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,17 @@
src_cred_name: "AWX-Collection-tests-credential_input_source-src_cred-{{ test_id }}"
target_cred_name: "AWX-Collection-tests-credential_input_source-target_cred-{{ test_id }}"

- block:
- name: detect credential types
ansible.builtin.set_fact:
credentials: "{{ lookup('awx.awx.controller_api', 'credential_types') }}"

- name: Register Credentials found
set_fact:
cyberark_found: "{{ 'CyberArk Central Credential Provider Lookup' in credentials | map(attribute='name') | list }}"

- name: Test credential lookup workflow
when: cyberark_found
block:
- name: Add credential Lookup
credential:
description: Credential for Testing Source
Expand Down Expand Up @@ -121,7 +131,9 @@
that:
- "result is changed"

always:
- name: Clean up if previous block ran
when: cyberark_found
block:
- name: Remove a credential source
credential_input_source:
input_field_name: password
Expand Down
22 changes: 0 additions & 22 deletions awx_collection/tests/integration/targets/inventory/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
set_fact:
inv_name1: "AWX-Collection-tests-inventory-inv1-{{ test_id }}"
inv_name2: "AWX-Collection-tests-inventory-inv2-{{ test_id }}"
cred_name1: "AWX-Collection-tests-inventory-cred1-{{ test_id }}"
group_name1: "AWX-Collection-tests-instance_group-group1-{{ test_id }}"

- block:
Expand All @@ -23,21 +22,6 @@
that:
- "result is changed"

- name: Create an Insights Credential
credential:
name: "{{ cred_name1 }}"
organization: Default
credential_type: Insights
inputs:
username: joe
password: secret
state: present
register: result

- assert:
that:
- "result is changed"

- name: Create an Inventory
inventory:
name: "{{ inv_name1 }}"
Expand Down Expand Up @@ -228,9 +212,3 @@
name: "{{ group_name1 }}"
state: absent

- name: Delete Insights Credential
credential:
name: "{{ cred_name1 }}"
organization: "Default"
credential_type: Insights
state: absent
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@
ig2: "AWX-Collection-tests-workflow_job_template-ig2-{{ test_id }}"
host1: "AWX-Collection-tests-workflow_job_template-h1-{{ test_id }}"

- name: detect credential types
ansible.builtin.set_fact:
credentials: "{{ lookup('awx.awx.controller_api', 'credential_types') }}"

- name: Register Credentials found
set_fact:
github_found: "{{ 'Github Personal Access Token' in credentials | map(attribute='name') | list }}"

- block:
- name: "Create a new organization"
organization:
Expand All @@ -36,21 +44,29 @@
- Ansible Galaxy
register: result

- name: Create Credentials
- name: Create SCM Credential
credential:
name: "{{ item.name }}"
name: "{{ scm_cred_name }}"
organization: Default
credential_type: "{{ item.type }}"
credential_type: Source Control
register: result
loop:
- name: "{{ scm_cred_name }}"
type: Source Control
- name: "{{ github_webhook_credential_name }}"
type: GitHub Personal Access Token

- assert:
that:
- "result is changed"

- name: Create Github PAT Credential
credential:
name: "{{ github_webhook_credential_name }}"
organization: Default
credential_type: Github Personal Access Token
register: result
when: github_found

- assert:
that:
- "result is changed"
when: github_found

- name: Add email notification
notification_template:
Expand Down Expand Up @@ -867,8 +883,8 @@
name: "{{ webhook_wfjt_name }}"
organization: Default
inventory: Demo Inventory
webhook_service: gitlab
webhook_credential: "{{ github_webhook_credential_name }}"
webhook_service: "{{ 'gitlab' if github_found else omit }}"
webhook_credential: "{{ github_webhook_credential_name if github_found else omit }}"
ignore_errors: true
register: result

Expand All @@ -882,8 +898,8 @@
name: "{{ webhook_wfjt_name }}"
organization: Default
inventory: Demo Inventory
webhook_service: github
webhook_credential: "{{ github_webhook_credential_name }}"
webhook_service: "{{ 'github' if github_found else omit }}"
webhook_credential: "{{ github_webhook_credential_name if github_found else omit }}"
register: result

- assert:
Expand Down

0 comments on commit 817f19b

Please sign in to comment.