Expose tripleo_container_manage_clean_orphans var

This exposes new var for tripleo_container_manage. Also,
removes the check to force set clean_orphans=True in
needs_delete filter, when there is one or no item in
the startup config.

There is a possibility when disabling services, there would
be one or zero container_startup_configs for a step.

Partial-Bug: #1893335
Change-Id: I9d08168015487c48d8b380a9575ba236b7fb7d0d
This commit is contained in:
Rabi Mishra 2020-08-28 14:15:06 +05:30
parent 3220e4e5e3
commit 1b93165288
9 changed files with 23 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. |
@ -188,6 +190,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
@ -209,6 +212,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):
@ -98,7 +94,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
@ -116,15 +112,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

@ -18,6 +18,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_hide_sensitive_logs: "{{ hide_sensitive_logs | default(true) }}" tripleo_container_manage_hide_sensitive_logs: "{{ hide_sensitive_logs | default(true) }}"
tripleo_container_manage_debug: "{{ ((ansible_verbosity | int) >= 2) | bool }}" tripleo_container_manage_debug: "{{ ((ansible_verbosity | int) >= 2) | bool }}"
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

@ -207,6 +207,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
@ -258,6 +259,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

@ -33,6 +33,8 @@ provisioner:
hosts: hosts:
instance: instance:
ansible_host: localhost ansible_host: localhost
ansible_connection: local
ansible_distribution: centos8
log: true log: true
env: env:
ANSIBLE_STDOUT_CALLBACK: yaml ANSIBLE_STDOUT_CALLBACK: yaml

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

@ -71,5 +71,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):