From 287717ae04b05808867f032d918a6508551b5096 Mon Sep 17 00:00:00 2001 From: Tobias Bauriedel Date: Fri, 16 Aug 2024 17:04:04 +0200 Subject: [PATCH] add molecule test for carbonapi --- .github/workflows/molecule_carbonapi.yml | 47 ++++++++++++++++++++++++ README.md | 2 + molecule/carbonapi/converge.yml | 9 +++++ molecule/carbonapi/molecule.yml | 18 +++++++++ molecule/carbonapi/prepare.yml | 9 +++++ molecule/carbonapi/verify.yml | 8 ++++ requirements-test.txt | 7 +++- roles/carbonapi/tasks/setup.yml | 1 + 8 files changed, 99 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/molecule_carbonapi.yml create mode 100644 molecule/carbonapi/converge.yml create mode 100644 molecule/carbonapi/molecule.yml create mode 100644 molecule/carbonapi/prepare.yml create mode 100644 molecule/carbonapi/verify.yml diff --git a/.github/workflows/molecule_carbonapi.yml b/.github/workflows/molecule_carbonapi.yml new file mode 100644 index 0000000..4957703 --- /dev/null +++ b/.github/workflows/molecule_carbonapi.yml @@ -0,0 +1,47 @@ +--- +name: Test role carbonapi + +on: + pull_request: + branches: + - '*' + +jobs: + build: + runs-on: ubuntu-latest + + env: + COLLECTION_NAMESPACE: tbauriedel + COLLECTION_NAME: gographite + + strategy: + matrix: + distro: ['rockylinux8', 'ubuntu2204', 'debian12'] + scenario: ['carbonapi'] + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.10' + + - name: Install dependencies + run: | + python3 -m pip install --upgrade pip + python3 -m pip install -r requirements-test.txt + + - name: Install collection + run: | + mkdir -p ~/.ansible/collections/ansible_collections/$COLLECTION_NAMESPACE + cp -a ../ansible-collection-$COLLECTION_NAME ~/.ansible/collections/ansible_collections/$COLLECTION_NAMESPACE/$COLLECTION_NAME + + - name: Test with molecule + run: | + ansible --version + molecule --version + molecule test -s ${{ matrix.scenario }} + env: + MOLECULE_DISTRO: ${{ matrix.distro }} diff --git a/README.md b/README.md index 344155f..01a2632 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +![Lint](https://github.com/tbauriedel/ansible-collection-gographite/actions/workflows/linting.yml/badge.svg) + # ansible-role-gographite Installs and configures [go-carbon](https://github.com/go-graphite/go-carbon) and [carbonapi](https://github.com/go-graphite/carbonapi). diff --git a/molecule/carbonapi/converge.yml b/molecule/carbonapi/converge.yml new file mode 100644 index 0000000..c6f372d --- /dev/null +++ b/molecule/carbonapi/converge.yml @@ -0,0 +1,9 @@ +--- +- name: Converge + hosts: all + + collections: + - tbauriedel.gographite + + roles: + - carbonapi diff --git a/molecule/carbonapi/molecule.yml b/molecule/carbonapi/molecule.yml new file mode 100644 index 0000000..4efa50d --- /dev/null +++ b/molecule/carbonapi/molecule.yml @@ -0,0 +1,18 @@ +--- +dependency: + name: galaxy +driver: + name: docker +platforms: + - name: carbonapi + image: "geerlingguy/docker-${MOLECULE_DISTRO:-ubuntu2204}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + cgroupns_mode: host + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:rw + privileged: true + pre_build_image: true +provisioner: + name: ansible +verifier: + name: ansible diff --git a/molecule/carbonapi/prepare.yml b/molecule/carbonapi/prepare.yml new file mode 100644 index 0000000..3c5e65f --- /dev/null +++ b/molecule/carbonapi/prepare.yml @@ -0,0 +1,9 @@ +--- +- name: Prepare + hosts: all + tasks: + - name: Install dependencies + ansible.builtin.package: + name: libcairo2 + state: present + when: ansible_os_family == "Debian" diff --git a/molecule/carbonapi/verify.yml b/molecule/carbonapi/verify.yml new file mode 100644 index 0000000..a313635 --- /dev/null +++ b/molecule/carbonapi/verify.yml @@ -0,0 +1,8 @@ +--- +- name: Verify + hosts: all + tasks: + - name: Ensure service is running + ansible.builtin.service: + name: carbonapi + state: started diff --git a/requirements-test.txt b/requirements-test.txt index 48133f2..c89f44b 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -1,3 +1,6 @@ -ansible-core +ansible-core==2.16.3 ansible-lint -yamllint \ No newline at end of file +yamllint +molecule +molecule-docker +requests \ No newline at end of file diff --git a/roles/carbonapi/tasks/setup.yml b/roles/carbonapi/tasks/setup.yml index fee6be3..c860978 100644 --- a/roles/carbonapi/tasks/setup.yml +++ b/roles/carbonapi/tasks/setup.yml @@ -18,6 +18,7 @@ ansible.builtin.dnf: name: "{{ _fetched_source.dest }}" state: present + disable_gpg_check: true when: ansible_os_family == 'RedHat' - name: Ensure config-dir exists