From 3f134d0f53067004314fddeb1a77b036c547e45f Mon Sep 17 00:00:00 2001 From: Sajauddin Mohammad Date: Fri, 23 Sep 2016 02:25:23 -0400 Subject: [PATCH] Changed docker_restart_policy to unless-stopped Current implementation has docker_restart_policy "always" and docker_restart_policy_retry:"10" which should be mutually exclusive. "unless-stopped" will restart the containers on any exit state but not start on daemon startup if container was put to stopped state before. Closes-Bug: #1621187 Change-Id: I4d881cd123a55625121b7a9047385e9b54e2e129 --- ansible/group_vars/all.yml | 4 ++-- ansible/library/kolla_docker.py | 15 ++++++++++----- kolla/image/build.py | 2 +- tests/test_kolla_docker.py | 21 +++++++++++---------- 4 files changed, 24 insertions(+), 18 deletions(-) diff --git a/ansible/group_vars/all.yml b/ansible/group_vars/all.yml index 52e7db6df2..c708e8cdbd 100644 --- a/ansible/group_vars/all.yml +++ b/ansible/group_vars/all.yml @@ -72,8 +72,8 @@ docker_registry: docker_namespace: "kolla" docker_registry_username: -# Valid options are [ never, on-failure, always ] -docker_restart_policy: "always" +# Valid options are [ never, on-failure, always, unless-stopped ] +docker_restart_policy: "unless-stopped" # '0' means unlimited retries docker_restart_policy_retry: "10" diff --git a/ansible/library/kolla_docker.py b/ansible/library/kolla_docker.py index 6ef4556e2b..0f2bd44a24 100644 --- a/ansible/library/kolla_docker.py +++ b/ansible/library/kolla_docker.py @@ -145,6 +145,7 @@ options: - never - on-failure - always + - unless-stopped restart_retries: description: - How many times to attempt a restart if restart_policy is set @@ -511,7 +512,9 @@ class DockerWorker(object): 'volumes_from': self.params.get('volumes_from') } - if self.params.get('restart_policy') in ['on-failure', 'always']: + if self.params.get('restart_policy') in ['on-failure', + 'always', + 'unless-stopped']: options['restart_policy'] = { 'Name': self.params.get('restart_policy'), 'MaximumRetryCount': self.params.get('restart_retries') @@ -674,10 +677,12 @@ def generate_module(): pid_mode=dict(required=False, type='str', choices=['host']), privileged=dict(required=False, type='bool', default=False), remove_on_exit=dict(required=False, type='bool', default=True), - restart_policy=dict(required=False, type='str', choices=['no', - 'never', - 'on-failure', - 'always']), + restart_policy=dict(required=False, type='str', choices=[ + 'no', + 'never', + 'on-failure', + 'always', + 'unless-stopped']), restart_retries=dict(required=False, type='int', default=10), tls_verify=dict(required=False, type='bool', default=False), tls_cert=dict(required=False, type='str'), diff --git a/kolla/image/build.py b/kolla/image/build.py index 27d06b3020..0684c3c18d 100644 --- a/kolla/image/build.py +++ b/kolla/image/build.py @@ -825,7 +825,7 @@ class KollaWorker(object): for plugin in [match.group(0) for match in (re.search('{}-plugin-.+'.format(image.name), section) for section in - self.conf.list_all_sections()) if match]: + self.conf.list_all_sections()) if match]: try: self.conf.register_opts( common_config.get_source_opts(), diff --git a/tests/test_kolla_docker.py b/tests/test_kolla_docker.py index b9e7dadca0..7e9b976500 100644 --- a/tests/test_kolla_docker.py +++ b/tests/test_kolla_docker.py @@ -73,7 +73,8 @@ class ModuleArgsTest(base.BaseTestCase): required=False, type='str', choices=['no', 'never', 'on-failure', - 'always']), + 'always', + 'unless-stopped']), restart_retries=dict(required=False, type='int', default=10), tls_verify=dict(required=False, type='bool', default=False), tls_cert=dict(required=False, type='str'), @@ -107,7 +108,7 @@ FAKE_DATA = { 'pid_mode': '', 'privileged': False, 'volumes_from': None, - 'restart_policy': 'always', + 'restart_policy': 'unless-stopped', 'restart_retries': 10}, 'labels': {'build-date': '2016-06-02', 'kolla_version': '2.0.1', @@ -516,14 +517,14 @@ class TestVolume(base.BaseTestCase): self.fake_data = copy.deepcopy(FAKE_DATA) self.volumes = { 'Volumes': - [{'Driver': u'local', - 'Labels': None, - 'Mountpoint': '/var/lib/docker/volumes/nova_compute/_data', - 'Name': 'nova_compute'}, - {'Driver': 'local', - 'Labels': None, - 'Mountpoint': '/var/lib/docker/volumes/mariadb/_data', - 'Name': 'mariadb'}] + [{'Driver': u'local', + 'Labels': None, + 'Mountpoint': '/var/lib/docker/volumes/nova_compute/_data', + 'Name': 'nova_compute'}, + {'Driver': 'local', + 'Labels': None, + 'Mountpoint': '/var/lib/docker/volumes/mariadb/_data', + 'Name': 'mariadb'}] } def test_create_volume(self):