Merge "Expose tripleo_container_manage_clean_orphans var" into stable/train

This commit is contained in:
Zuul 2020-09-01 22:26:41 +00:00 committed by Gerrit Code Review
commit 73464f3c02
8 changed files with 21 additions and 18 deletions

View File

@ -111,6 +111,8 @@ Roles variables
| tripleo_container_manage_config_overrides | {} | Allows to override any | | tripleo_container_manage_config_overrides | {} | Allows to override any |
| | | container configuration | | | | container configuration |
+------------------------------------------------+-----------------------------+----------------------------+ +------------------------------------------------+-----------------------------+----------------------------+
| tripleo_container_manage_clean_orphans | true | Option to clean orphans |
+------------------------------------------------+-----------------------------+----------------------------+
| tripleo_container_manage_valid_exit_code | [] | Allow to check if a | | tripleo_container_manage_valid_exit_code | [] | Allow to check if a |
| | | container returned the | | | | container returned the |
| | | exit code in parameter. | | | | 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_patterns: 'haproxy.json'
tripleo_container_manage_config: "/var/lib/tripleo-config/container-startup-config/step_1" tripleo_container_manage_config: "/var/lib/tripleo-config/container-startup-config/step_1"
tripleo_container_manage_config_id: "tripleo_step1" tripleo_container_manage_config_id: "tripleo_step1"
tripleo_container_manage_clean_orphans: false
tripleo_container_manage_config_overrides: tripleo_container_manage_config_overrides:
haproxy: haproxy:
image: docker.io/tripleomaster/centos-binary-haproxy:hotfix image: docker.io/tripleomaster/centos-binary-haproxy:hotfix
@ -172,6 +175,11 @@ containers by Ansible.
$ ansible-playbook haproxy.yaml --check --diff $ 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 The ``tripleo_container_manage_config_overrides`` parameter is optional
and can be used to override a specific container attribute like the image 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 or the container user. The parameter takes a dictionary where each key is the

View File

@ -19,10 +19,6 @@ import json
import re import re
import six import six
from collections import OrderedDict
from operator import itemgetter
# cmp() doesn't exist on python3 # cmp() doesn't exist on python3
if six.PY3: if six.PY3:
def cmp(a, b): def cmp(a, b):
@ -92,7 +88,7 @@ class FilterModule(object):
return return_dict return return_dict
def needs_delete(self, container_infos, config, config_id, 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. """Returns a list of containers which need to be removed.
This filter will check which containers need to be removed for these This filter will check which containers need to be removed for these
@ -110,15 +106,6 @@ class FilterModule(object):
to_skip = [] to_skip = []
installed_containers = [] 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: for c in container_infos:
c_name = c['Name'] c_name = c['Name']
installed_containers.append(c_name) installed_containers.append(c_name)

View File

@ -16,6 +16,7 @@
# All variables intended for modification should place placed in this file. # 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" # All variables within this role should have a prefix of "tripleo_container_manage"
tripleo_container_manage_check_puppet_config: false tripleo_container_manage_check_puppet_config: false

View File

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

View File

@ -30,4 +30,5 @@
tripleo_container_cli: "{{ tripleo_container_manage_cli }}" tripleo_container_cli: "{{ tripleo_container_manage_cli }}"
tripleo_containers_to_rm: >- tripleo_containers_to_rm: >-
{{ podman_containers.containers | needs_delete(config=all_containers_hash, {{ 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) }}

View File

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

View File

@ -24,7 +24,7 @@
tripleo_containers_to_rm: >- tripleo_containers_to_rm: >-
{{ podman_containers.containers | needs_delete(config=batched_container_data| {{ podman_containers.containers | needs_delete(config=batched_container_data|
haskey(attribute='action', reverse=True)|singledict, 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" - name: "Async container create/run"
async: "{{ (not ansible_check_mode | bool) | ternary('600', omit) }}" async: "{{ (not ansible_check_mode | bool) | ternary('600', omit) }}"

View File

@ -488,7 +488,8 @@ class TestHelperFilters(tests_base.TestCase):
expected_list = ['rabbitmq', 'haproxy', 'heat', 'test1', 'old_tripleo'] expected_list = ['rabbitmq', 'haproxy', 'heat', 'test1', 'old_tripleo']
result = self.filters.needs_delete(container_infos=data, result = self.filters.needs_delete(container_infos=data,
config=config, config=config,
config_id='tripleo_step1') config_id='tripleo_step1',
clean_orphans=True)
self.assertEqual(result, expected_list) self.assertEqual(result, expected_list)
def test_needs_delete_no_config_check(self): 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, result = self.filters.needs_delete(container_infos=data,
config=config, config=config,
config_id='tripleo_step1', config_id='tripleo_step1',
check_config=False) check_config=False,
clean_orphans=True)
self.assertEqual(result, expected_list) self.assertEqual(result, expected_list)
def test_needs_delete_single_config(self): def test_needs_delete_single_config(self):