summaryrefslogtreecommitdiff
path: root/test/integration/targets/incidental_inventory_foreman
diff options
context:
space:
mode:
authorMatt Clay <mclay@redhat.com>2020-02-25 23:18:50 -0800
committerGitHub <noreply@github.com>2020-02-25 23:18:50 -0800
commite3591223a042caa537fcc88cf7553227b8657f70 (patch)
tree137991b3e16fb757859fcbbeafd93d7d46ef2a7b /test/integration/targets/incidental_inventory_foreman
parenta19ae28326ce861c0eeae803e939050b5bcd64bd (diff)
downloadansible-e3591223a042caa537fcc88cf7553227b8657f70.tar.gz
Second batch of incidental integration tests. (#67765)
* Update incidental test aliases. * Rewrite target references for renamed targets. * Add incidental tests to CI. * Update sanity tests for incidental cloud tests. * Initial copy of incidental tests. * Copy contrib files into test. * Update paths in test. * Add support plugins. * Update plugin to work around missing deps. * Update sanity ignores. * Fix matrix entries. * Remove debug echo.
Diffstat (limited to 'test/integration/targets/incidental_inventory_foreman')
-rw-r--r--test/integration/targets/incidental_inventory_foreman/aliases3
-rw-r--r--test/integration/targets/incidental_inventory_foreman/ansible.cfg5
-rw-r--r--test/integration/targets/incidental_inventory_foreman/inspect_cache.yml31
-rwxr-xr-xtest/integration/targets/incidental_inventory_foreman/runme.sh50
-rw-r--r--test/integration/targets/incidental_inventory_foreman/test_foreman_inventory.yml59
5 files changed, 148 insertions, 0 deletions
diff --git a/test/integration/targets/incidental_inventory_foreman/aliases b/test/integration/targets/incidental_inventory_foreman/aliases
new file mode 100644
index 0000000000..c28a056e81
--- /dev/null
+++ b/test/integration/targets/incidental_inventory_foreman/aliases
@@ -0,0 +1,3 @@
+shippable/cloud/incidental
+cloud/foreman
+destructive
diff --git a/test/integration/targets/incidental_inventory_foreman/ansible.cfg b/test/integration/targets/incidental_inventory_foreman/ansible.cfg
new file mode 100644
index 0000000000..63e24c4bd0
--- /dev/null
+++ b/test/integration/targets/incidental_inventory_foreman/ansible.cfg
@@ -0,0 +1,5 @@
+[defaults]
+inventory = test-config.foreman.yaml
+
+[inventory]
+enable_plugins = foreman
diff --git a/test/integration/targets/incidental_inventory_foreman/inspect_cache.yml b/test/integration/targets/incidental_inventory_foreman/inspect_cache.yml
new file mode 100644
index 0000000000..c91f4c3868
--- /dev/null
+++ b/test/integration/targets/incidental_inventory_foreman/inspect_cache.yml
@@ -0,0 +1,31 @@
+---
+- hosts: localhost
+ vars:
+ foreman_stub_host: "{{ lookup('env', 'FOREMAN_HOST') }}"
+ foreman_stub_port: "{{ lookup('env', 'FOREMAN_PORT') }}"
+ foreman_stub_api_path: /api/v2
+ cached_hosts_key: "http://{{ foreman_stub_host }}:{{ foreman_stub_port }}{{ foreman_stub_api_path }}/hosts"
+ tasks:
+ - name: verify a cache file was created
+ find:
+ path:
+ - ./foreman_cache
+ register: matching_files
+
+ - assert:
+ that:
+ - matching_files.matched == 1
+ - name: read the cached inventory
+ set_fact:
+ contents: "{{ lookup('file', matching_files.files.0.path) }}"
+
+ - name: extract all the host names
+ set_fact:
+ cached_hosts: "{{ contents[cached_hosts_key] | json_query('[*].name') }}"
+
+ - assert:
+ that:
+ "'{{ item }}' in cached_hosts"
+ loop:
+ - "v6.example-780.com"
+ - "c4.j1.y5.example-487.com"
diff --git a/test/integration/targets/incidental_inventory_foreman/runme.sh b/test/integration/targets/incidental_inventory_foreman/runme.sh
new file mode 100755
index 0000000000..ba94a9360f
--- /dev/null
+++ b/test/integration/targets/incidental_inventory_foreman/runme.sh
@@ -0,0 +1,50 @@
+#!/usr/bin/env bash
+
+[[ -n "$DEBUG" || -n "$ANSIBLE_DEBUG" ]] && set -x
+
+set -euo pipefail
+
+export ANSIBLE_INVENTORY
+export ANSIBLE_PYTHON_INTERPRETER
+
+unset ANSIBLE_INVENTORY
+unset ANSIBLE_PYTHON_INTERPRETER
+
+export ANSIBLE_CONFIG=ansible.cfg
+export FOREMAN_HOST="${FOREMAN_HOST:-localhost}"
+export FOREMAN_PORT="${FOREMAN_PORT:-8080}"
+FOREMAN_CONFIG=test-config.foreman.yaml
+
+# Set inventory caching environment variables to populate a jsonfile cache
+export ANSIBLE_INVENTORY_CACHE=True
+export ANSIBLE_INVENTORY_CACHE_PLUGIN=jsonfile
+export ANSIBLE_INVENTORY_CACHE_CONNECTION=./foreman_cache
+
+# flag for checking whether cleanup has already fired
+_is_clean=
+
+function _cleanup() {
+ [[ -n "$_is_clean" ]] && return # don't double-clean
+ echo Cleanup: removing $FOREMAN_CONFIG...
+ rm -vf "$FOREMAN_CONFIG"
+ unset ANSIBLE_CONFIG
+ unset FOREMAN_HOST
+ unset FOREMAN_PORT
+ unset FOREMAN_CONFIG
+ _is_clean=1
+}
+trap _cleanup INT TERM EXIT
+
+cat > "$FOREMAN_CONFIG" <<FOREMAN_YAML
+plugin: foreman
+url: http://${FOREMAN_HOST}:${FOREMAN_PORT}
+user: ansible-tester
+password: secure
+validate_certs: False
+FOREMAN_YAML
+
+ansible-playbook test_foreman_inventory.yml --connection=local "$@"
+ansible-playbook inspect_cache.yml --connection=local "$@"
+
+# remove inventory cache
+rm -r ./foreman_cache
diff --git a/test/integration/targets/incidental_inventory_foreman/test_foreman_inventory.yml b/test/integration/targets/incidental_inventory_foreman/test_foreman_inventory.yml
new file mode 100644
index 0000000000..d5eeed4f8b
--- /dev/null
+++ b/test/integration/targets/incidental_inventory_foreman/test_foreman_inventory.yml
@@ -0,0 +1,59 @@
+---
+- hosts: localhost
+ vars:
+ foreman_stub_host: "{{ lookup('env', 'FOREMAN_HOST') }}"
+ foreman_stub_port: "{{ lookup('env', 'FOREMAN_PORT') }}"
+ foreman_stub_api_path: /api/v2
+ foreman_stub_host_uri: "http://{{ foreman_stub_host }}:{{ foreman_stub_port }}"
+ foreman_stub_api_uri: "{{ foreman_stub_host_uri }}{{ foreman_stub_api_path }}"
+ foreman_stub_heartbeat_uri: "{{ foreman_stub_host_uri }}/ping"
+ tasks:
+ - debug:
+ msg: >-
+ Foreman host: {{ foreman_stub_host }} |
+ Foreman port: {{ foreman_stub_port }} |
+ API path: {{ foreman_stub_api_path }} |
+ Foreman API URL: {{ foreman_stub_api_uri }}
+
+ - name: Wait for Foreman API stub to come up online
+ wait_for:
+ host: "{{ foreman_stub_host }}"
+ port: "{{ foreman_stub_port }}"
+ state: started
+
+ # smoke test that flask app is serving
+ - name: Smoke test HTTP response from Foreman stub
+ uri:
+ url: "{{ foreman_stub_heartbeat_uri }}"
+ return_content: yes
+ register: heartbeat_resp
+ failed_when: >
+ heartbeat_resp.json.status != 'ok' or heartbeat_resp.json.response != 'pong'
+
+ #### Testing start
+ - name: >
+ Check that there are 'foreman_pgagne_sats' and 'foreman_base'
+ groups present in inventory
+ assert:
+ that: >
+ '{{ item }}' in groups
+ with_items:
+ - foreman_pgagne_sats
+ - foreman_base
+
+ - name: Check that host are in appropriate groups
+ assert:
+ that: >
+ '{{ item.key }}' in groups['{{ item.value }}']
+ with_dict:
+ v6.example-780.com: foreman_base
+ c4.j1.y5.example-487.com: ungrouped
+
+ - name: Check host UUIDs
+ assert:
+ that: >
+ hostvars['{{ item.key }}']['foreman_subscription_facet_attributes']['uuid'] == '{{ item.value }}'
+ with_dict:
+ v6.example-780.com: 2c72fa49-995a-4bbf-bda0-684c7048ad9f
+ c4.j1.y5.example-487.com: 0a494b6e-7e90-4ed2-8edc-43a41436a242
+ #### Testing end