From a26346a9e47dfb76f3d7e6f5209634cba990aaea Mon Sep 17 00:00:00 2001 From: Dawa Ometto Date: Tue, 1 Oct 2024 11:28:25 +0200 Subject: [PATCH] More accurately simulate component execution on workspace in tests --- .github/workflows/molecule.yml | 2 ++ molecule/default/converge.yml | 24 ++++++++++++++++++------ molecule/default/molecule.yml | 2 +- molecule/default/prepare.yml | 11 +++++++++++ molecule/requirements.yml | 5 +++++ 5 files changed, 37 insertions(+), 7 deletions(-) create mode 100644 molecule/requirements.yml diff --git a/.github/workflows/molecule.yml b/.github/workflows/molecule.yml index 1a1d1db..f73c272 100644 --- a/.github/workflows/molecule.yml +++ b/.github/workflows/molecule.yml @@ -17,6 +17,7 @@ jobs: ANSIBLE_STDOUT_CALLBACK: yaml CRUN_VER: 1.11.2 REQUIREMENTS_FILE: molecule/requirements.txt + ANSIBLE_GALAXY_REQUIREMENTS_FILE: molecule/requirements.yml BOOTSTRAP_KEY: foobar # defines an api bootstrap key for the molecule tests steps: - name: Workaround crun issue on ubuntu @@ -41,6 +42,7 @@ jobs: with: python-version: '3.11' - run: pip install -r ${{ env.REQUIREMENTS_FILE }} + - run: ansible-galaxy install -r ${{ env.ANSIBLE_GALAXY_REQUIREMENTS_FILE }} - name: Molecule tests run: | BOOTSTRAP_KEY=${{ env.BOOTSTRAP_KEY }} molecule -vvv test --all diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml index 5b2faeb..1ddd2c1 100644 --- a/molecule/default/converge.yml +++ b/molecule/default/converge.yml @@ -2,10 +2,22 @@ - name: Converge hosts: all gather_facts: false - -- name: Run playbook as test - ansible.builtin.import_playbook: ../../galaxysrv.yml vars: - src_galaxy_tool_files: "{{ playbook_dir ~ '/molecule/_testfiles/tool_list.yaml.sample' }}" - src_galaxy_workflow_files: "{{ playbook_dir ~ '/molecule/_testfiles/sample-workflow.ga' }}" - src_ibridges: 'true' + component: + name: galaxy + path: galaxysrv.yml + arguments: -i 127.0.0.1, --skip-tags {{ ansible_skip_tags | join(',') }} + parameters: + src_galaxy_tool_files: "{{ playbook_dir ~ '/molecule/_testfiles/tool_list.yaml.sample' }}" + src_galaxy_workflow_files: "{{ playbook_dir ~ '/molecule/_testfiles/sample-workflow.ga' }}" + src_ibridges: 'true' + tasks: + + - name: Test the component by executing it using ansible on the workspace + ansible.builtin.command: > + ansible-playbook -c local -v -b {{ component.arguments }} --extra-vars='{{ component.parameters | to_json }}' /usr/local/{{ component.name }}/{{ component.path }} + register: ansible_on_workspace + changed_when: > + ansible_on_workspace.stdout_lines is not defined or + 'changed=0' not in + ansible_on_workspace.stdout_lines[ lookup('ansible.utils.index_of', ansible_on_workspace.stdout_lines, 'regex', '\s*PLAY RECAP\s*')+1 ] diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml index a669883..25f19f1 100644 --- a/molecule/default/molecule.yml +++ b/molecule/default/molecule.yml @@ -10,7 +10,7 @@ driver: password: $DOCKER_PW platforms: - name: workspace-src-ubuntu_jammy - image: ghcr.io/utrechtuniversity/src-test-workspace:ubuntu_jammy + image: ghcr.io/utrechtuniversity/src-test-workspace:ubuntu_jammy-pilot <<: *image_settings command: /sbin/init volumes: diff --git a/molecule/default/prepare.yml b/molecule/default/prepare.yml index 64e64cc..74a974b 100644 --- a/molecule/default/prepare.yml +++ b/molecule/default/prepare.yml @@ -13,6 +13,17 @@ version: 9.4.0 state: present + - name: Copy local component + ansible.posix.synchronize: + src: ../../../ + dest: /usr/local/galaxy + archive: false + links: true + recursive: true + rsync_opts: + - --exclude=".*" + ssh_connection_multiplexing: true + - name: Run nginx component ansible.builtin.import_playbook: ../../plugin-nginx/plugin-nginx.yml vars: diff --git a/molecule/requirements.yml b/molecule/requirements.yml new file mode 100644 index 0000000..826f625 --- /dev/null +++ b/molecule/requirements.yml @@ -0,0 +1,5 @@ +--- +collections: + - name: ansible.posix + - name: community.general + - name: ansible.utils