Changeset - 30d5b3fa5b93
[Not reviewed]
0 4 2
Branko Majic (branko) - 6 years ago 2018-08-18 13:51:47
branko@majic.rs
MAR-132: Added support for Debian 9 (Stretch) to database_server role:

- Updated Molecule test configuration to include Debian 9 Stretch in
test matrix.
- Updated tests related to UTF-8 configuration (differences between
Debian 8 and 9).
- Deploy UTF-8 configuration in alternate locations depending on what
distro is being used.
- Force set-up of root password on Debian Stretch (default is to use
the unix_socket authentication).
6 files changed with 101 insertions and 17 deletions:
0 comments (0 inline, 0 general)
docs/rolereference.rst
Show inline comments
 
@@ -1955,6 +1955,7 @@ Distribution compatibility
 
Role is compatible with the following distributions:
 

	
 
- Debian 8 (Jessie)
 
- Debian 9 (Stretch)
 

	
 

	
 
Examples
roles/database_server/molecule/default/molecule.yml
Show inline comments
 
@@ -21,6 +21,13 @@ platforms:
 
    memory: 512
 
    cpus: 1
 

	
 
  - name: parameters-mandatory-stretch64
 
    groups:
 
      - parameters-mandatory
 
    box: debian/contrib-stretch64
 
    memory: 512
 
    cpus: 1
 

	
 
provisioner:
 
  name: ansible
 
  config_options:
roles/database_server/molecule/default/tests/test_default.py
Show inline comments
 
@@ -74,20 +74,6 @@ def test_root_my_cnf_login(host):
 
        assert "performance_schema" in login.stdout
 

	
 

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

	
 
    config = host.file('/etc/mysql/conf.d/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.
roles/database_server/molecule/default/tests/test_default_jessie64.py
Show inline comments
 
new file 100644
 
import os
 

	
 
import testinfra.utils.ansible_runner
 

	
 

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

	
 

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

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

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

	
 

	
 
def test_stretch_utf8_configuration_file_absent(host):
 
    """
 
    Tests if the Stretch configuration file is absent.
 
    """
 

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

	
 
    assert not config.exists
roles/database_server/molecule/default/tests/test_default_stretch64.py
Show inline comments
 
new file 100644
 
import os
 

	
 
import testinfra.utils.ansible_runner
 

	
 

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

	
 

	
 
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_jessie_utf8_configuration_file_absent(host):
 
    """
 
    Tests if the Jessie configuration file is absent.
 
    """
 

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

	
 
    assert not config.exists
roles/database_server/tasks/main.yml
Show inline comments
 
@@ -33,20 +33,48 @@
 
    group: root
 
    mode: 0400
 

	
 
- name: Set UTF-8 encoding as default for MariaDB
 
- name: Check if root user authentication is based on use of unix_socket module (Stretch default)
 
  command: mysql --skip-column-names -B -e "select 1 from mysql.user where user='root' and plugin='unix_socket';"
 
  when: "ansible_distribution_release == 'stretch'"
 
  register: "root_using_unix_socket_authentication"
 
  changed_when: false
 

	
 
- name: Disable use of unix socket login on Debian Stretch (temporary workaround)
 
  command: "mysql -B -e \"update mysql.user set plugin='' where user='root' and plugin='unix_socket'; flush privileges;\""
 
  when: "ansible_distribution_release == 'stretch' and root_using_unix_socket_authentication.stdout != ''"
 

	
 
- name: Remove UTF-8 encoding configuration file from the old location on Debian Stretch
 
  file:
 
    path: "/etc/mysql/conf.d/utf8.cnf"
 
    state: absent
 
  when: "ansible_distribution_release == 'stretch'"
 
  register: mariadb_utf8_configuration_stretch
 

	
 
- name: Set UTF-8 encoding as default for MariaDB (on Jessie)
 
  copy:
 
    src: "utf8.cnf"
 
    dest: "/etc/mysql/conf.d/utf8.cnf"
 
    owner: root
 
    group: root
 
    mode: 0644
 
  register: mariadb_utf8_configuration
 
  when: "ansible_distribution_release == 'jessie'"
 
  register: mariadb_utf8_configuration_jessie
 

	
 
- name: Set UTF-8 encoding as default for MariaDB (on Stretch)
 
  copy:
 
    src: "utf8.cnf"
 
    dest: "/etc/mysql/mariadb.conf.d/90-utf8.cnf"
 
    owner: root
 
    group: root
 
    mode: 0644
 
  when: "ansible_distribution_release == 'stretch'"
 
  register: mariadb_utf8_configuration_stretch
 

	
 
- name: Restart MariaDB in order to use UTF-8 as default character set
 
  service:
 
    name: mysql
 
    state: restarted
 
  when: mariadb_utf8_configuration.changed
 
  when: mariadb_utf8_configuration_jessie.changed or mariadb_utf8_configuration_stretch.changed
 
  tags:
 
    # [ANSIBLE0016] Tasks that run when changed should likely be handlers
 
    #   UTF-8 configuration must be applied immediatelly in order to ensure that
0 comments (0 inline, 0 general)