From e11f9c900a062c335fe88e137d29b5278ae64b39 Mon Sep 17 00:00:00 2001 From: Michael Nguyen Date: Thu, 24 May 2018 15:55:40 -0400 Subject: [PATCH] k8-cluster: continue on failure Convert the k8-cluster test to the `continue on failure. Addresses issue #375. --- tests/k8-cluster/cleanup.yml | 19 +++ tests/k8-cluster/main.yml | 163 ++++++----------------- tests/k8-cluster/setup.yml | 45 +++++++ tests/k8-cluster/single_node_cluster.yml | 40 ++++++ 4 files changed, 148 insertions(+), 119 deletions(-) create mode 100644 tests/k8-cluster/cleanup.yml create mode 100644 tests/k8-cluster/setup.yml create mode 100644 tests/k8-cluster/single_node_cluster.yml diff --git a/tests/k8-cluster/cleanup.yml b/tests/k8-cluster/cleanup.yml new file mode 100644 index 0000000..00d185b --- /dev/null +++ b/tests/k8-cluster/cleanup.yml @@ -0,0 +1,19 @@ +--- +# set ft=ansible +# + +- import_role: + name: k8_remove_all + tags: + - k8_remove_all + +- import_role: + name: docker_remove_all + tags: + - docker_remove_all + +- when: ansible_distribution == 'RedHat' + import_role: + name: redhat_unsubscribe + tags: + - redhat_unsubscribe diff --git a/tests/k8-cluster/main.yml b/tests/k8-cluster/main.yml index a680bbb..746e926 100644 --- a/tests/k8-cluster/main.yml +++ b/tests/k8-cluster/main.yml @@ -1,122 +1,47 @@ ---- -# vim: set ft=ansible: -# -# This playbook creates a kubernetes cluster on a single system using the -# example in the Red Hat documentation. The cluster contains a database -# and a webserver pod with data from the database to present a webpage that -# says "Red Hat Rocks!" -# -# Execution Steps: -# 1. Subscribe to RedHat if running RHEL Atomic Host -# 2. Create an insecure private registry -# 3. Copy over the mariadb and apache webserver Dockerfile and supporting -# files, build the docker image, tag the image, then push to the private -# registry. -# 4. Setup and start the kubernetes pods -# 5. Setup and start the mariadb and webserver pods -# 6. Verify that the pods are running and that the mariadb and webserver -# can communicate through the kubernetes services -# -- name: k8-cluster +- name: Kubernetes Cluster - Test Suite hosts: all become: true -# This giant mess of pre-tasks is here to workaround the problem that is fixed -# in this PR - https://github.com/projectatomic/atomic/pull/1185 -# -# The fallout from that missing functionality is that the 'kube-proxy' system -# container will not start correctly unless atomic 1.22 is used to install -# the system container with the right SELinux labels. - - pre_tasks: - - import_role: - name: rpm_version - vars: - rv_rpms: atomic - - - when: - - ansible_distribution == 'Fedora' - - ansible_distribution_major_version | version_compare('26', '>') - - g_atomic_host is defined - - g_atomic_host['atomic'] | version_compare('1.22', '<=') - block: - - name: Grab the atomic 1.22 RPMs - get_url: - url: "{{ item }}" - dest: /root/ - with_items: - - https://kojipkgs.fedoraproject.org//packages/atomic/1.22.1/1.fc27/x86_64/atomic-1.22.1-1.fc27.x86_64.rpm - - https://kojipkgs.fedoraproject.org//packages/atomic/1.22.1/1.fc27/x86_64/atomic-registries-1.22.1-1.fc27.x86_64.rpm - - - name: Override the atomic package - command: rpm-ostree override replace /root/atomic-1.22.1-1.fc27.x86_64.rpm /root/atomic-registries-1.22.1-1.fc27.x86_64.rpm - - - import_role: - name: reboot - - roles: - - role: ansible_version_check - tags: - - ansible_version_check - - - role: osname_set_fact - tags: - - osname_set_fact - - - when: ansible_distribution == 'RedHat' - role: redhat_subscription - tags: - - redhat_subscription - - - role: docker_private_registry - tags: - - docker_private_registry - - - role: docker_build_tag_push - tags: - - docker_build_tag_push - - - when: ansible_distribution == "CentOSDev" - role: resize_lv - rl_lvname: 'root' - rl_lvsize: '6' - tags: - - resize_lv - - - role: kubernetes_setup - tags: - - kubernetes_setup - - - role: k8_cluster_services_rc_setup - tags: - - k8_cluster_services_rc_setup - - post_tasks: - - name: Check if everything works! - shell: curl http://localhost:80/cgi-bin/action | grep "RedHat rocks" - register: curl - retries: 6 - delay: 10 - until: curl|success - - -- name: Kubernetes Cluster - Cleanup - hosts: all - become: true - - tags: - - cleanup - - roles: - - role: k8_remove_all - tags: - - k8_remove_all - - - role: docker_remove_all - tags: - - docker_remove_all - - - when: ansible_distribution == 'RedHat' - role: redhat_unsubscribe - tags: - - redhat_unsubscribe + vars: + tests: [] + + tasks: + - name: Set logging + set_fact: + log_results: true + result_file: "{{ playbook_dir }}/k8-cluster-result.log" + tags: setup + + - include_tasks: 'setup.yml' + tags: setup + + # TEST + # Verify setup of single node kubernetes cluster + - block: + - include_tasks: 'single_node_cluster.yml' + - set_fact: + tests: "{{ tests + [ { 'name':'Single Node Kubernetes Test', 'result':'Passed', 'result_details': '' } ] }}" + rescue: + - set_fact: + tests: "{{ tests + [ { 'name':'Single Node Kubernetes Test', 'result':'Failed', 'result_details': ansible_failed_result } ] }}" + tags: single_node_cluster + + # CLEANUP + - block: + - include_tasks: 'cleanup.yml' + - set_fact: + tests: "{{ tests + [ { 'name': 'Cleanup', 'result':'Passed', 'result_details': '' } ] }}" + rescue: + - set_fact: + tests: "{{ tests + [ { 'name':'Cleanup', 'result':'Failed', 'result_details': ansible_failed_result } ] }}" + always: + # WRITE RESULTS TO FILE + - name: Remove existing log files + local_action: file path={{ result_file }} state=absent + become: false + + - name: Save result to file + when: log_results + local_action: copy content={{ tests | to_nice_yaml(indent=2) }} dest={{ result_file }} + become: false + tags: cleanup diff --git a/tests/k8-cluster/setup.yml b/tests/k8-cluster/setup.yml new file mode 100644 index 0000000..5907da0 --- /dev/null +++ b/tests/k8-cluster/setup.yml @@ -0,0 +1,45 @@ +--- +# set ft=ansible +# + +- import_role: + name: ansible_version_check + tags: + - ansible_version_check + +- import_role: + name: osname_set_fact + tags: + - osname_set_fact + +- when: ansible_distribution == 'RedHat' + import_role: + name: redhat_subscription + tags: + - redhat_subscription + +- import_role: + name: rpm_version + vars: + rv_rpms: atomic + +- when: + - ansible_distribution == 'Fedora' + - ansible_distribution_major_version | version_compare('26', '>') + - g_atomic_host is defined + - g_atomic_host['atomic'] | version_compare('1.22', '<=') + block: + - name: Grab the atomic 1.22 RPMs + get_url: + url: "{{ item }}" + dest: /root/ + with_items: + - https://kojipkgs.fedoraproject.org//packages/atomic/1.22.1/1.fc27/x86_64/atomic-1.22.1-1.fc27.x86_64.rpm + - https://kojipkgs.fedoraproject.org//packages/atomic/1.22.1/1.fc27/x86_64/atomic-registries-1.22.1-1.fc27.x86_64.rpm + + - name: Override the atomic package + command: rpm-ostree override replace /root/atomic-1.22.1-1.fc27.x86_64.rpm /root/atomic-registries-1.22.1-1.fc27.x86_64.rpm + + - import_role: + name: reboot + diff --git a/tests/k8-cluster/single_node_cluster.yml b/tests/k8-cluster/single_node_cluster.yml new file mode 100644 index 0000000..2ff16e9 --- /dev/null +++ b/tests/k8-cluster/single_node_cluster.yml @@ -0,0 +1,40 @@ +--- +# set ft=ansible +# + +- import_role: + name: docker_private_registry + tags: + - docker_private_registry + +- import_role: + name: docker_build_tag_push + tags: + - docker_build_tag_push + +- when: ansible_distribution == "CentOSDev" + import_role: + name: resize_lv + vars: + rl_lvname: 'root' + rl_lvsize: '6' + tags: + - resize_lv + +- import_role: + name: kubernetes_setup + tags: + - kubernetes_setup + +- import_role: + name: k8_cluster_services_rc_setup + tags: + - k8_cluster_services_rc_setup + +- name: Check if everything works! + shell: curl http://localhost:80/cgi-bin/action | grep "RedHat rocks" + register: curl + retries: 6 + delay: 10 + until: curl|success +