Files @ 2c24e973d44a
Branch filter:

Location: majic-ansible-roles/roles/database_server/molecule/default/tests/test_default.py

branko
MAR-192: Added support for Debian 12 Bookworm to backup_server role:

- Use test parametrisation instead of looping over a list when testing
correct key usage.
- Replace deprecated key algorithm (in Debian 12 Bookworm) for test
purposes (it just needs to be one of the RSA variants).
import os

import testinfra.utils.ansible_runner


testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
    os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('parameters-mandatory')


def test_installed_packages(host):
    """
    Tests if the correct packages have been installed.
    """

    assert host.package('mariadb-client').is_installed
    assert host.package('mariadb-server').is_installed
    assert host.package('python3-pymysql').is_installed


def test_service(host):
    """
    Tests if the database server service is enabled on boot and running.
    """

    service = host.service('mysql')

    assert service.is_enabled
    assert service.is_running


def test_utf8_configuration_file(host):
    """
    Tests if UTF-8 database server configuration file has been deployed
    correctly.
    """

    config = host.file('/etc/mysql/mariadb.conf.d/90-utf8.cnf')

    assert config.is_file
    assert config.user == 'root'
    assert config.group == 'root'
    assert config.mode == 0o644


def test_utf8_configuration(host):
    """
    Tests if UTF-8 configuration has been applied correctly to server.
    """

    with host.sudo():
        assert host.run("mysql -uroot -BNe 'drop database if exists test'").rc == 0
        assert host.run("mysql -uroot -BNe 'create database test'").rc == 0

        check_server = host.run("mysql -uroot test -BNe 'select @@character_set_server; select @@collation_server'")

        assert check_server.rc == 0
        assert check_server.stdout == "utf8\nutf8_general_ci\n"

        check_database = host.run("mysql -uroot test -BNe 'select @@character_set_database; select @@collation_database'")

        assert check_database.rc == 0
        assert check_database.stdout == "utf8\nutf8_general_ci\n"

        check_database = host.run("mysql -uroot -BNe 'select @@character_set_connection; select @@collation_connection'")

        assert check_database.rc == 0
        assert check_database.stdout == "utf8\nutf8_general_ci\n"