Changeset - f05151d6f802
[Not reviewed]
0 8 1
Branko Majic (branko) - 6 years ago 2018-08-05 14:41:45
branko@majic.rs
MAR-132: Added support for Debian 9 (Stretch) to wsgi_website role:

- Set the shell for application system account explicitly (workaround
for Debian bug 865762 in Stretch).
- Updated Molecule tests to cover Debian 9.
- Updated Molecule test preparation playbook to account for a number
of differences between Jessie and Stretch (mainly related to mailing
functionality).
- Renamed a couple of variables in test for sending out mails to make
it clearer what is being looked up as part of regex matching.
- Updated Molecule tests where certain paths depend on what Debian
release they are ran against.
- Split-up Jessie-specific tests into separate file.
- Remove the /bin/ss utility instead of renaming it (testinfra socket
tests do not work with /bin/ss).
9 files changed with 95 insertions and 20 deletions:
0 comments (0 inline, 0 general)
docs/rolereference.rst
Show inline comments
 
@@ -1870,6 +1870,7 @@ Distribution compatibility
 
Role is compatible with the following distributions:
 

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

	
 

	
 
Examples
roles/wsgi_website/molecule/default/molecule.yml
Show inline comments
 
@@ -17,10 +17,23 @@ platforms:
 
  - name: wsgi-website-jessie64
 
    groups:
 
      - wsgi-website
 
      - parameters-mandatory
 
      - parameters-optional
 
      - jessie
 
    box: debian/contrib-jessie64
 
    memory: 512
 
    cpus: 1
 

	
 
  - name: wsgi-website-stretch64
 
    groups:
 
      - wsgi-website
 
      - parameters-mandatory
 
      - parameters-optional
 
      - stretch
 
    box: debian/contrib-stretch64
 
    memory: 512
 
    cpus: 1
 

	
 
provisioner:
 
  name: ansible
 
  config_options:
roles/wsgi_website/molecule/default/playbook.yml
Show inline comments
 
@@ -38,7 +38,8 @@
 
      https_tls_certificate: "{{ lookup('file', 'tests/data/x509/parameters-optional.local_https.cert.pem') }}"
 
      https_tls_key: "{{ lookup('file', 'tests/data/x509/parameters-optional.local_https.key.pem') }}"
 
      packages:
 
        - libmariadb-client-lgpl-dev-compat
 
        - "{% if ansible_distribution_release == 'jessie' %}libmariadb-client-lgpl-dev-compat\
 
{% elif ansible_distribution_release == 'stretch' %}libmariadbclient-dev-compat{% endif %}"
 
        - global
 
      proxy_headers:
 
        Accept-Encoding: '""'
roles/wsgi_website/molecule/default/prepare.yml
Show inline comments
 
@@ -33,11 +33,42 @@
 
        name: swaks
 
        state: present
 

	
 
    - name: Install net-tools for testing sockets
 
      apt:
 
        name: net-tools
 
        state: present
 

	
 
    - name: Install Postfix for testing mail forwarding (Exim4 not covered)
 
      apt:
 
        name: postfix
 
        state: present
 

	
 
    - name: Install procmail for consistency with mail_server and mail_forwarder roles
 
      apt:
 
        name: procmail
 
        state: present
 

	
 
    - name: Update Postfix configuration
 
      lineinfile:
 
        path: /etc/postfix/main.cf
 
        regexp: "^{{ item.key }}"
 
        line: "{{ item.value }}"
 
        state: present
 
      with_dict:
 
        myhostname: "myhostname = {{ inventory_hostname }}"
 
        mailbox_command: 'mailbox_command = procmail -a "$EXTENSION"'
 
      notify:
 
        - Restart Postfix
 

	
 
    - name: Direct all mails from the root account to vagrant (Stretch image does not do that by default)
 
      lineinfile:
 
        path: /etc/aliases
 
        regexp: "^root"
 
        line: "root: vagrant"
 
        state: present
 
      notify:
 
        - Generate aliases database
 

	
 
    - name: Set-up group for an additional user
 
      group:
 
        name: user
 
@@ -49,5 +80,17 @@
 
        group: user
 
        shell: /bin/bash
 

	
 
    - name: Rename the ss utility (see https://github.com/philpep/testinfra/pull/320)
 
      command: "mv /bin/ss /bin/ss.bak"
 
    - name: Remove the ss utility (see https://github.com/philpep/testinfra/pull/320)
 
      file:
 
        path: "/bin/ss"
 
        state: absent
 

	
 
  handlers:
 

	
 
    - name: Restart Postfix
 
      service:
 
        name: postfix
 
        state: restarted
 

	
 
    - name: Generate aliases database
 
      command: "/usr/bin/newaliases"
roles/wsgi_website/molecule/default/tests/test_default.py
Show inline comments
 
@@ -210,7 +210,7 @@ def test_mail_forwarding(host, original_destination, expected_destination_user):
 

	
 
    send = host.run('swaks --suppress-data --to ' + original_destination)
 
    assert send.rc == 0
 
    message_id = re.search('Ok: queued as (.*)', send.stdout).group(1)
 
    original_queue_id = re.search('Ok: queued as (.*)', send.stdout).group(1)
 

	
 
    # Sleep for a couple of seconds so the mail can get delivered.
 
    time.sleep(5)
 
@@ -219,11 +219,11 @@ def test_mail_forwarding(host, original_destination, expected_destination_user):
 
        mail_log = host.file('/var/log/mail.log')
 

	
 
        # First extract message ID of forwarded mail.
 
        pattern = "%s: to=<%s>.*status=sent \(forwarded as ([^)]*)\)" % (message_id, original_destination)
 
        message_id = re.search(pattern, mail_log.content).group(1)
 
        pattern = "%s: to=<%s>.*status=sent \(forwarded as ([^)]*)\)" % (original_queue_id, original_destination)
 
        forward_queue_id = re.search(pattern, mail_log.content).group(1)
 

	
 
        # Now try to determine where the forward ended-up at.
 
        pattern = "%s: to=<%s@%s>, orig_to=<%s>.*status=sent" % (message_id, expected_destination_user, hostname, original_destination)
 
        pattern = "%s: to=<%s@%s>, orig_to=<%s>.*status=sent" % (forward_queue_id, expected_destination_user, hostname, original_destination)
 
        assert re.search(pattern, mail_log.content) is not None
 

	
 

	
roles/wsgi_website/molecule/default/tests/test_parameters_mandatory.py
Show inline comments
 
@@ -4,7 +4,7 @@ import testinfra.utils.ansible_runner
 

	
 

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

	
 

	
 
def test_https_enforcement(host):
roles/wsgi_website/molecule/default/tests/test_parameters_optional.py
Show inline comments
 
@@ -4,7 +4,7 @@ import testinfra.utils.ansible_runner
 

	
 

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

	
 

	
 
def test_installed_packages(host):
 
@@ -12,19 +12,15 @@ def test_installed_packages(host):
 
    Tests if additional packages are installed.
 
    """
 

	
 
    assert host.package('libmariadb-client-lgpl-dev-compat').is_installed
 
    assert host.package('global').is_installed
 
    ansible_facts = host.ansible("setup")["ansible_facts"]
 

	
 
    if ansible_facts['ansible_distribution_release'] == 'jessie':
 
        mariadb_compat_package = 'libmariadb-client-lgpl-dev-compat'
 
    elif ansible_facts['ansible_distribution_release'] == 'stretch':
 
        mariadb_compat_package = 'libmariadbclient-dev-compat'
 

	
 
def test_mariadb_compat_symlink(host):
 
    """
 
    Tests if compatibility symlink is set-up for mysql_config binary if
 
    libmariadb-client-lgpl-dev-compat is installed.
 
    """
 

	
 
    link = host.file('/usr/bin/mysql_config')
 
    assert link.is_symlink
 
    assert link.linked_to == "/usr/bin/mariadb_config"
 
    assert host.package(mariadb_compat_package).is_installed
 
    assert host.package('global').is_installed
 

	
 

	
 
def test_https_enforcement(host):
roles/wsgi_website/molecule/default/tests/test_parameters_optional_jessie].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(['jessie'])
 

	
 

	
 
def test_mariadb_compat_symlink(host):
 
    """
 
    Tests if compatibility symlink is set-up for mysql_config binary if
 
    libmariadb-client-lgpl-dev-compat is installed.
 
    """
 

	
 
    link = host.file('/usr/bin/mysql_config')
 
    assert link.is_symlink
 
    assert link.linked_to == "/usr/bin/mariadb_config"
roles/wsgi_website/tasks/main.yml
Show inline comments
 
@@ -50,6 +50,10 @@
 
    createhome: false
 
    state: present
 
    home: "{{ home }}"
 
    # This is a workaround for a rather stupid bug that Debian seems
 
    # uninterested to backport -
 
    # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=865762
 
    shell: /bin/sh
 

	
 
- name: Add nginx user to website group
 
  user:
0 comments (0 inline, 0 general)