From c491896c842341aafc34a1a6f4da5f80cc931b95 Mon Sep 17 00:00:00 2001 From: Guido Grazioli Date: Tue, 24 Sep 2024 19:33:04 +0200 Subject: [PATCH 1/2] Fix mirroring template --- molecule/mirroring/converge.yml | 47 +++++++++++ molecule/mirroring/molecule.yml | 77 +++++++++++++++++++ molecule/mirroring/prepare.yml | 6 ++ molecule/mirroring/roles | 1 + molecule/mirroring/verify.yml | 71 +++++++++++++++++ .../broker_connections.broker.xml.j2 | 2 +- 6 files changed, 203 insertions(+), 1 deletion(-) create mode 100644 molecule/mirroring/converge.yml create mode 100644 molecule/mirroring/molecule.yml create mode 100644 molecule/mirroring/prepare.yml create mode 120000 molecule/mirroring/roles create mode 100644 molecule/mirroring/verify.yml diff --git a/molecule/mirroring/converge.yml b/molecule/mirroring/converge.yml new file mode 100644 index 00000000..b90d5fc7 --- /dev/null +++ b/molecule/mirroring/converge.yml @@ -0,0 +1,47 @@ +--- +- name: Converge + hosts: all + gather_facts: yes + vars: + activemq_cluster_enabled: false + activemq_ha_enabled: false + activemq_shared_storage: false + activemq_replication: false + activemq_scale_down_enabled: false + activemq_configure_firewalld: false + activemq_systemd_wait_for_log: false + activemq_systemd_wait_for_port: true + activemq_cluster_discovery: "provided" + activemq_nio_enabled: true + activemq_cors_strict_checking: false + activemq_prometheus_enabled: false + activemq_acceptors: + - name: "{{ inventory_hostname }}" + bind_address: 0.0.0.0 + bind_port: "{{ activemq_port }}" + parameters: + tcpSendBufferSize: 1048576 + tcpReceiveBufferSize: 1048576 + protocols: AMQP + useEpoll: true + sslEnabled: false + activemq_addresses: + - name: queue.in + anycast: + - name: queue.in + - name: queue.out + anycast: + - name: queue.out + - name: DLQ + anycast: + - name: DLQ + parameters: + durable: True + - name: ExpiryQueue + anycast: + - name: ExpiryQueue + - name: a.test + anycast: + - name: a.test + roles: + - middleware_automation.amq.activemq diff --git a/molecule/mirroring/molecule.yml b/molecule/mirroring/molecule.yml new file mode 100644 index 00000000..6f802395 --- /dev/null +++ b/molecule/mirroring/molecule.yml @@ -0,0 +1,77 @@ +--- +driver: + name: docker +platforms: + - name: instance1 + image: registry.access.redhat.com/ubi9/ubi-init:latest + pre_build_image: true + privileged: true + command: "/usr/sbin/init" + networks: + - name: amq + tmpfs: + - /run + - /tmp + - name: instance2 + image: registry.access.redhat.com/ubi9/ubi-init:latest + pre_build_image: true + privileged: true + command: "/usr/sbin/init" + networks: + - name: amq + tmpfs: + - /run + - /tmp +provisioner: + name: ansible + config_options: + defaults: + interpreter_python: auto_silent + ssh_connection: + pipelining: false + playbooks: + prepare: prepare.yml + converge: converge.yml + verify: verify.yml + inventory: + host_vars: + localhost: + ansible_python_interpreter: "{{ ansible_playbook_python }}" + instance1: + activemq_broker_connections: + - uri: "tcp://instance2:{{ activemq_port }}" + name: DC2 + sync: true + user: amq-broker + password: amq-broker + operations: + - type: mirror + parameters: + queue_removal: false + instance2: + activemq_broker_connections: + - uri: "tcp://instance1:{{ activemq_port }}" + name: DC1 + sync: true + user: amq-broker + password: amq-broker + operations: + - type: mirror + parameters: + queue_removal: false + env: + ANSIBLE_FORCE_COLOR: "true" +verifier: + name: ansible +scenario: + test_sequence: + - cleanup + - destroy + - create + - prepare + - converge + - idempotence + - side_effect + - verify + - cleanup + - destroy diff --git a/molecule/mirroring/prepare.yml b/molecule/mirroring/prepare.yml new file mode 100644 index 00000000..f17db3a2 --- /dev/null +++ b/molecule/mirroring/prepare.yml @@ -0,0 +1,6 @@ +--- +- name: Prepare + hosts: all + tasks: + - name: "Run preparation common to all scenario" + ansible.builtin.include_tasks: ../prepare.yml diff --git a/molecule/mirroring/roles b/molecule/mirroring/roles new file mode 120000 index 00000000..b741aa3d --- /dev/null +++ b/molecule/mirroring/roles @@ -0,0 +1 @@ +../../roles \ No newline at end of file diff --git a/molecule/mirroring/verify.yml b/molecule/mirroring/verify.yml new file mode 100644 index 00000000..30b8affc --- /dev/null +++ b/molecule/mirroring/verify.yml @@ -0,0 +1,71 @@ +--- +- name: Verify + hosts: all + tasks: + - name: Populate service facts + ansible.builtin.service_facts: + + - name: Populate activemq facts + middleware_automation.amq.activemq_facts: + base_url: http://localhost:8161 + auth_username: amq-broker + auth_password: amq-broker + validate_certs: false + + - name: Check if amq-broker service is started + ansible.builtin.assert: + that: + - ansible_facts.services["amq-broker.service"]["state"] == "running" + - ansible_facts.services["amq-broker.service"]["status"] == "enabled" + + - name: Read content of instance1 logs + ansible.builtin.slurp: + src: /var/log/activemq/amq-broker/artemis.log + register: slurped_log_instance1 + delegate_to: instance1 + run_once: true + no_log: true + + - name: Read content of instance2 logs + ansible.builtin.slurp: + src: /var/log/activemq/amq-broker/artemis.log + register: slurped_log_instance2 + delegate_to: instance2 + run_once: true + no_log: true + + - name: Check cluster status + run_once: true + block: + - name: Check live-only on instance1 + ansible.builtin.assert: + that: + - "'live Message Broker is starting' in slurped_log_instance1.content|b64decode or 'Primary message broker is starting' in slurped_log_instance1.content|b64decode" + - "'Connected on Server AMQP Connection DC2 on instance2:61616' in slurped_log_instance1.content|b64decode" + quiet: true + - name: Check live-only on instance2 + ansible.builtin.assert: + that: + - "'live message broker is starting' in slurped_log_instance2.content|b64decode or 'Primary message broker is starting' in slurped_log_instance2.content|b64decode" + - "'Connected on Server AMQP Connection DC1 on instance1:61616' in slurped_log_instance2.content|b64decode" + quiet: true + + - name: Check cluster status via jolokia facts (master) + ansible.builtin.assert: + that: + - ansible_facts.activemq.Active == true + - ansible_facts.activemq.Backup == false + - ansible_facts.activemq.Clustered == false + - ansible_facts.activemq.SharedStore == false + - ansible_facts.activemq.HAPolicy == "Primary Only" + when: inventory_hostname == 'instance1' + + - name: Check cluster status via jolokia facts + ansible.builtin.assert: + that: + - ansible_facts.activemq.Active == true + - ansible_facts.activemq.Backup == false + - ansible_facts.activemq.Clustered == false + - ansible_facts.activemq.SharedStore == false + - ansible_facts.activemq.HAPolicy == "Primary Only" + when: inventory_hostname == 'instance2' diff --git a/roles/activemq/templates/broker_connections.broker.xml.j2 b/roles/activemq/templates/broker_connections.broker.xml.j2 index 1db3bdb7..dce87459 100644 --- a/roles/activemq/templates/broker_connections.broker.xml.j2 +++ b/roles/activemq/templates/broker_connections.broker.xml.j2 @@ -1,5 +1,5 @@ {% for operation in broker_connection.operations | default([]) %} - <{{ operation.type }} {% for param in lookup('ansible.builtin.dict', operation.parameters, wantlist=true) | default([]) %}{{ param.key | replace('_','-') }}="{{ param.value }}" {% endfor %}/> + <{{ operation.type }} {% for param in lookup('ansible.builtin.dict', operation.parameters, wantlist=true) | default([]) %}{{ param.key | replace('_','-') }}="{{ param.value | string | lower }}" {% endfor %}/> {% endfor %} From 86c6089c57d20b1979b27bdf44fe0947893b4745 Mon Sep 17 00:00:00 2001 From: Guido Grazioli Date: Tue, 24 Sep 2024 19:38:31 +0200 Subject: [PATCH 2/2] add test to ci --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c84f46b9..d06518d8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,4 +16,4 @@ jobs: with: fqcn: 'middleware_automation/amq' molecule_tests: >- - [ "default", "static_cluster", "replication", "live_only", "federation", "amq_upgrade", "mask_passwords", "custom_xml", "uninstall" ] + [ "default", "static_cluster", "replication", "live_only", "mirroring", "federation", "amq_upgrade", "mask_passwords", "custom_xml", "uninstall" ]