Browse Source

[train-only] container_systemd: clean and test requires for systemd

Clean some old functions and test the healthcheck dependencies on their
units.

This adds a test case in molecule where we:

- Stop a service and check its healthcheck is also stopped by systemd.
- Start a service and check its healthcheck is also started by systemd.

Change-Id: I5e759d1fed4fe1f7bc2b542d0981e5ce9531d463
changes/34/742734/17
Emilien Macchi 2 weeks ago
parent
commit
b761544043
2 changed files with 57 additions and 23 deletions
  1. +11
    -23
      tripleo_ansible/ansible_plugins/action/container_systemd.py
  2. +46
    -0
      tripleo_ansible/roles/tripleo-container-manage/molecule/default/playbook.yml

+ 11
- 23
tripleo_ansible/ansible_plugins/action/container_systemd.py View File

@@ -266,27 +266,25 @@ class ActionModule(ActionBase):
if results.get('changed', False):
self.changed = True

def _add_systemd_requires(self, services, task_vars):
def _add_systemd_requires(self, services):
"""Add systemd dependencies for healthchecks.

:param services: List for service names.
:param task_vars: Dictionary of Ansible task variables.
"""
for name in services:
service = 'tripleo_{}'.format(name)
if self.debug:
DISPLAY.display('Adding systemd dependency for '
'{}'.format(service))

command = ('systemctl add-requires {}.service '.format(service)
+ '{}_healthcheck.timer'.format(service))
results = self._execute_module(
module_name='command',
module_args=dict(cmd=command),
task_vars=task_vars
if self.debug:
DISPLAY.display('Adding systemd dependency for '
'{} with command: '
'{}'.format(service, command))
results = self._low_level_execute_command(
command,
executable='/bin/bash'
)
if results.get('changed', False):
self.changed = True
if results.get('rc', 0) != 0:
raise AnsibleActionFail('Failed to run {}'.format(command))

@tenacity.retry(
reraise=True,
@@ -347,15 +345,6 @@ class ActionModule(ActionBase):
self._manage_service(name=name, state='started',
extension=extension, task_vars=task_vars)

def _add_requires(self, services, task_vars):
"""Add systemd requires for healthchecks.

:param services: List of services to manage.
"""
for s in services:
# TODO
pass

def run(self, tmp=None, task_vars=None):
self.changed = False
self.restarted = []
@@ -414,8 +403,7 @@ class ActionModule(ActionBase):
self._ensure_started(service_names=h_already_created,
extension='timer',
task_vars=task_vars)
requires_healthchecks = changed_healthchecks + h_already_created
self._add_systemd_requires(requires_healthchecks, task_vars)
self._add_systemd_requires(all_healthchecks)

result['changed'] = self.changed
result['restarted'] = self.restarted


+ 46
- 0
tripleo_ansible/roles/tripleo-container-manage/molecule/default/playbook.yml View File

@@ -107,6 +107,52 @@
fail_msg: 'fedora_three container has wrong image'
success_msg: 'fedora_three container has the right image'

- name: Test systemd healthcheck dependency on service
become: true
hosts: all
gather_facts: false
tasks:
- name: Stop systemd service for tripleo_fedora
systemd:
name: tripleo_fedora.service
state: stopped
enabled: true
- name: Check if tripleo_fedora_healthcheck timer is active
command: systemctl is-active --quiet tripleo_fedora_healthcheck.timer
register: tripleo_fedora_healthcheck_active_result
failed_when: false
when:
- not ansible_check_mode|bool
- name: Assert that tripleo_fedora_healthcheck timer service is not active
assert:
that:
- tripleo_fedora_healthcheck_active_result.rc == 3
fail_msg: 'tripleo_fedora systemd service is active'
success_msg: 'tripleo_fedora systemd service is not active'
when:
- not ansible_check_mode|bool
- name: Start systemd service for tripleo_fedora
systemd:
name: tripleo_fedora.service
state: started
enabled: true
- name: Check if tripleo_fedora_healthcheck timer is active
command: systemctl is-active --quiet tripleo_fedora_healthcheck.timer
register: tripleo_fedora_healthcheck_active_result
until: tripleo_fedora_healthcheck_active_result.rc == 0
retries: 5
delay: 5
when:
- not ansible_check_mode|bool
- name: Assert that tripleo_fedora_healthcheck timer service is active
assert:
that:
- tripleo_fedora_healthcheck_active_result.rc == 0
fail_msg: 'tripleo_fedora systemd service is not active'
success_msg: 'tripleo_fedora systemd service is active'
when:
- not ansible_check_mode|bool

- name: Test idempotency on fedora container
become: true
hosts: all


Loading…
Cancel
Save