import os import uuid import testinfra.utils.ansible_runner testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('parameters-optional') def test_backup(host): """ Tests if Prosody data directory is correctly backed-up. """ distribution_release = host.ansible("setup")["ansible_facts"]["ansible_distribution_release"] # Deliver a couple of messages in order to make sure the directory structure # is created. message = str(uuid.uuid1()) 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("echo '%s' | go-sendxmpp --debug " "--username jane.doe@domain2 --password janepassword --jserver domain3:5222 " "mick.doe@domain3", message) assert send.rc == 0 with host.sudo(): # Remove restore directory in order to make sure restore has worked # correctly. host.run("rm -rf /root/restore") backup_run = host.run('duply main backup') assert backup_run.rc == 0 restore_run = host.run('duply main restore /root/restore') assert restore_run.rc == 0 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