summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorViktor Adam <rycus86@gmail.com>2018-02-21 19:55:17 +0000
committerViktor Adam <rycus86@gmail.com>2018-02-21 19:55:17 +0000
commite54e8f41993e5fd6378b15c5ab9a3d43615b8618 (patch)
treeb9c31ef26b9b0c30d839e6c03ddf6758a9071905
parentba0e5332de2fb032b5b21e8e2835244152927c0f (diff)
downloaddocker-py-e54e8f41993e5fd6378b15c5ab9a3d43615b8618.tar.gz
Shorthand method for service.force_update()
Signed-off-by: Viktor Adam <rycus86@gmail.com>
-rw-r--r--docker/models/services.py15
-rw-r--r--tests/integration/models_services_test.py41
2 files changed, 54 insertions, 2 deletions
diff --git a/docker/models/services.py b/docker/models/services.py
index 8a633df..125896b 100644
--- a/docker/models/services.py
+++ b/docker/models/services.py
@@ -69,6 +69,11 @@ class Service(Model):
spec = self.attrs['Spec']['TaskTemplate']['ContainerSpec']
kwargs['image'] = spec['Image']
+ if kwargs.get('force_update') is True:
+ task_template = self.attrs['Spec']['TaskTemplate']
+ current_value = int(task_template.get('ForceUpdate', 0))
+ kwargs['force_update'] = current_value + 1
+
create_kwargs = _get_create_service_kwargs('update', kwargs)
return self.client.api.update_service(
@@ -124,6 +129,16 @@ class Service(Model):
service_mode,
fetch_current_spec=True)
+ def force_update(self):
+ """
+ Force update the service even if no changes require it.
+
+ Returns:
+ ``True``if successful.
+ """
+
+ return self.update(force_update=True, fetch_current_spec=True)
+
class ServiceCollection(Collection):
"""Services on the Docker server."""
diff --git a/tests/integration/models_services_test.py b/tests/integration/models_services_test.py
index cb8eca2..36caa85 100644
--- a/tests/integration/models_services_test.py
+++ b/tests/integration/models_services_test.py
@@ -276,7 +276,7 @@ class ServiceTest(unittest.TestCase):
assert spec.get('Command') == ['sleep', '300']
@helpers.requires_api_version('1.25')
- def test_restart_service(self):
+ def test_force_update_service(self):
client = docker.from_env(version=TEST_API_VERSION)
service = client.services.create(
# create arguments
@@ -286,7 +286,7 @@ class ServiceTest(unittest.TestCase):
command="sleep 300"
)
initial_version = service.version
- service.update(
+ assert service.update(
# create argument
name=service.name,
# task template argument
@@ -296,3 +296,40 @@ class ServiceTest(unittest.TestCase):
)
service.reload()
assert service.version > initial_version
+
+ @helpers.requires_api_version('1.25')
+ def test_force_update_service_using_bool(self):
+ client = docker.from_env(version=TEST_API_VERSION)
+ service = client.services.create(
+ # create arguments
+ name=helpers.random_name(),
+ # ContainerSpec arguments
+ image="alpine",
+ command="sleep 300"
+ )
+ initial_version = service.version
+ assert service.update(
+ # create argument
+ name=service.name,
+ # task template argument
+ force_update=True,
+ # ContainerSpec argument
+ command="sleep 600"
+ )
+ service.reload()
+ assert service.version > initial_version
+
+ @helpers.requires_api_version('1.25')
+ def test_force_update_service_using_shorthand_method(self):
+ client = docker.from_env(version=TEST_API_VERSION)
+ service = client.services.create(
+ # create arguments
+ name=helpers.random_name(),
+ # ContainerSpec arguments
+ image="alpine",
+ command="sleep 300"
+ )
+ initial_version = service.version
+ assert service.force_update()
+ service.reload()
+ assert service.version > initial_version