Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Molecule tests should dump the logs on failure #74

Merged
merged 2 commits into from
Jul 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion molecule/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ Molecule is the default way to [test ansible operators](https://sdk.operatorfram

## Dependencies

If you want to run the tests on bare metal (not via the docker image), then deploy the depencencies by running the following command: `pip install -r requirements.txt` (assuming you are in the molecule directory).
If you want to run the tests on bare metal (not via the docker image), then deploy the depencencies by running the following commands (assuming you are in the `molecule` directory):

```
pip install -r requirements.txt
ansible-galaxy collection install community.kubernetes
```

## Running Test Scenarios

Expand Down
1 change: 1 addition & 0 deletions molecule/accessible-namespaces-test/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ provisioner:
playbooks:
destroy: ../default/destroy.yml
prepare: ../default/prepare.yml
cleanup: ../default/cleanup.yml
inventory:
group_vars:
all:
Expand Down
1 change: 1 addition & 0 deletions molecule/affinity-tolerations-resources-test/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ provisioner:
playbooks:
destroy: ../default/destroy.yml
prepare: ../default/prepare.yml
cleanup: ../default/cleanup.yml
inventory:
group_vars:
all:
Expand Down
4 changes: 2 additions & 2 deletions molecule/asserts/roles-test/ro_clusterrole_asserts.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
- name: Get cluster roles
k8s_facts:
k8s_info:
api_version: rbac.authorization.k8s.io/v1
kind: ClusterRole
name: kiali-viewer
Expand All @@ -11,7 +11,7 @@
fail_msg: "The kiali-viewer cluster role does not exist"

- name: Get cluster role binding
k8s_facts:
k8s_info:
api_version: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
name: kiali
Expand Down
4 changes: 2 additions & 2 deletions molecule/asserts/roles-test/ro_role_asserts.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
- name: Get roles
k8s_facts:
k8s_info:
api_version: rbac.authorization.k8s.io/v1
kind: Role
namespace: "{{ item[0] }}"
Expand All @@ -16,7 +16,7 @@
- "{{ roles.results }}"

- name: Get role binding
k8s_facts:
k8s_info:
api_version: rbac.authorization.k8s.io/v1
kind: RoleBinding
namespace: "{{ item[0] }}"
Expand Down
4 changes: 2 additions & 2 deletions molecule/asserts/roles-test/rw_clusterrole_asserts.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
- name: Get cluster roles
k8s_facts:
k8s_info:
api_version: rbac.authorization.k8s.io/v1
kind: ClusterRole
name: kiali
Expand All @@ -11,7 +11,7 @@
fail_msg: "The kiali cluster role does not exist"

- name: Get cluster role binding
k8s_facts:
k8s_info:
api_version: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
name: kiali
Expand Down
4 changes: 2 additions & 2 deletions molecule/asserts/roles-test/rw_role_asserts.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
- name: Get roles
k8s_facts:
k8s_info:
api_version: rbac.authorization.k8s.io/v1
kind: Role
namespace: "{{ item[0] }}"
Expand All @@ -16,7 +16,7 @@
- "{{ roles.results }}"

- name: Get role binding
k8s_facts:
k8s_info:
api_version: rbac.authorization.k8s.io/v1
kind: RoleBinding
namespace: "{{ item[0] }}"
Expand Down
2 changes: 1 addition & 1 deletion molecule/common/prepare-prometheus.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
- name: Get Prometheus HTTP endpoint route (this test requires a HTTP route to the Prometheus endpoint)
k8s_facts:
k8s_info:
api_version: route.openshift.io/v1
kind: Route
name: prometheus
Expand Down
10 changes: 5 additions & 5 deletions molecule/common/tasks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
kiali_cr: "{{ lookup('k8s', api_version='kiali.io/v1alpha1', kind='Kiali', namespace=cr_namespace, resource_name=custom_resource.metadata.name) }}"

- name: Get Kiali Operator Pod
k8s_facts:
k8s_info:
api_version: v1
kind: Pod
namespace: "{{ kiali.operator_namespace }}"
Expand All @@ -20,7 +20,7 @@
register: kiali_operator_pod

- name: Get Kiali Pod
k8s_facts:
k8s_info:
api_version: v1
kind: Pod
namespace: "{{ kiali.install_namespace }}"
Expand All @@ -37,7 +37,7 @@
kiali_configmap: "{{ kiali_configmap.data['config.yaml'] | from_yaml }}"

- name: Get Kiali Deployment
k8s_facts:
k8s_info:
api_version: apps/v1
kind: Deployment
namespace: "{{ kiali.install_namespace }}"
Expand All @@ -46,7 +46,7 @@
register: kiali_deployment

- name: Get Kiali Service
k8s_facts:
k8s_info:
api_version: v1
kind: Service
namespace: "{{ kiali.install_namespace }}"
Expand All @@ -55,7 +55,7 @@
register: kiali_service

- name: Get Kiali Route
k8s_facts:
k8s_info:
api_version: route.openshift.io/v1
kind: Route
namespace: "{{ kiali.install_namespace }}"
Expand Down
2 changes: 1 addition & 1 deletion molecule/common/wait_for_kiali_cr_changes.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
- name: Wait for changes to take effect
k8s_facts:
k8s_info:
api_version: kiali.io/v1alpha1
kind: Kiali
name: "{{ custom_resource.metadata.name }}"
Expand Down
2 changes: 1 addition & 1 deletion molecule/common/wait_for_kiali_running.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
- name: Asserting that Kiali Pod exists and there is only one
k8s_facts:
k8s_info:
api_version: v1
kind: Pod
namespace: "{{ kiali.install_namespace }}"
Expand Down
1 change: 1 addition & 0 deletions molecule/config-values-test/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ provisioner:
playbooks:
destroy: ../default/destroy.yml
prepare: ../default/prepare.yml
cleanup: ../default/cleanup.yml
inventory:
group_vars:
all:
Expand Down
1 change: 1 addition & 0 deletions molecule/default-namespace-test/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ provisioner:
playbooks:
destroy: ../default/destroy.yml
prepare: ../default/prepare.yml
cleanup: ../default/cleanup.yml
inventory:
group_vars:
all:
Expand Down
30 changes: 30 additions & 0 deletions molecule/default/cleanup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
- name: Cleanup
hosts: localhost
connection: local
tasks:

# Cleanup should only ever execute when a molecule test fails - this will dump logs

- name: Get Kiali Operator Pod logs
community.kubernetes.k8s_log:
namespace: "{{ kiali.operator_namespace }}"
label_selectors:
- app=kiali-operator
register: kiali_operator_logs
ignore_errors: yes
- name: Dump Kiali Operator Pod logs
debug:
msg: "{{ kiali_operator_logs.log_lines }}"
when: kiali_operator_logs is defined and kiali_operator_logs.log_lines is defined

- name: Get Kiali Server Pod logs
community.kubernetes.k8s_log:
namespace: "{{ kiali.install_namespace }}"
label_selectors:
- app=kiali
register: kiali_logs
ignore_errors: yes
- name: Dump Kiali Server Pod logs
debug:
msg: "{{ kiali_logs.log_lines }}"
when: kiali_logs is defined and kiali_logs.log_lines is defined
File renamed without changes.
4 changes: 2 additions & 2 deletions molecule/default/destroy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

# Wait for the last things to be removed (which are the configmap and monitoring dashboards). This avoids the namespace-stuck-problem.
- name: Wait for Kiali ConfigMap to be uninstalled
k8s_facts:
k8s_info:
api_version: v1
kind: ConfigMap
namespace: "{{ kiali.install_namespace }}"
Expand All @@ -56,7 +56,7 @@
delay: 5

- name: Wait for Kiali MonitoringDashboards to be uninstalled
k8s_facts:
k8s_info:
api_version: monitoring.kiali.io/v1alpha1
kind: MonitoringDashboard
namespace: "{{ kiali.install_namespace }}"
Expand Down
1 change: 1 addition & 0 deletions molecule/default/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ provisioner:
playbooks:
destroy: ../default/destroy.yml
prepare: ../default/prepare.yml
prepare: ../default/cleanup.yml
inventory:
group_vars:
all:
Expand Down
2 changes: 1 addition & 1 deletion molecule/default/prepare.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
definition: "{{ lookup('template', cr_file_path) }}"

- name: Asserting that Kiali is Deployed
k8s_facts:
k8s_info:
api_version: v1
kind: Deployment
namespace: "{{ kiali.install_namespace }}"
Expand Down
6 changes: 5 additions & 1 deletion molecule/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
FROM quay.io/ansible/molecule:2.22
FROM quay.io/ansible/molecule:3.0.4
RUN apk add gettext gcc libc-dev
RUN pip install openshift junit-xml jmespath docker kubernetes
RUN ansible-galaxy collection install community.kubernetes

# fixes https://github.com/ansible-community/molecule/pull/2690 - take this out when we move to 3.0.5
RUN mkdir -p /usr/share/ansible && ln -s /root/.ansible/collections /usr/share/ansible/collections
File renamed without changes.
1 change: 1 addition & 0 deletions molecule/metrics-test/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ provisioner:
playbooks:
destroy: ../default/destroy.yml
prepare: ../default/prepare.yml
cleanup: ../default/cleanup.yml
inventory:
group_vars:
all:
Expand Down
1 change: 1 addition & 0 deletions molecule/null-cr-values-test/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ provisioner:
playbooks:
destroy: ../default/destroy.yml
prepare: ../default/prepare.yml
cleanup: ../default/cleanup.yml
inventory:
group_vars:
all:
Expand Down
1 change: 1 addition & 0 deletions molecule/only-view-only-mode-test/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ provisioner:
playbooks:
destroy: ../default/destroy.yml
prepare: ../default/prepare.yml
cleanup: ../default/cleanup.yml
inventory:
group_vars:
all:
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions molecule/openid-test/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ provisioner:
playbooks:
destroy: ../default/destroy.yml
prepare: ../default/prepare.yml
cleanup: ../default/cleanup.yml
inventory:
group_vars:
all:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

# Test that there are no main masthead console links (we used to create these, but no longer)
- name: Get app links if exist
k8s_facts:
k8s_info:
api_version: console.openshift.io/v1
kind: ConsoleLink
name: "kiali-app-{{ kiali.install_namespace }}"
Expand Down Expand Up @@ -54,19 +54,19 @@

# Test that console links are correct across namespaces
- name: Get links from consolelinks1
k8s_facts:
k8s_info:
api_version: console.openshift.io/v1
kind: ConsoleLink
name: "kiali-namespace-consolelinks1"
register: consolelinks1
- name: Get links from consolelinks2
k8s_facts:
k8s_info:
api_version: console.openshift.io/v1
kind: ConsoleLink
name: "kiali-namespace-consolelinks2"
register: consolelinks2
- name: Get links from noconsolelinks
k8s_facts:
k8s_info:
api_version: console.openshift.io/v1
kind: ConsoleLink
name: "kiali-namespace-noconsolelinks"
Expand Down Expand Up @@ -99,19 +99,19 @@

# Test that console links are correct - note we removed a namespace from accessible_namespaces so the link should be gone
- name: Get links from consolelinks1
k8s_facts:
k8s_info:
api_version: console.openshift.io/v1
kind: ConsoleLink
name: "kiali-namespace-consolelinks1"
register: consolelinks1
- name: Get links from consolelinks2
k8s_facts:
k8s_info:
api_version: console.openshift.io/v1
kind: ConsoleLink
name: "kiali-namespace-consolelinks2"
register: consolelinks2
- name: Get links from noconsolelinks
k8s_facts:
k8s_info:
api_version: console.openshift.io/v1
kind: ConsoleLink
name: "kiali-namespace-noconsolelinks"
Expand Down Expand Up @@ -139,19 +139,19 @@

# Test that console links are correct across namespaces
- name: Get links from consolelinks1
k8s_facts:
k8s_info:
api_version: console.openshift.io/v1
kind: ConsoleLink
name: "kiali-namespace-consolelinks1"
register: consolelinks1
- name: Get links from consolelinks2
k8s_facts:
k8s_info:
api_version: console.openshift.io/v1
kind: ConsoleLink
name: "kiali-namespace-consolelinks2"
register: consolelinks2
- name: Get links from noconsolelinks
k8s_facts:
k8s_info:
api_version: console.openshift.io/v1
kind: ConsoleLink
name: "kiali-namespace-noconsolelinks"
Expand All @@ -178,7 +178,7 @@
name: "{{ custom_resource.metadata.name }}"

- name: Confirm all the Console Links got deleted
k8s_facts:
k8s_info:
api_version: console.openshift.io/v1
kind: ConsoleLink
label_selectors:
Expand Down
1 change: 1 addition & 0 deletions molecule/os-console-links-test/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ provisioner:
playbooks:
destroy: ../default/destroy.yml
prepare: ../default/prepare.yml
cleanup: ../default/cleanup.yml
inventory:
group_vars:
all:
Expand Down
1 change: 1 addition & 0 deletions molecule/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Project requirements
# 'pip install -r requirements.txt'
# In addition to these, you must also exec "ansible-galaxy collection install community.kubernetes"
molecule
openshift
jmespath
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions molecule/roles-test/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ provisioner:
playbooks:
destroy: ../default/destroy.yml
prepare: ../default/prepare.yml
cleanup: ../default/cleanup.yml
inventory:
group_vars:
all:
Expand Down
Loading