Changeset - 798fded7b618
[Not reviewed]
0 1 0
Branko Majic (branko) - 2 months ago 2024-03-03 12:02:15
branko@majic.rs
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.
1 file changed with 28 insertions and 39 deletions:
0 comments (0 inline, 0 general)
roles/xmpp_server/molecule/default/tests/test_backup.py
Show inline comments
 
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
0 comments (0 inline, 0 general)