diff --git a/roles/trouter/molecule/default/molecule.yml b/roles/trouter/molecule/default/molecule.yml index cf4b2ac1e..44ede3868 100644 --- a/roles/trouter/molecule/default/molecule.yml +++ b/roles/trouter/molecule/default/molecule.yml @@ -37,9 +37,3 @@ provisioner: inventory: links: host_vars: host_vars -verifier: - name: testinfra - env: - TEST_HOST: "localhost" - options: - verbose: true diff --git a/roles/trouter/molecule/default/tests/test_trouter.py b/roles/trouter/molecule/default/tests/test_trouter.py deleted file mode 100644 index 1ace30fbf..000000000 --- a/roles/trouter/molecule/default/tests/test_trouter.py +++ /dev/null @@ -1,58 +0,0 @@ -"""TRouter Tests""" -import os -import pytest -from hamcrest import assert_that, contains_string, has_length - -test_host = os.environ.get('TEST_HOST') - - -# pylint: disable=redefined-outer-name -@pytest.fixture(scope="module") -def get_ansible_vars(host): - """Define get_ansible_vars""" - java_role = "file=../roles/java/vars/main.yml name=java_role" - common_vars = "file=../../../common/vars/main.yml name=common_vars" - common_defaults = "file=../../../common/defaults/main.yml name=common_defaults" - common_hosts = "file=../../../common/vars/hosts.yml name=common_hosts" - ansible_vars = host.ansible("include_vars", java_role)["ansible_facts"]["java_role"] - ansible_vars.update(host.ansible("include_vars", common_vars)["ansible_facts"]["common_vars"]) - ansible_vars.update(host.ansible("include_vars", common_hosts)["ansible_facts"]["common_hosts"]) - ansible_vars.update(host.ansible("include_vars", common_defaults)["ansible_facts"]["common_defaults"]) - return ansible_vars - -def test_trouter_service_is_running_and_enabled(host): - """Check trouter service""" - trouter = host.service("alfresco-transform-router") - assert_that(trouter.is_running) - assert_that(trouter.is_enabled) - -def test_trouter_log_exists(host, get_ansible_vars): - "Check that ats-atr.log exists in /var/log/alfresco" - with host.sudo(get_ansible_vars['username']): - assert_that(host.file("/var/log/alfresco/ats-atr.log").exists) - -def test_trouter_response(host): - "Check that trouter context is available and returns a HTTP 200 status code" - cmd = host.run("curl -iL http://{}:8095/transform/config".format(test_host)) - http_response = host.run("curl -sL -w '%{http_code}' http://" + test_host + ":8095/transform/config -o /dev/null") - assert_that(http_response.stdout, contains_string("200")) - assert_that(cmd.stdout, contains_string("pdfRendererOptions")) - assert_that(cmd.stdout, contains_string("archiveOptions")) - assert_that(cmd.stdout, contains_string("imageMagickOptions")) - assert_that(cmd.stdout, contains_string("tikaOptions")) - assert_that(cmd.stdout, contains_string("pdfboxOptions")) - assert_that(cmd.stdout, contains_string("textToPdfOptions")) - assert_that(cmd.stdout, contains_string("stringOptions")) - -def test_environment_jvm_opts(host): - "Check that overwritten JVM_OPTS are taken into consideration" - java_processes = host.process.filter(user="alfresco", comm="java") - assert_that(java_processes, has_length(3)) - for java_process in java_processes: - if 'alfresco-transform-router' in java_process.args: - assert_that(java_process.args, contains_string('-Xmx900m')) - assert_that(java_process.args, contains_string('-Xms800m')) - -def test_no_ghostscript(host): - host.run_expect([127], "gs") - host.run_expect([127], "ghostscript") diff --git a/roles/trouter/molecule/default/verify.yml b/roles/trouter/molecule/default/verify.yml new file mode 100644 index 000000000..d5b2ec0a7 --- /dev/null +++ b/roles/trouter/molecule/default/verify.yml @@ -0,0 +1,57 @@ +--- +- name: trouter Tests + hosts: all + become: true + gather_facts: true + vars: + trouter_host: "localhost" + tasks: + - name: Gather service facts + ansible.builtin.service_facts: + + - name: Assert AIO service is running and enabled + ansible.builtin.assert: + that: + - ansible_facts.services['alfresco-transform-router.service'].state == 'running' + - ansible_facts.services['alfresco-transform-router.service'].status == 'enabled' + + - name: Ensure ats-atr.log exists + ansible.builtin.stat: + path: /var/log/alfresco/ats-atr.log + register: atr_log + failed_when: not atr_log.stat.exists + + - name: Call Transform AIO config API and validate response + ansible.builtin.uri: + url: "http://{{ trouter_host }}:8095/transform/config" + return_content: true + register: aio_api_response + + - name: Assert API output includes expected keys + ansible.builtin.assert: + that: + - '"pdfRendererOptions" in aio_api_response.content' + - '"archiveOptions" in aio_api_response.content' + - '"tikaOptions" in aio_api_response.content' + - '"imageMagickOptions" in aio_api_response.content' + - '"pdfboxOptions" in aio_api_response.content' + - '"textToPdfOptions" in aio_api_response.content' + - '"stringOptions" in aio_api_response.content' + fail_msg: "Transform AIO config API missing expected keys." + + - name: Validate JVM memory settings + ansible.builtin.command: "pgrep -fa java" + register: jvm_opts + changed_when: false + failed_when: > + '-Xmx900m' not in jvm_opts.stdout or '-Xms800m' not in jvm_opts.stdout + + - name: Test ghostscript command + ansible.builtin.shell: ghostscript + register: ghostscript_test + failed_when: ghostscript_test.rc != 127 + + - name: Test gs command + ansible.builtin.shell: gs + register: gs_test + failed_when: gs_test.rc != 127