diff options
author | Samuli Silvius <s.silvius@partner.samsung.com> | 2019-04-04 08:22:08 +0300 |
---|---|---|
committer | Samuli Silvius <s.silvius@partner.samsung.com> | 2019-04-17 09:30:59 +0300 |
commit | bb3bef83ca562b9aadc288b3ec46264d73ec73ac (patch) | |
tree | 269f5624b39b14cfe249099df11f962147967d0e /ansible/roles/rancher | |
parent | cceed25e6c773c18e479e246ddeadebc82870f70 (diff) |
Molecule tests for rancher role
Issue-ID: OOM-1775
Change-Id: I6ea11db932cd77e03909e4c72acc4b92a544eb4b
Signed-off-by: Samuli Silvius <s.silvius@partner.samsung.com>
Diffstat (limited to 'ansible/roles/rancher')
-rw-r--r-- | ansible/roles/rancher/.yamllint | 11 | ||||
-rw-r--r-- | ansible/roles/rancher/defaults/main.yml | 2 | ||||
-rw-r--r-- | ansible/roles/rancher/molecule/default/cleanup.yml | 14 | ||||
-rw-r--r-- | ansible/roles/rancher/molecule/default/group_vars/all.yml | 2 | ||||
-rw-r--r-- | ansible/roles/rancher/molecule/default/molecule.yml | 91 | ||||
-rw-r--r-- | ansible/roles/rancher/molecule/default/playbook.yml | 28 | ||||
-rw-r--r-- | ansible/roles/rancher/molecule/default/prepare.yml | 5 | ||||
-rw-r--r-- | ansible/roles/rancher/tasks/rancher_health.yml | 4 |
8 files changed, 155 insertions, 2 deletions
diff --git a/ansible/roles/rancher/.yamllint b/ansible/roles/rancher/.yamllint new file mode 100644 index 00000000..ad0be760 --- /dev/null +++ b/ansible/roles/rancher/.yamllint @@ -0,0 +1,11 @@ +extends: default + +rules: + braces: + max-spaces-inside: 1 + level: error + brackets: + max-spaces-inside: 1 + level: error + line-length: disable + truthy: disable diff --git a/ansible/roles/rancher/defaults/main.yml b/ansible/roles/rancher/defaults/main.yml index 8edc5180..6ab52e64 100644 --- a/ansible/roles/rancher/defaults/main.yml +++ b/ansible/roles/rancher/defaults/main.yml @@ -2,3 +2,5 @@ rancher_server_url: "http://{{ hostvars[groups.infrastructure.0].ansible_host }}:8080" rancher_remove_other_env: true rancher_redeploy_k8s_env: true +rancher_cluster_health_state: healthy +rancher_cluster_health_check_retries: 30 diff --git a/ansible/roles/rancher/molecule/default/cleanup.yml b/ansible/roles/rancher/molecule/default/cleanup.yml new file mode 100644 index 00000000..13b48278 --- /dev/null +++ b/ansible/roles/rancher/molecule/default/cleanup.yml @@ -0,0 +1,14 @@ +--- +- name: Cleanup host + hosts: localhost + roles: + - role: cleanup-containers + vars: + container_list: + - rancher-agent + - rancher-server + # For some reason getting error "Device busy error" when trying to delete directory with root privileges and rancher-containers not anymore running. + # - role: cleanup-directories + # vars: + # directories_files_list_to_remove: + # - /var/lib/rancher/ diff --git a/ansible/roles/rancher/molecule/default/group_vars/all.yml b/ansible/roles/rancher/molecule/default/group_vars/all.yml new file mode 100644 index 00000000..107377cf --- /dev/null +++ b/ansible/roles/rancher/molecule/default/group_vars/all.yml @@ -0,0 +1,2 @@ +--- +app_name: molecule-test-app diff --git a/ansible/roles/rancher/molecule/default/molecule.yml b/ansible/roles/rancher/molecule/default/molecule.yml new file mode 100644 index 00000000..e6152d55 --- /dev/null +++ b/ansible/roles/rancher/molecule/default/molecule.yml @@ -0,0 +1,91 @@ +--- +dependency: + name: galaxy +driver: + name: docker +lint: + name: yamllint +platforms: + - name: infrastructure-server + image: molecule-${PREBUILD_PLATFORM_DISTRO:-centos}:${PREBUILD_DISTRO_VERSION:-centos7.6} + pre_build_image: true + privileged: true + override_command: false + restart_policy: unless-stopped + env: + container: docker + volumes: + - /var/run/docker.sock:/var/run/docker.sock + - /var/lib/rancher:/var/lib/rancher:ro + groups: + - infrastructure + networks: + - name: rancher + + - name: kubernetes-node-1 + image: molecule-${PREBUILD_PLATFORM_DISTRO:-centos}:${PREBUILD_DISTRO_VERSION:-centos7.6} + pre_build_image: true + privileged: true + override_command: false + restart_policy: unless-stopped + env: + container: docker + volumes: + - /var/run/docker.sock:/var/run/docker.sock + - /var/lib/rancher:/var/lib/rancher:ro + groups: + - kubernetes + networks: + - name: rancher + +provisioner: + name: ansible + env: + ANSIBLE_ROLES_PATH: ../../../../test/roles + ANSIBLE_LIBRARY: ../../../../library + inventory: + links: + group_vars: ../../../../group_vars + # 1) When running with molecule-dev container, use this definition and comment out localhost under host_vars (2) + hosts: + all: + hosts: + localhost: + ansible_connection: ssh + ansible_host: ${LOCALHOST_ANSIBLE_HOST:-""} + ansible_user: ${LOCALHOST_ANSIBLE_USER:-""} + ansible_password: ${LOCALHOST_ANSIBLE_PASSWORD:-""} + ansible_sudo_pass: ${LOCALHOST_ANSIBLE_SUDO_PASS:-""} + # end of 1) + # 2) When running with native molecule installation, use this definition and comment out hosts section under inventory (1) + # host_vars: + # localhost: + # ansible_sudo_pass: ${LOCALHOST_ANSIBLE_SUDO_PASS:-""} + # ansible_ssh_pass: ${LOCALHOST_ANSIBLE_PASSWORD:-""} + # End of 2) + lint: + name: ansible-lint +scenario: + name: default + test_sequence: + - lint + - cleanup + - destroy + - dependency + - syntax + - create + - prepare + - converge + # - idempotence + # --> Action: 'idempotence' + # ERROR: Idempotence test failed because of the following tasks: + # * [infrastructure-server] => rancher : Create rancher kubernetes environment + # * [kubernetes-node-1] => rancher : Add Rancher Agent + - side_effect + - verify + - cleanup + - destroy +verifier: + name: testinfra + lint: + name: flake8 diff --git a/ansible/roles/rancher/molecule/default/playbook.yml b/ansible/roles/rancher/molecule/default/playbook.yml new file mode 100644 index 00000000..e0ef086c --- /dev/null +++ b/ansible/roles/rancher/molecule/default/playbook.yml @@ -0,0 +1,28 @@ +--- +- name: Converge rancher master + hosts: infrastructure + roles: + - prepare-common # molecule specific role needed here to populate cluster_ip + - role: rancher + vars: + mode: server + rancher_server_url: "http://{{ cluster_ip }}:8080" + +- name: Converge rancher agent + hosts: kubernetes + roles: + - role: rancher + vars: + mode: agent + +- name: Wait for Kubernetes environment to be healthy + hosts: infrastructure + roles: + - role: rancher + vars: + mode: health + rancher_server_url: "http://{{ cluster_ip }}:8080" + # Do not get rancher cluster healthy in this env (to be checked), + # but it's enough in molecule test to verify we get this unhealthy response + rancher_cluster_health_state: unhealthy + rancher_cluster_health_check_retries: 40 diff --git a/ansible/roles/rancher/molecule/default/prepare.yml b/ansible/roles/rancher/molecule/default/prepare.yml new file mode 100644 index 00000000..90159c6c --- /dev/null +++ b/ansible/roles/rancher/molecule/default/prepare.yml @@ -0,0 +1,5 @@ +--- +- name: Prepare kube nodes + hosts: kubernetes + roles: + - prepare-docker diff --git a/ansible/roles/rancher/tasks/rancher_health.yml b/ansible/roles/rancher/tasks/rancher_health.yml index b0323739..b6e8d68b 100644 --- a/ansible/roles/rancher/tasks/rancher_health.yml +++ b/ansible/roles/rancher/tasks/rancher_health.yml @@ -3,6 +3,6 @@ uri: url: "{{ rancher_server_url }}/v2-beta/projects/{{ k8s_env_id }}" register: env_info - retries: 30 + retries: "{{ rancher_cluster_health_check_retries }}" delay: 15 - until: "env_info.json.healthState == 'healthy'" + until: env_info.json.healthState == rancher_cluster_health_state |