diff options
Diffstat (limited to 'ansible')
-rw-r--r-- | ansible/roles/application/.gitignore | 1 | ||||
-rw-r--r-- | ansible/roles/application/.yamllint | 11 | ||||
-rw-r--r-- | ansible/roles/application/molecule/default/Dockerfile.j2 | 14 | ||||
-rw-r--r-- | ansible/roles/application/molecule/default/molecule.yml | 60 | ||||
-rw-r--r-- | ansible/roles/application/molecule/default/playbook.yml | 5 | ||||
-rw-r--r-- | ansible/roles/application/molecule/default/prepare.yml | 5 | ||||
-rw-r--r-- | ansible/roles/application/molecule/default/tests/test_default.py | 29 | ||||
-rw-r--r-- | ansible/roles/application/tasks/install.yml | 16 | ||||
-rw-r--r-- | ansible/roles/dns/handlers/main.yml | 3 | ||||
-rw-r--r-- | ansible/roles/dns/tasks/main.yml | 28 | ||||
-rw-r--r-- | ansible/test/roles/prepare-application/defaults/main.yml | 4 | ||||
-rw-r--r-- | ansible/test/roles/prepare-application/tasks/main.yml | 47 |
12 files changed, 196 insertions, 27 deletions
diff --git a/ansible/roles/application/.gitignore b/ansible/roles/application/.gitignore new file mode 100644 index 00000000..155cbb20 --- /dev/null +++ b/ansible/roles/application/.gitignore @@ -0,0 +1 @@ +application/ diff --git a/ansible/roles/application/.yamllint b/ansible/roles/application/.yamllint new file mode 100644 index 00000000..ad0be760 --- /dev/null +++ b/ansible/roles/application/.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/application/molecule/default/Dockerfile.j2 b/ansible/roles/application/molecule/default/Dockerfile.j2 new file mode 100644 index 00000000..e6aa95d3 --- /dev/null +++ b/ansible/roles/application/molecule/default/Dockerfile.j2 @@ -0,0 +1,14 @@ +# Molecule managed + +{% if item.registry is defined %} +FROM {{ item.registry.url }}/{{ item.image }} +{% else %} +FROM {{ item.image }} +{% endif %} + +RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python sudo bash ca-certificates && apt-get clean; \ + elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python sudo python-devel python*-dnf bash && dnf clean all; \ + elif [ $(command -v yum) ]; then yum makecache fast && yum install -y python sudo yum-plugin-ovl bash && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \ + elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python sudo bash python-xml && zypper clean -a; \ + elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates; \ + elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python sudo bash ca-certificates && xbps-remove -O; fi diff --git a/ansible/roles/application/molecule/default/molecule.yml b/ansible/roles/application/molecule/default/molecule.yml new file mode 100644 index 00000000..8f19d7ff --- /dev/null +++ b/ansible/roles/application/molecule/default/molecule.yml @@ -0,0 +1,60 @@ +--- +dependency: + name: galaxy +driver: + name: docker +lint: + name: yamllint +platforms: + - name: instance + image: centos:7 +provisioner: + name: ansible + env: + ANSIBLE_ROLES_PATH: ../../../../test/roles + inventory: + group_vars: + all: + app_name: moleculetestapp + app_data_path: "/opt/{{ app_name }}" + app_helm_release_name: "{{ app_name }}" + app_kubernetes_namespace: "{{ app_name }}" + app_helm_charts_install_directory: application/helm_charts + app_helm_plugins_directory: "{{ app_helm_charts_install_directory}}/helm/plugins/" + app_helm_charts_infra_directory: "{{ app_data_path }}/helm_charts" + helm_bin_dir: /usr/local/bin + app_helm_build_targets: + - all + - onap + app_helm_chart_name: "{{ app_name }}" + application_pre_install_role: + application_post_install_role: + 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: + # * [instance] => application : Get helm dir + # * [instance] => application : Helm init and upgrade + # * [instance] => application : Helm Serve + # * [instance] => application : Helm Add Repo + # * [instance] => application : Helm Install application moleculetestapp + - side_effect + - verify + - cleanup + - destroy +verifier: + name: testinfra + lint: + name: flake8 diff --git a/ansible/roles/application/molecule/default/playbook.yml b/ansible/roles/application/molecule/default/playbook.yml new file mode 100644 index 00000000..4121f124 --- /dev/null +++ b/ansible/roles/application/molecule/default/playbook.yml @@ -0,0 +1,5 @@ +--- +- name: Helm charts available + hosts: all + roles: + - application diff --git a/ansible/roles/application/molecule/default/prepare.yml b/ansible/roles/application/molecule/default/prepare.yml new file mode 100644 index 00000000..8a5288dd --- /dev/null +++ b/ansible/roles/application/molecule/default/prepare.yml @@ -0,0 +1,5 @@ +--- +- name: Prepare infra + hosts: all + roles: + - prepare-application diff --git a/ansible/roles/application/molecule/default/tests/test_default.py b/ansible/roles/application/molecule/default/tests/test_default.py new file mode 100644 index 00000000..3e0cbb42 --- /dev/null +++ b/ansible/roles/application/molecule/default/tests/test_default.py @@ -0,0 +1,29 @@ +import os + +import testinfra.utils.ansible_runner + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') + + +def test_helm_commands(host): + fc = host.file('/tmp/helm_simu_output').content_string + expected_content = """home +init --upgrade --skip-refresh +version --tiller-connection-timeout 10 +repo list +serve +repo list +repo add local http://127.0.0.1:8879 +install --name moleculetestapp local/moleculetestapp --namespace \ +moleculetestapp -f /opt/moleculetestapp/override.yaml""" + assert fc == expected_content + + +def test_helm_override_file(host): + fc = host.file('/opt/moleculetestapp/override.yaml').content_string + expected_content = """global: + cacert: 'this is dummy server certificate value + + '""" + assert fc == expected_content diff --git a/ansible/roles/application/tasks/install.yml b/ansible/roles/application/tasks/install.yml index 103ecc8b..cdc7ced0 100644 --- a/ansible/roles/application/tasks/install.yml +++ b/ansible/roles/application/tasks/install.yml @@ -4,7 +4,7 @@ {{ helm_bin_dir }}/helm init --upgrade --skip-refresh - changed_when: true # init is always changed type of action + changed_when: true # init is always changed type of action # A correct way to implement this would be using --wait option in helm init invocation. # However, it does not work due to https://github.com/helm/helm/issues/4031 (fixed in newer helm release) @@ -14,29 +14,29 @@ until: result.rc == 0 delay: 10 retries: 12 - changed_when: false # for idempotency + changed_when: false # for idempotency - name: Get all helm repos command: "{{ helm_bin_dir }}/helm repo list" register: repos - changed_when: false # for idempotency + changed_when: false # for idempotency - name: Remove stable repo command: "{{ helm_bin_dir }}/helm repo remove stable" - changed_when: true # when executed its a changed type of action + changed_when: true # when executed its a changed type of action when: "'stable' in repos.stdout" - name: Helm Serve shell: "{{ helm_bin_dir }}/helm serve &" async: 45 - poll: 3 # wait 3sec to get a chance for some stderr + poll: 3 # wait 3sec to get a chance for some stderr register: helm_serve changed_when: "'address already in use' not in helm_serve.stderr" - name: List helm repos command: "{{ helm_bin_dir }}/helm repo list" register: helm_repo_list - changed_when: false # for idempotency + changed_when: false # for idempotency failed_when: - helm_repo_list.rc > 0 - "'Error: no repositories to show' not in helm_repo_list.stderr" @@ -44,7 +44,7 @@ - name: Helm Add Repo command: "{{ helm_bin_dir }}/helm repo add {{ helm_repository_name | mandatory }} {{ helm_repository_url | mandatory }}" when: "'local' not in helm_repo_list.stdout" - changed_when: true # when executed its a changed type of action + changed_when: true # when executed its a changed type of action - name: Build local helm repository make: @@ -72,6 +72,6 @@ {{ helm_repository_name }}/{{ app_helm_chart_name }} --namespace {{ app_kubernetes_namespace }} {{ '' if app_skip_helm_override else '-f ' + app_helm_override_file }} - changed_when: true # when executed its a changed type of action + changed_when: true # when executed its a changed type of action register: helm_install failed_when: helm_install.stderr diff --git a/ansible/roles/dns/handlers/main.yml b/ansible/roles/dns/handlers/main.yml index 9d77893a..9e957474 100644 --- a/ansible/roles/dns/handlers/main.yml +++ b/ansible/roles/dns/handlers/main.yml @@ -1,5 +1,5 @@ --- -- name: Restart dns server container +- name: Run dns server container docker_container: name: dns-server image: "{{ dns_server_image }}" @@ -12,3 +12,4 @@ - "53:53/udp" state: started restart_policy: unless-stopped + recreate: true diff --git a/ansible/roles/dns/tasks/main.yml b/ansible/roles/dns/tasks/main.yml index 3eba9fdb..121ee0c4 100644 --- a/ansible/roles/dns/tasks/main.yml +++ b/ansible/roles/dns/tasks/main.yml @@ -8,7 +8,7 @@ template: src: simulated_hosts.j2 dest: "{{ app_data_path }}/cfg/simulated_hosts" - notify: Restart dns server container + notify: Run dns server container - name: Load dns server container docker_image: @@ -16,21 +16,13 @@ load_path: "{{ infra_images_path }}/{{ dns_server_image_tar }}" state: present timeout: 120 - notify: Restart dns server container + notify: Run dns server container -- name: Start dns server container - docker_container: - name: dns-server - network_mode: host - image: "{{ dns_server_image }}" - command: -H /simulated_hosts --log-facility=- - capabilities: NET_ADMIN - dns_servers: - - 127.0.0.1 - volumes: - - "{{ app_data_path }}/cfg/simulated_hosts:/simulated_hosts:ro" - ports: - - "53:53/tcp" - - "53:53/udp" - state: started - restart_policy: unless-stopped +- name: Enumerate running containers + docker_list_containers: + register: containers_list + +- name: Ensure dns container is running + command: /bin/true + notify: Run dns server container + when: "'dns-server' not in containers_list.containers" diff --git a/ansible/test/roles/prepare-application/defaults/main.yml b/ansible/test/roles/prepare-application/defaults/main.yml new file mode 100644 index 00000000..227bd4f0 --- /dev/null +++ b/ansible/test/roles/prepare-application/defaults/main.yml @@ -0,0 +1,4 @@ +--- +simulate_helm: true +app_helm_charts_install_directory: application/helm_charts +helm_simulation_output_file: /tmp/helm_simu_output
\ No newline at end of file diff --git a/ansible/test/roles/prepare-application/tasks/main.yml b/ansible/test/roles/prepare-application/tasks/main.yml new file mode 100644 index 00000000..2f143a07 --- /dev/null +++ b/ansible/test/roles/prepare-application/tasks/main.yml @@ -0,0 +1,47 @@ +--- +- name: Create Application helm charts directory + file: + path: "{{ app_helm_charts_install_directory }}" + state: directory + delegate_to: localhost + +- name: Create Makefile to simulate helm charts dir and make building + copy: + content: | + all: + onap: + dest: "{{ app_helm_charts_install_directory }}/Makefile" + delegate_to: localhost + when: simulate_helm + +- name: Clean previous simulation output file + file: + path: "{{ helm_simulation_output_file }}" + state: absent + +- name: simulate helm binary + copy: + content: | + #!/bin/bash + echo "$@" >> {{ helm_simulation_output_file }} + dest: "{{ helm_bin_dir }}/helm" + mode: 0755 + when: simulate_helm + +- name: Install make + package: + name: make + state: present + +- name: Create local certs dir for dummy certs + file: + path: certs + state: directory + delegate_to: localhost + +- name: Create dummy cert file to simulate offline server certificates in helm install with override.yml file + copy: + content: | + this is dummy server certificate value + dest: certs/rootCA.crt + delegate_to: localhost |