From 798fded7b6188e035a212a9d032da4e9843e7f8c 2024-03-03 12:02:15 From: Branko Majic Date: 2024-03-03 12:02:15 Subject: [PATCH] MAR-192: Fix/improve backup tests for XMPP server: - Don't send message to self because go-sendxmpp will retrieve them, and they won't end-up the offline messages file. - Generate a random UUID in order to test for the content in the backed-up files. Makes the test more reliable. --- diff --git a/roles/xmpp_server/molecule/default/tests/test_backup.py b/roles/xmpp_server/molecule/default/tests/test_backup.py index 1b27ff1455c629e956d212ce860611b18a0335bf..26c0d091e7ad44f067c8e83ff944fa60facdea9d 100644 --- a/roles/xmpp_server/molecule/default/tests/test_backup.py +++ b/roles/xmpp_server/molecule/default/tests/test_backup.py @@ -1,4 +1,5 @@ import os +import uuid import testinfra.utils.ansible_runner @@ -14,29 +15,20 @@ def test_backup(host): distribution_release = host.ansible("setup")["ansible_facts"]["ansible_distribution_release"] - # Ugly, but functional for now. - if distribution_release == "bullseye": - # Deliver a couple of messages in order to make sure the directory structure - # is created. - send = host.run("echo 'Hello' | sendxmpp --tls-ca-path /usr/local/share/ca-certificates/testca.crt " - "-t -u jane.doe -p janepassword -j domain2:5222 jane.doe@domain2") - assert send.rc == 0 + # Deliver a couple of messages in order to make sure the directory structure + # is created. + message = str(uuid.uuid1()) - send = host.run("echo 'Hello' | sendxmpp --tls-ca-path /usr/local/share/ca-certificates/testca.crt " - "-t -u mick.doe -p mickpassword -j domain3:5222 mick.doe@domain3") + if distribution_release == "bullseye": + send = host.run("echo '%s' | sendxmpp --tls-ca-path /usr/local/share/ca-certificates/testca.crt " + "-t -u jane.doe -p janepassword -j domain2:5222 mick.doe@domain3", message) assert send.rc == 0 else: - send = host.run(f"echo 'Hello' | go-sendxmpp --debug " - f"--username jane.doe@domain2 --password janepassword --jserver domain2:5222 " - f"jane.doe@domain2") + send = host.run("echo '%s' | go-sendxmpp --debug " + "--username jane.doe@domain2 --password janepassword --jserver domain3:5222 " + "mick.doe@domain3", message) assert send.rc == 0 - send = host.run(f"echo 'Hello' | go-sendxmpp --debug " - f"--username mick.doe@domain3 --password mickpassword --jserver domain3:5222 " - f"mick.doe@domain3") - assert send.rc == 0 - - with host.sudo(): # Remove restore directory in order to make sure restore has worked @@ -49,24 +41,21 @@ def test_backup(host): restore_run = host.run('duply main restore /root/restore') assert restore_run.rc == 0 - for directory_path in ["/root/restore/var/lib/prosody/domain2", - "/root/restore/var/lib/prosody/domain2/offline", - "/root/restore/var/lib/prosody/domain3", - "/root/restore/var/lib/prosody/domain3/offline"]: - - directory = host.file(directory_path) - - assert directory.is_directory - assert directory.user == "prosody" - assert directory.group == "prosody" - assert directory.mode == 0o750 - - for file_path in ["/root/restore/var/lib/prosody/domain2/offline/jane%2edoe.list", - "/root/restore/var/lib/prosody/domain3/offline/mick%2edoe.list"]: - - f = host.file(file_path) - - assert f.is_file - assert f.user == 'prosody' - assert f.group == 'prosody' - assert f.mode == 0o640 + directory = host.file("/root/restore/var/lib/prosody/domain3") + assert directory.is_directory + assert directory.user == "prosody" + assert directory.group == "prosody" + assert directory.mode == 0o750 + + directory = host.file("/root/restore/var/lib/prosody/domain3/offline") + assert directory.is_directory + assert directory.user == "prosody" + assert directory.group == "prosody" + assert directory.mode == 0o750 + + offline_messages = host.file("/root/restore/var/lib/prosody/domain3/offline/mick%2edoe.list") + assert offline_messages.is_file + assert offline_messages.user == 'prosody' + assert offline_messages.group == 'prosody' + assert offline_messages.mode == 0o640 + assert message in offline_messages.content_string