mirror of
https://github.com/ansible/awx.git
synced 2026-05-07 17:37:37 -02:30
Adding integration tests and example in import
This commit is contained in:
@@ -38,6 +38,10 @@ EXAMPLES = '''
|
|||||||
- name: Import all tower assets
|
- name: Import all tower assets
|
||||||
tower_import:
|
tower_import:
|
||||||
assets: "{{ export_output.assets }}"
|
assets: "{{ export_output.assets }}"
|
||||||
|
|
||||||
|
- name: Import orgs from a json file
|
||||||
|
tower_import:
|
||||||
|
assets: "{{ lookup('file', 'org.json') | from_json() }}"
|
||||||
'''
|
'''
|
||||||
|
|
||||||
from ..module_utils.tower_awxkit import TowerAWXKitModule
|
from ..module_utils.tower_awxkit import TowerAWXKitModule
|
||||||
|
|||||||
@@ -0,0 +1,77 @@
|
|||||||
|
---
|
||||||
|
- name: Generate a random string for test
|
||||||
|
set_fact:
|
||||||
|
test_id: "{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
|
||||||
|
when: test_id is not defined
|
||||||
|
|
||||||
|
- name: Generate names
|
||||||
|
set_fact:
|
||||||
|
org_name1: "AWX-Collection-tests-tower_export-organization-{{ test_id }}"
|
||||||
|
org_name2: "AWX-Collection-tests-tower_export-organization2-{{ test_id }}"
|
||||||
|
inventory_name1: "AWX-Collection-tests-tower_export-inv1-{{ test_id }}"
|
||||||
|
|
||||||
|
- block:
|
||||||
|
- name: Create some organizations
|
||||||
|
tower_organization:
|
||||||
|
name: "{{ item }}"
|
||||||
|
loop:
|
||||||
|
- "{{ org_name1 }}"
|
||||||
|
- "{{ org_name2 }}"
|
||||||
|
|
||||||
|
- name: Create an inventory
|
||||||
|
tower_inventory:
|
||||||
|
name: "{{ inventory_name1 }}"
|
||||||
|
organization: "{{ org_name1 }}"
|
||||||
|
|
||||||
|
- name: Export all tower assets
|
||||||
|
tower_export:
|
||||||
|
all: True
|
||||||
|
register: all_assets
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- all_assets is not changed
|
||||||
|
- all_assets is successful
|
||||||
|
- all_assets['assets']['organizations'] | length() >= 2
|
||||||
|
|
||||||
|
- name: Export all inventories
|
||||||
|
tower_export:
|
||||||
|
inventory: 'all'
|
||||||
|
register: inventory_export
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- inventory_export is successful
|
||||||
|
- inventory_export is not changed
|
||||||
|
- inventory_export['assets']['inventory'] | length() >= 1
|
||||||
|
- "'organizations' not in inventory_export['assets']"
|
||||||
|
|
||||||
|
# This mimics the example in the module
|
||||||
|
- name: Export an all and a specific
|
||||||
|
tower_export:
|
||||||
|
inventory: 'all'
|
||||||
|
organizations: "{{ org_name1 }}"
|
||||||
|
register: mixed_export
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- mixed_export is successful
|
||||||
|
- mixed_export is not changed
|
||||||
|
- mixed_export['assets']['inventory'] | length() >= 1
|
||||||
|
- mixed_export['assets']['organizations'] | length() == 1
|
||||||
|
- "'workflow_job_templates' not in mixed_export['assets']"
|
||||||
|
|
||||||
|
always:
|
||||||
|
- name: Remove our inventory
|
||||||
|
tower_inventory:
|
||||||
|
name: "{{ inventory_name1 }}"
|
||||||
|
organization: "{{ org_name1 }}"
|
||||||
|
state: absent
|
||||||
|
|
||||||
|
- name: Remove test organizations
|
||||||
|
tower_organization:
|
||||||
|
name: "{{ item }}"
|
||||||
|
state: absent
|
||||||
|
loop:
|
||||||
|
- "{{ org_name1 }}"
|
||||||
|
- "{{ org_name2 }}"
|
||||||
@@ -0,0 +1,108 @@
|
|||||||
|
---
|
||||||
|
- name: Generate a random string for test
|
||||||
|
set_fact:
|
||||||
|
test_id: "{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
|
||||||
|
when: test_id is not defined
|
||||||
|
|
||||||
|
- name: Generate names
|
||||||
|
set_fact:
|
||||||
|
org_name1: "AWX-Collection-tests-tower_import-organization-{{ test_id }}"
|
||||||
|
org_name2: "AWX-Collection-tests-tower_import-organization2-{{ test_id }}"
|
||||||
|
|
||||||
|
- block:
|
||||||
|
- name: "Import something"
|
||||||
|
tower_import:
|
||||||
|
assets:
|
||||||
|
organizations:
|
||||||
|
- name: "{{ org_name1 }}"
|
||||||
|
description: ""
|
||||||
|
max_hosts: 0
|
||||||
|
custom_virtualenv: null
|
||||||
|
related:
|
||||||
|
notification_templates: []
|
||||||
|
notification_templates_started: []
|
||||||
|
notification_templates_success: []
|
||||||
|
notification_templates_error: []
|
||||||
|
notification_templates_approvals: []
|
||||||
|
natural_key:
|
||||||
|
name: "Default"
|
||||||
|
type: "organization"
|
||||||
|
register: import_output
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- import_output is changed
|
||||||
|
|
||||||
|
- name: "Import something again (awxkit is not idempotent, this tests a filure)"
|
||||||
|
tower_import:
|
||||||
|
assets:
|
||||||
|
organizations:
|
||||||
|
- name: "{{ org_name1 }}"
|
||||||
|
description: ""
|
||||||
|
max_hosts: 0
|
||||||
|
custom_virtualenv: null
|
||||||
|
related:
|
||||||
|
notification_templates: []
|
||||||
|
notification_templates_started: []
|
||||||
|
notification_templates_success: []
|
||||||
|
notification_templates_error: []
|
||||||
|
notification_templates_approvals: []
|
||||||
|
natural_key:
|
||||||
|
name: "Default"
|
||||||
|
type: "organization"
|
||||||
|
register: import_output
|
||||||
|
ignore_errors: True
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- import_output is failed
|
||||||
|
- "'Organization with this Name already exists' in import_output.msg"
|
||||||
|
|
||||||
|
- name: "Write out a json file"
|
||||||
|
copy:
|
||||||
|
content: |
|
||||||
|
{
|
||||||
|
"organizations": [
|
||||||
|
{
|
||||||
|
"name": "{{ org_name2 }}",
|
||||||
|
"description": "",
|
||||||
|
"max_hosts": 0,
|
||||||
|
"custom_virtualenv": null,
|
||||||
|
"related": {
|
||||||
|
"notification_templates": [],
|
||||||
|
"notification_templates_started": [],
|
||||||
|
"notification_templates_success": [],
|
||||||
|
"notification_templates_error": [],
|
||||||
|
"notification_templates_approvals": []
|
||||||
|
},
|
||||||
|
"natural_key": {
|
||||||
|
"name": "Default",
|
||||||
|
"type": "organization"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
dest: ./org.json
|
||||||
|
|
||||||
|
- name: "Load assets from a file"
|
||||||
|
tower_import:
|
||||||
|
assets: "{{ lookup('file', 'org.json') | from_json() }}"
|
||||||
|
register: import_output
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- import_output is changed
|
||||||
|
|
||||||
|
always:
|
||||||
|
- name: Remove organizations
|
||||||
|
tower_organization:
|
||||||
|
name: "{{ item }}"
|
||||||
|
state: absent
|
||||||
|
loop:
|
||||||
|
- "{{ org_name1 }}"
|
||||||
|
- "{{ org_name2 }}"
|
||||||
|
|
||||||
|
- name: Delete org.json
|
||||||
|
file:
|
||||||
|
path: ./org.json
|
||||||
|
state: absent
|
||||||
Reference in New Issue
Block a user