Files @ 772c56cb8d3e
Branch filter:

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

branko
MAR-239: Dropped support for Debian 11 Bullseye from the ldap_client role.
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.
    """

    expected_character_set_and_collation = "utf8mb3\nutf8mb3_general_ci\n"

    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 == expected_character_set_and_collation

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

        assert check_database.rc == 0
        assert check_database.stdout == expected_character_set_and_collation

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

        assert check_database.rc == 0
        assert check_database.stdout == expected_character_set_and_collation