diff options
-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 | ||||
-rwxr-xr-x | build/creating_data/docker-images-collector.sh | 118 | ||||
-rwxr-xr-x | build/creating_data/download-bin-tools.sh | 18 |
14 files changed, 325 insertions, 34 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 diff --git a/build/creating_data/docker-images-collector.sh b/build/creating_data/docker-images-collector.sh new file mode 100755 index 00000000..e13b9150 --- /dev/null +++ b/build/creating_data/docker-images-collector.sh @@ -0,0 +1,118 @@ +#! /usr/bin/env bash + +# COPYRIGHT NOTICE STARTS HERE +# +# Copyright 2019 © Samsung Electronics Co., Ltd. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# COPYRIGHT NOTICE ENDS HERE + +### This script is preparing docker images list based on kubernetes project + +### NOTE: helm needs to be installed and working, it is required for correct processing +### of helm charts in oom directory + +# Fail fast settings +set -e + +usage () { + echo " " + echo " This script is preparing docker images list based on kubernetes project" + echo " Usage:" + echo " ./$(basename $0) <project version> <path to project> [<output list file>]" + echo " " + echo " Example: ./$(basename $0) onap_3.0.2 /root/oom/kubernetes/onap" + echo " " + echo " Dependencies: helm, python-yaml, make" + echo " " + exit 1 +} + +parse_yaml() { +python - <<PYP +#!/usr/bin/python +from __future__ import print_function +import yaml +import sys + +with open("${1}", 'r') as f: + values = yaml.load(f) + + enabled = filter(lambda x: values[x].get('enabled', False) == True, values) + print(' '.join(enabled)) +PYP +} + +create_list() { + helm template "${PROJECT_DIR}/../${1}" | grep 'image:\ \|tag_version:\ \|h._image' | + sed -e 's/^.*\"h._image\"\ :\ //; s/^.*\"\(.*\)\".*$/\1/' \ + -e 's/\x27\|,//g; s/^.*\(image\|tag_version\):\ //' | tr -d '\r' +} + +# Configuration +TAG="${1}" +PROJECT_DIR="${2}" +LIST="${3}" +LISTS_DIR="$(readlink -f $(dirname ${0}))/../data_lists" +HELM_REPO="local http://127.0.0.1:8879" + +if [ "${1}" == "-h" ] || [ "${1}" == "--help" ] || [ $# -lt 2 ]; then + usage +elif [ ! -f "${PROJECT_DIR}/../Makefile" ]; then + echo "Wrong path to project directory entered" + exit 1 +elif [ -z "${LIST}" ]; then + mkdir -p ${LISTS_DIR} + LIST="${LISTS_DIR}/${TAG}-docker_images.list" +fi + +if [ -e "${LIST}" ]; then + mv -f "${LIST}" "${LIST}.bk" + MSG="$(realpath ${LIST}) already existed\nCreated backup $(realpath ${LIST}).bk\n" +fi + +PROJECT="$(basename ${2})" + +# Setup helm +if pgrep -x "helm" > /dev/null; then + echo "helm is already running" +else + helm init -c > /dev/null + helm serve & +fi + +# Create helm repository +if ! helm repo list 2>&1 | awk '{ print $1, $2 }' | grep -q "$HELM_REPO" > /dev/null; then + helm repo add "$HELM_REPO" +fi + +# Make all +pushd "${PROJECT_DIR}/.." +echo "Building project..." +make all > /dev/null; make ${PROJECT} > /dev/null +popd + +# Create the list from all enabled subsystems +echo "Creating the list..." +if [ "${PROJECT}" == "onap" ]; then + for subsystem in `parse_yaml "${PROJECT_DIR}/values.yaml"`; do + create_list ${subsystem} + done +else + create_list ${PROJECT} +fi | sort -u > ${LIST} + +echo -e ${MSG} +echo -e 'The list has been created:\n '"${LIST}" +exit 0 diff --git a/build/creating_data/download-bin-tools.sh b/build/creating_data/download-bin-tools.sh index a87fa204..327e210f 100755 --- a/build/creating_data/download-bin-tools.sh +++ b/build/creating_data/download-bin-tools.sh @@ -1,6 +1,6 @@ # COPYRIGHT NOTICE STARTS HERE # -# Copyright 2018 © Samsung Electronics Co., Ltd. +# Copyright 2018-2019 © Samsung Electronics Co., Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -20,7 +20,7 @@ usage () { echo "Usage:" echo -e "./$(basename $0) [destination directory]\n" echo "Examples:" - echo " ./$(basename $0) ./git-repo" + echo " ./$(basename $0) ./downloads" } if [ "${1}" == "-h" ] || [ -z "${1}" ] ; then @@ -30,9 +30,10 @@ else OUTDIR="${1}" fi -# we are keeping just casablanca support in casablanca branch -KUBECTL_VERSION=${KUBECTL_VERSION:-1.11.2} -HELM_VERSION=${HELM_VERSION:-2.9.1} +# we are keeping just dublin support in dublin branch +KUBECTL_VERSION=${KUBECTL_VERSION:-1.13.5} +HELM_VERSION=${HELM_VERSION:-2.12.3} +RKE_VERSION=${RKE_VERSION:-0.2.1} mkdir -p "$OUTDIR" cd "$OUTDIR" @@ -42,7 +43,7 @@ download() { url_file="${url%%\?*}" file=$(basename "$url_file") echo "Downloading $url" - curl --retry 5 -y 10 -Y 10 --location "$url" -o "$file" + curl -s --retry 5 -y 10 -Y 10 --location "$url" -o "$file" } download "https://storage.googleapis.com/kubernetes-release/release/v${KUBECTL_VERSION}/bin/linux/amd64/kubectl" @@ -51,6 +52,9 @@ download "https://storage.googleapis.com/kubernetes-helm/helm-v${HELM_VERSION}-l tar -xf ./helm-v${HELM_VERSION}-linux-amd64.tar.gz linux-amd64/helm -O > helm rm -f ./helm-v${HELM_VERSION}-linux-amd64.tar.gz -chmod a+x ./helm ./kubectl +download "https://github.com/rancher/rke/releases/download/v${RKE_VERSION}/rke_linux-amd64" +mv rke_linux-amd64 rke + +chmod a+x ./helm ./kubectl ./rke exit 0 |