Browse Source

Merge "Expose tripleo_container_manage_clean_orphans var" into stable/train

changes/28/747728/7
Zuul 4 weeks ago
committed by Gerrit Code Review
parent
commit
73464f3c02
8 changed files with 21 additions and 18 deletions
  1. +8
    -0
      doc/source/roles/role-tripleo-container-manage.rst
  2. +1
    -14
      tripleo_ansible/ansible_plugins/filter/helpers.py
  3. +1
    -0
      tripleo_ansible/roles/tripleo-container-manage/defaults/main.yml
  4. +2
    -0
      tripleo_ansible/roles/tripleo-container-manage/molecule/default/playbook.yml
  5. +2
    -1
      tripleo_ansible/roles/tripleo-container-manage/tasks/delete_orphan.yml
  6. +2
    -0
      tripleo_ansible/roles/tripleo-container-manage/tasks/main.yml
  7. +1
    -1
      tripleo_ansible/roles/tripleo-container-manage/tasks/podman/create.yml
  8. +4
    -2
      tripleo_ansible/tests/plugins/filter/test_helpers.py

+ 8
- 0
doc/source/roles/role-tripleo-container-manage.rst View File

@@ -111,6 +111,8 @@ Roles variables
| tripleo_container_manage_config_overrides | {} | Allows to override any |
| | | container configuration |
+------------------------------------------------+-----------------------------+----------------------------+
| tripleo_container_manage_clean_orphans | true | Option to clean orphans |
+------------------------------------------------+-----------------------------+----------------------------+
| tripleo_container_manage_valid_exit_code | [] | Allow to check if a |
| | | container returned the |
| | | exit code in parameter. |
@@ -151,6 +153,7 @@ overrides the image setting in one-off.
tripleo_container_manage_config_patterns: 'haproxy.json'
tripleo_container_manage_config: "/var/lib/tripleo-config/container-startup-config/step_1"
tripleo_container_manage_config_id: "tripleo_step1"
tripleo_container_manage_clean_orphans: false
tripleo_container_manage_config_overrides:
haproxy:
image: docker.io/tripleomaster/centos-binary-haproxy:hotfix
@@ -172,6 +175,11 @@ containers by Ansible.

$ ansible-playbook haproxy.yaml --check --diff

The ``tripleo_container_manage_clean_orphans`` parameter is optional
and can be set to `false` to not clean orphaned containers for a
config_id. It can be used to manage a single container without
impacting other running containers with same config_id.

The ``tripleo_container_manage_config_overrides`` parameter is optional
and can be used to override a specific container attribute like the image
or the container user. The parameter takes a dictionary where each key is the


+ 1
- 14
tripleo_ansible/ansible_plugins/filter/helpers.py View File

@@ -19,10 +19,6 @@ import json
import re
import six

from collections import OrderedDict
from operator import itemgetter


# cmp() doesn't exist on python3
if six.PY3:
def cmp(a, b):
@@ -92,7 +88,7 @@ class FilterModule(object):
return return_dict

def needs_delete(self, container_infos, config, config_id,
clean_orphans=True, check_config=True):
clean_orphans=False, check_config=True):
"""Returns a list of containers which need to be removed.

This filter will check which containers need to be removed for these
@@ -110,15 +106,6 @@ class FilterModule(object):
to_skip = []
installed_containers = []

# If config has no item, it's probably due to a user error where
# the given pattern match no container.
# If config has one item, it's because we want to manage only one
# container.
# In both cases, we don't want to remove the others in the same
# config_id.
if len(config) <= 1:
clean_orphans = False

for c in container_infos:
c_name = c['Name']
installed_containers.append(c_name)


+ 1
- 0
tripleo_ansible/roles/tripleo-container-manage/defaults/main.yml View File

@@ -16,6 +16,7 @@


# All variables intended for modification should place placed in this file.
tripleo_container_manage_clean_orphans: true

# All variables within this role should have a prefix of "tripleo_container_manage"
tripleo_container_manage_check_puppet_config: false


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

@@ -243,6 +243,7 @@
tripleo_container_manage_config: '/tmp/container-configs'
tripleo_container_manage_debug: true
tripleo_container_manage_config_patterns: 'fedora.json'
tripleo_container_manage_clean_orphans: false
tripleo_container_manage_config_overrides:
fedora:
image: fedora:rawhide
@@ -297,6 +298,7 @@
tripleo_container_manage_config: '/tmp/container-configs'
tripleo_container_manage_debug: true
tripleo_container_manage_config_patterns: 'feduraaa.json'
tripleo_container_manage_clean_orphans: false
tasks:
- include_role:
name: tripleo-container-manage


+ 2
- 1
tripleo_ansible/roles/tripleo-container-manage/tasks/delete_orphan.yml View File

@@ -30,4 +30,5 @@
tripleo_container_cli: "{{ tripleo_container_manage_cli }}"
tripleo_containers_to_rm: >-
{{ podman_containers.containers | needs_delete(config=all_containers_hash,
config_id=tripleo_container_manage_config_id, check_config=False) }}
config_id=tripleo_container_manage_config_id, check_config=False,
clean_orphans=True) }}

+ 2
- 0
tripleo_ansible/roles/tripleo-container-manage/tasks/main.yml View File

@@ -79,5 +79,7 @@
- tripleo_container_manage_check_puppet_config|bool
- name: "Delete orphan containers from {{ tripleo_container_manage_config }}"
include_tasks: delete_orphan.yml
when:
- tripleo_container_manage_clean_orphans|bool
- name: "Create containers from {{ tripleo_container_manage_config }}"
include_tasks: create.yml

+ 1
- 1
tripleo_ansible/roles/tripleo-container-manage/tasks/podman/create.yml View File

@@ -24,7 +24,7 @@
tripleo_containers_to_rm: >-
{{ podman_containers.containers | needs_delete(config=batched_container_data|
haskey(attribute='action', reverse=True)|singledict,
config_id=tripleo_container_manage_config_id, clean_orphans=False) }}
config_id=tripleo_container_manage_config_id) }}

- name: "Async container create/run"
async: "{{ (not ansible_check_mode | bool) | ternary('600', omit) }}"


+ 4
- 2
tripleo_ansible/tests/plugins/filter/test_helpers.py View File

@@ -488,7 +488,8 @@ class TestHelperFilters(tests_base.TestCase):
expected_list = ['rabbitmq', 'haproxy', 'heat', 'test1', 'old_tripleo']
result = self.filters.needs_delete(container_infos=data,
config=config,
config_id='tripleo_step1')
config_id='tripleo_step1',
clean_orphans=True)
self.assertEqual(result, expected_list)

def test_needs_delete_no_config_check(self):
@@ -610,7 +611,8 @@ class TestHelperFilters(tests_base.TestCase):
result = self.filters.needs_delete(container_infos=data,
config=config,
config_id='tripleo_step1',
check_config=False)
check_config=False,
clean_orphans=True)
self.assertEqual(result, expected_list)

def test_needs_delete_single_config(self):


Loading…
Cancel
Save