From 421acd4cb4b96fa71d207d28002c1987f2d51ad3 Mon Sep 17 00:00:00 2001 From: Fabian von Feilitzsch Date: Tue, 25 Aug 2020 15:01:05 -0400 Subject: [PATCH] Add tests for inventory plugin --- molecule/default/converge.yml | 31 ++++++++++++++++-------------- molecule/default/molecule.yml | 5 +++++ molecule/default/verify.yml | 36 +++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 14 deletions(-) diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml index 8966b827..cf4af285 100644 --- a/molecule/default/converge.yml +++ b/molecule/default/converge.yml @@ -26,32 +26,35 @@ apiVersion: v1 kind: DeploymentConfig metadata: - name: elastic + name: hello-world labels: app: galaxy - service: elastic + service: hello-world namespace: testing spec: template: metadata: labels: app: galaxy - service: elastic + service: hello-world spec: containers: - - name: elastic - volumeMounts: - - mountPath: /usr/share/elasticsearch/data - name: elastic-volume - command: ['elasticsearch'] - image: 'ansible/galaxy-elasticsearch:2.4.6' - volumes: - - name: elastic-volume - persistentVolumeClaim: - claimName: elastic-volume + - name: hello-world + image: python + command: + - python + - '-m' + - http.server + env: + - name: TEST + value: test replicas: 1 strategy: - type: Rolling + type: Recreate + wait: yes + wait_condition: + type: Available + status: True register: output - name: Show output diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml index 7600539e..80eef677 100644 --- a/molecule/default/molecule.yml +++ b/molecule/default/molecule.yml @@ -9,10 +9,15 @@ platforms: - k8s provisioner: name: ansible + config_options: + inventory: + enable_plugins: community.okd.openshift lint: | set -e ansible-lint inventory: + hosts: + plugin: community.okd.openshift host_vars: localhost: virtualenv: ${MOLECULE_EPHEMERAL_DIRECTORY}/virtualenv diff --git a/molecule/default/verify.yml b/molecule/default/verify.yml index 799ebab2..f69f41e0 100644 --- a/molecule/default/verify.yml +++ b/molecule/default/verify.yml @@ -1,4 +1,40 @@ --- +- name: Verify inventory and connection plugins + # This group is created by the openshift_inventory plugin + # It is automatically configured to use the `oc` connection plugin + hosts: namespace_testing_pods + gather_facts: no + vars: + file_content: | + Hello world + tasks: + - name: End play if host not running (TODO should we not add these to the inventory?) + meta: end_host + when: pod_phase != "Running" + + - setup: + + - debug: var=ansible_facts + + - name: Assert the TEST environment variable was retrieved + assert: + that: ansible_facts.env.TEST == 'test' + + - name: Copy a file into the host + copy: + content: '{{ file_content }}' + dest: /tmp/test_file + + - name: Retrieve the file from the host + slurp: + src: /tmp/test_file + register: slurped_file + + - name: Assert the file content matches expectations + assert: + that: (slurped_file.content|b64decode) == file_content + + - name: Verify hosts: localhost connection: local