From 1f98a9b0b77c41d62edea2faf3eee1db1af00766 Mon Sep 17 00:00:00 2001 From: Micah Abbott Date: Fri, 19 May 2017 16:36:57 -0400 Subject: [PATCH 1/4] tests: OpenShift Ansible Installer sanity test This is a 'meta' playbook that borrowed heavily from the work done in 'ansible-ansible-openshift-ansible' [0]. It will install an OpenShift Origin cluster on a single host via the openshift/openshfit-ansible installer. This playbook can be invoked as you would for any other tests in this repo, by supplying an inventory file or hostname/IP address to `ansible-playbook`. The host from the inventory is used to template out a second inventory file which is used when calling `ansible-playbook` on the openshift/openshift-ansible playbook. This, in theory, allows users to maintain the same workflow that is familiar to running other tests in this repo. There are variables defined in the playbook that control the version of OpenShift Origin to be installed, the `git` tag of the openshift/openshift-ansible repo to use, the host where the cluster should be installed, and the Ansible user to use when installing the cluster. These can all be overridden via CLI parameters. This lacks a couple of things that could be added later: - additional checks to determine health of cluster - cleanup/uninstall of the cluster - maybe deploying a project? --- tests/openshift-ansible-test/main.yml | 56 +++++++++++++++++++ .../templates/cluster-inventory.j2 | 27 +++++++++ 2 files changed, 83 insertions(+) create mode 100644 tests/openshift-ansible-test/main.yml create mode 100644 tests/openshift-ansible-test/templates/cluster-inventory.j2 diff --git a/tests/openshift-ansible-test/main.yml b/tests/openshift-ansible-test/main.yml new file mode 100644 index 0000000..8b89165 --- /dev/null +++ b/tests/openshift-ansible-test/main.yml @@ -0,0 +1,56 @@ +--- +# vim: set ft=ansible: +# +- name: OpenShift Ansible Installer Test + hosts: all + + tasks: + - name: Setup vars for templating the inventory, etc. + set_fact: + oo_ansible_user: "{{ cli_ansible_user | default(ansible_user) }}" + oo_ansible_tag: "{{ cli_oo_ansible_tag | default('master') }}" + oo_host: "{{ cli_oo_host | default(ansible_host) }}" + oo_release: "{{ cli_oo_release | default('1.5.1') }}" + + - name: Make temp directory of holding + command: mktemp -d + register: mktemp + delegate_to: localhost + + - name: git clone openshift-ansible repo + git: + repo: "https://github.com/openshift/openshift-ansible.git" + dest: "{{ mktemp.stdout }}" + version: "{{ oo_ansible_tag }}" + delegate_to: localhost + + - name: Template the inventory file + template: + src: "templates/cluster-inventory.j2" + dest: "{{ mktemp.stdout }}/cluster-inventory" + delegate_to: localhost + + - name: Run the openshift-ansible playbook + command: ansible-playbook -i cluster-inventory playbooks/byo/config.yml -e 'ansible_python_interpreter=/usr/bin/python3' + args: + chdir: "{{ mktemp.stdout }}" + delegate_to: localhost + register: playbook + + - name: Wait for 8443 to open up + wait_for: + port: 8443 + delay: 60 + + # this may not be required + - name: Add admin user to cluster-admin role + command: /usr/local/bin/oadm policy add-cluster-role-to-user cluster-admin admin + + - name: Login to the cluster + command: "/usr/local/bin/oc login -u admin -p OriginAdmin https://{{ oo_host }}:8443" + + # this is kind of a hack + - name: Verify pods are running + command: /usr/local/bin/oc get pods -o jsonpath='{.items[*].status.phase}' + register: pods + failed_when: pods.stdout != "Running Running Running" diff --git a/tests/openshift-ansible-test/templates/cluster-inventory.j2 b/tests/openshift-ansible-test/templates/cluster-inventory.j2 new file mode 100644 index 0000000..acb2899 --- /dev/null +++ b/tests/openshift-ansible-test/templates/cluster-inventory.j2 @@ -0,0 +1,27 @@ +[OSEv3:children] +masters +nodes +etcd + +[OSEv3:vars] +ansible_user={{ oo_ansible_user }} +ansible_become=true +deployment_type=origin +containerized=true +openshift_release={{ oo_release }} +openshift_master_default_subdomain={{ oo_host}}.xip.io +openshift_router_selector='router=true' +openshift_registry_selector='registry=true' + +# enable htpasswd auth +openshift_master_identity_providers=[{'name': 'htpasswd_auth', 'login': 'true', 'challenge': 'true', 'kind': 'HTPasswdPasswordIdentityProvider', 'filename': '/etc/origin/master/htpasswd'}] +openshift_master_htpasswd_users={'admin': '$apr1$zgSjCrLt$1KSuj66CggeWSv.D.BXOA1'} + +[masters] +{{ oo_host }} + +[etcd] +{{ oo_host }} + +[nodes] +{{ oo_host }} openshift_schedulable=true openshift_node_labels="{'router':'true','registry':'true'}" From f9f1ca06cc68e532a608af736f088ecec3881c69 Mon Sep 17 00:00:00 2001 From: Micah Abbott Date: Thu, 1 Jun 2017 16:57:32 -0400 Subject: [PATCH 2/4] openshift-ansible-testing: make it work with CentOS + RHEL AH - added symlinks to callback_plugins + roles - introduced new vars to handle public vs private ip addresses - added conditional to skip memory check - added conditional to use Python3 for Fedora only - added README.md --- tests/openshift-ansible-test/README.md | 32 +++++++++++++++++++ tests/openshift-ansible-test/callback_plugins | 1 + tests/openshift-ansible-test/main.yml | 16 ++++++---- tests/openshift-ansible-test/roles | 1 + .../templates/cluster-inventory.j2 | 8 ++--- 5 files changed, 48 insertions(+), 10 deletions(-) create mode 100644 tests/openshift-ansible-test/README.md create mode 120000 tests/openshift-ansible-test/callback_plugins create mode 120000 tests/openshift-ansible-test/roles diff --git a/tests/openshift-ansible-test/README.md b/tests/openshift-ansible-test/README.md new file mode 100644 index 0000000..f7d9509 --- /dev/null +++ b/tests/openshift-ansible-test/README.md @@ -0,0 +1,32 @@ +This playbook performs a sanity test of a stable version of the OpenShift Ansible installer +against an Atomic Host. + +The test accepts normal inventory data as like every other test in the repo, then uses that +data to generate a separate inventory that is used when running the OpenShift Ansible +installer playbook. + +This playbook only does a sanity check that the installer completes successfully and +the expected pods are running afterwards. This does **NOT** perform any conformance +testing or deployment of additional apps/projects afterwards. + +### Prerequisites + - Ansible version 2.2 (other versions are not supported) + + - Configure subscription data (if used) + + If running against a RHEL Atomic Host, you should provide subscription + data that can be used by `subscription-manager`. See + [roles/redhat_subscription/tasks/main.yml](roles/redhat_subscription/tasks/main.yml) + for additional details. + + +### Running the Playbook + +To run the test, simply invoke as any other Ansible playbook: + +``` +$ ansible-playbook -i inventory tests/system-containers/main.yml +``` + +*NOTE*: You are responsible for providing a host to run the test against and the +inventory file for that host. diff --git a/tests/openshift-ansible-test/callback_plugins b/tests/openshift-ansible-test/callback_plugins new file mode 120000 index 0000000..6eabbce --- /dev/null +++ b/tests/openshift-ansible-test/callback_plugins @@ -0,0 +1 @@ +../../callback_plugins/ \ No newline at end of file diff --git a/tests/openshift-ansible-test/main.yml b/tests/openshift-ansible-test/main.yml index 8b89165..586576f 100644 --- a/tests/openshift-ansible-test/main.yml +++ b/tests/openshift-ansible-test/main.yml @@ -9,8 +9,11 @@ set_fact: oo_ansible_user: "{{ cli_ansible_user | default(ansible_user) }}" oo_ansible_tag: "{{ cli_oo_ansible_tag | default('master') }}" - oo_host: "{{ cli_oo_host | default(ansible_host) }}" + oo_public_host: "{{ cli_oo_public_host | default(ansible_host) }}" + oo_host: "{{ cli_oo_host | default(ansible_default_ipv4.address) }}" oo_release: "{{ cli_oo_release | default('1.5.1') }}" + oo_py_interpreter: "{{ '-e ansible_python_interpreter=/usr/bin/python3' if ansible_distribution == 'Fedora' else '' }}" + oo_skip_memory_check: "{{ '-e openshift_disable_check=memory_availability' if ansible_memtotal_mb|int < 8192 else '' }}" - name: Make temp directory of holding command: mktemp -d @@ -31,11 +34,10 @@ delegate_to: localhost - name: Run the openshift-ansible playbook - command: ansible-playbook -i cluster-inventory playbooks/byo/config.yml -e 'ansible_python_interpreter=/usr/bin/python3' + command: "ansible-playbook -i cluster-inventory playbooks/byo/config.yml {{ oo_py_interpreter }} {{ oo_skip_memory_check }}" args: chdir: "{{ mktemp.stdout }}" delegate_to: localhost - register: playbook - name: Wait for 8443 to open up wait_for: @@ -47,10 +49,12 @@ command: /usr/local/bin/oadm policy add-cluster-role-to-user cluster-admin admin - name: Login to the cluster - command: "/usr/local/bin/oc login -u admin -p OriginAdmin https://{{ oo_host }}:8443" + command: "/usr/local/bin/oc login -u admin -p OriginAdmin https://{{ oo_public_host }}:8443" - # this is kind of a hack + # this is kind of a hack; sometimes need to wait (5m) for the pods - name: Verify pods are running command: /usr/local/bin/oc get pods -o jsonpath='{.items[*].status.phase}' register: pods - failed_when: pods.stdout != "Running Running Running" + until: pods.stdout == "Running Running Running" + retries: 10 + delay: 30 diff --git a/tests/openshift-ansible-test/roles b/tests/openshift-ansible-test/roles new file mode 120000 index 0000000..148b132 --- /dev/null +++ b/tests/openshift-ansible-test/roles @@ -0,0 +1 @@ +../../roles/ \ No newline at end of file diff --git a/tests/openshift-ansible-test/templates/cluster-inventory.j2 b/tests/openshift-ansible-test/templates/cluster-inventory.j2 index acb2899..0bfcecc 100644 --- a/tests/openshift-ansible-test/templates/cluster-inventory.j2 +++ b/tests/openshift-ansible-test/templates/cluster-inventory.j2 @@ -9,7 +9,7 @@ ansible_become=true deployment_type=origin containerized=true openshift_release={{ oo_release }} -openshift_master_default_subdomain={{ oo_host}}.xip.io +openshift_master_default_subdomain={{ oo_public_host }}.xip.io openshift_router_selector='router=true' openshift_registry_selector='registry=true' @@ -18,10 +18,10 @@ openshift_master_identity_providers=[{'name': 'htpasswd_auth', 'login': 'true', openshift_master_htpasswd_users={'admin': '$apr1$zgSjCrLt$1KSuj66CggeWSv.D.BXOA1'} [masters] -{{ oo_host }} +{{ oo_public_host }} openshift_public_hostname={{ oo_public_host }} openshift_hostname={{ oo_host }} [etcd] -{{ oo_host }} +{{ oo_public_host }} [nodes] -{{ oo_host }} openshift_schedulable=true openshift_node_labels="{'router':'true','registry':'true'}" +{{ oo_public_host }} openshift_schedulable=true openshift_node_labels="{'router':'true','registry':'true'}" From 8cc0f35fabf283b56d45d2b763f8bdb2f79cdda0 Mon Sep 17 00:00:00 2001 From: Micah Abbott Date: Fri, 2 Jun 2017 17:12:15 -0400 Subject: [PATCH 3/4] fixup! openshift-ansible-testing: make it work with CentOS + RHEL AH --- tests/openshift-ansible-test/README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/openshift-ansible-test/README.md b/tests/openshift-ansible-test/README.md index f7d9509..609336b 100644 --- a/tests/openshift-ansible-test/README.md +++ b/tests/openshift-ansible-test/README.md @@ -19,13 +19,12 @@ testing or deployment of additional apps/projects afterwards. [roles/redhat_subscription/tasks/main.yml](roles/redhat_subscription/tasks/main.yml) for additional details. - ### Running the Playbook To run the test, simply invoke as any other Ansible playbook: ``` -$ ansible-playbook -i inventory tests/system-containers/main.yml +$ ansible-playbook -i inventory tests/openshift-ansible-testing/main.yml ``` *NOTE*: You are responsible for providing a host to run the test against and the From 6ea8e4bf72d711920baaff7ef18882742f70b3e1 Mon Sep 17 00:00:00 2001 From: Micah Abbott Date: Mon, 5 Jun 2017 14:33:05 -0400 Subject: [PATCH 4/4] fixup! openshift-ansible-testing: make it work with CentOS + RHEL AH --- tests/openshift-ansible-test/README.md | 11 +++++++++-- tests/openshift-ansible-test/main.yml | 8 ++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/tests/openshift-ansible-test/README.md b/tests/openshift-ansible-test/README.md index 609336b..bc63cd7 100644 --- a/tests/openshift-ansible-test/README.md +++ b/tests/openshift-ansible-test/README.md @@ -21,11 +21,18 @@ testing or deployment of additional apps/projects afterwards. ### Running the Playbook +*NOTE*: You are responsible for providing a host to run the test against and the +inventory file for that host. + To run the test, simply invoke as any other Ansible playbook: ``` $ ansible-playbook -i inventory tests/openshift-ansible-testing/main.yml ``` -*NOTE*: You are responsible for providing a host to run the test against and the -inventory file for that host. +*NOTE*: If you are running this playbook against a host in the Amazon EC2 environment, it has +been reported you will need to set the `cli_oo_host` variable to the internal IP +address of your EC2 instance. This can be done via the `inventory` file passed in +or on the command line like so: + +`$ ansible-playbok -i inventory -e cli_oo_host=10.0.36.120 tests/openshift-ansible-testing/main.yml` diff --git a/tests/openshift-ansible-test/main.yml b/tests/openshift-ansible-test/main.yml index 586576f..7172c11 100644 --- a/tests/openshift-ansible-test/main.yml +++ b/tests/openshift-ansible-test/main.yml @@ -10,6 +10,14 @@ oo_ansible_user: "{{ cli_ansible_user | default(ansible_user) }}" oo_ansible_tag: "{{ cli_oo_ansible_tag | default('master') }}" oo_public_host: "{{ cli_oo_public_host | default(ansible_host) }}" + # NOTE: If you intend to run the playbook against a host in the Amazon + # EC2 enviroment, it has been reported that you will need to set the + # 'cli_oo_host' variable to the interal IP address of your EC2 + # instance. This can be done via the inventory file or on the command + # line, like so: + # + # $ ansible-playbook -i inventory -e cli_oo_host=10.0.36.120 tests/openshift-ansible-testing/main.yml + # oo_host: "{{ cli_oo_host | default(ansible_default_ipv4.address) }}" oo_release: "{{ cli_oo_release | default('1.5.1') }}" oo_py_interpreter: "{{ '-e ansible_python_interpreter=/usr/bin/python3' if ansible_distribution == 'Fedora' else '' }}"