--- /dev/null
+application/
--- /dev/null
+extends: default
+
+rules:
+ braces:
+ max-spaces-inside: 1
+ level: error
+ brackets:
+ max-spaces-inside: 1
+ level: error
+ line-length: disable
+ truthy: disable
--- /dev/null
+# 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
--- /dev/null
+---
+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
--- /dev/null
+---
+- name: Helm charts available
+ hosts: all
+ roles:
+ - application
--- /dev/null
+---
+- name: Prepare infra
+ hosts: all
+ roles:
+ - prepare-application
--- /dev/null
+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
{{ 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)
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"
- 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:
{{ 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
--- /dev/null
+---
+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
--- /dev/null
+---
+- 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