From 139abd0849ba0d756db09cbfc0f6c77621743ba4 Mon Sep 17 00:00:00 2001 From: Hannes Ljungberg Date: Tue, 5 Mar 2019 17:07:27 +0100 Subject: [PATCH] docker_swarm_service: Add option groups (#53213) * Add logging option * Add limits option * Add reservations option * Add restart_config option * Add update_config option * Add placement option and remove placement_preferences * Yaml indentation * Use correct PR number for change log * Handle grouper fallbacks better * Add removed_in_version to argument spec * Fix broken suboption usage check * Reduce duplicate deprecated option tests * Clearer deprecation documentation * Compare bytes with MiB * Use correct test service suffix --- ...m_service-placement-preferences-option.yml | 2 - ...13-docker_swarm_service-option_groups.yaml | 14 + .../cloud/docker/docker_swarm_service.py | 552 +++++++++-- .../tasks/tests/logging.yml | 148 +++ .../tasks/tests/options.yml | 884 +----------------- .../tasks/tests/placement.yml | 152 +++ .../tasks/tests/resources.yml | 214 +++++ .../tasks/tests/restart_config.yml | 217 +++++ .../tasks/tests/update_config.yml | 327 +++++++ 9 files changed, 1592 insertions(+), 918 deletions(-) delete mode 100644 changelogs/fragments/51082-docker_swarm_service-placement-preferences-option.yml create mode 100644 changelogs/fragments/53213-docker_swarm_service-option_groups.yaml create mode 100644 test/integration/targets/docker_swarm_service/tasks/tests/logging.yml create mode 100644 test/integration/targets/docker_swarm_service/tasks/tests/placement.yml create mode 100644 test/integration/targets/docker_swarm_service/tasks/tests/resources.yml create mode 100644 test/integration/targets/docker_swarm_service/tasks/tests/restart_config.yml create mode 100644 test/integration/targets/docker_swarm_service/tasks/tests/update_config.yml diff --git a/changelogs/fragments/51082-docker_swarm_service-placement-preferences-option.yml b/changelogs/fragments/51082-docker_swarm_service-placement-preferences-option.yml deleted file mode 100644 index 5dc7dc32df9..00000000000 --- a/changelogs/fragments/51082-docker_swarm_service-placement-preferences-option.yml +++ /dev/null @@ -1,2 +0,0 @@ -minor_changes: - - "docker_swarm_service - Added support for ``placement_preferences`` parameter." diff --git a/changelogs/fragments/53213-docker_swarm_service-option_groups.yaml b/changelogs/fragments/53213-docker_swarm_service-option_groups.yaml new file mode 100644 index 00000000000..2ae79e894b7 --- /dev/null +++ b/changelogs/fragments/53213-docker_swarm_service-option_groups.yaml @@ -0,0 +1,14 @@ +minor_changes: + - "docker_swarm_service - Add option ``logging`` as a grouper for logging options." + - "docker_swarm_service - Add option ``placement`` as a grouper for placement options." + - "docker_swarm_service - Add option ``limits`` as a grouper for resource limit options." + - "docker_swarm_service - Add option ``reservations`` as a grouper for resource reservation options." + - "docker_swarm_service - Add option ``restart_config`` as a grouper for restart options." + - "docker_swarm_service - Add option ``update_config`` as a grouper for update options." +deprecated_features: + - "docker_swarm_service - Deprecate ``constraints`` in favour of ``placement``." + - "docker_swarm_service - Deprecate ``log_driver`` and ``log_driver_options`` in favour of ``logging``." + - "docker_swarm_service - Deprecate ``limit_cpu`` and ``limit_memory`` in favour of ``limits``." + - "docker_swarm_service - Deprecate ``reserve_cpu`` and ``reserve_memory`` in favour of ``reservations``." + - "docker_swarm_service - Deprecate ``restart_policy``, ``restart_policy_attempts``, ``restart_policy_delay`` and ``restart_policy_window`` in favour of ``restart_config``." + - "docker_swarm_service - Deprecate ``update_delay``, ``update_parallelism``, ``update_failure_action``, ``update_monitor``, ``update_max_failure_ratio`` and ``update_order`` in favour of ``update_config``." diff --git a/lib/ansible/modules/cloud/docker/docker_swarm_service.py b/lib/ansible/modules/cloud/docker/docker_swarm_service.py index c1e61cd5282..1b1336b274a 100644 --- a/lib/ansible/modules/cloud/docker/docker_swarm_service.py +++ b/lib/ansible/modules/cloud/docker/docker_swarm_service.py @@ -60,18 +60,29 @@ options: - Corresponds to the C(COMMAND) parameter of C(docker service create). type: raw version_added: 2.8 + placement: + description: + - Configures service placement preferences and constraints. + suboptions: + constraints: + description: + - List of the service constraints. + - Corresponds to the C(--constraint) option of C(docker service create). + type: list + preferences: + description: + - List of the placement preferences as key value pairs. + - Corresponds to the C(--placement-pref) option of C(docker service create). + - Requires API version >= 1.27. + type: list + type: dict + version_added: "2.8" constraints: description: - List of the service constraints. - Corresponds to the C(--constraint) option of C(docker service create). + - Deprecated in 2.8, will be removed in 2.12. Use parameter C(placement.constraints) instead. type: list - placement_preferences: - description: - - List of the placement preferences as key value pairs. - - Corresponds to the C(--placement-pref) option of C(docker service create). - - Requires API version >= 1.27. - type: list - version_added: 2.8 healthcheck: description: - Configure a check that is run to determine whether or not containers for this service are "healthy". @@ -184,25 +195,85 @@ options: - If variable also present in I(env), then I(env) value will override. type: list version_added: "2.8" + logging: + description: + - "Logging configuration for the service." + suboptions: + driver: + description: + - Configure the logging driver for a service. + - Corresponds to the C(--log-driver) option of C(docker service create). + type: str + options: + description: + - Options for service logging driver. + - Corresponds to the C(--log-opt) option of C(docker service create). + type: dict + type: dict + version_added: "2.8" log_driver: description: - Configure the logging driver for a service. - Corresponds to the C(--log-driver) option of C(docker service create). + - Deprecated in 2.8, will be removed in 2.12. Use parameter C(logging.driver) instead. type: str log_driver_options: description: - Options for service logging driver. - Corresponds to the C(--log-opt) option of C(docker service create). + - Deprecated in 2.8, will be removed in 2.12. Use parameter C(logging.options) instead. + type: dict + reservations: + description: + - Configures service resource reservations. + suboptions: + cpus: + description: + - Service CPU reservation. C(0) equals no reservation. + - Corresponds to the C(--reserve-cpu) option of C(docker service create). + type: float + memory: + description: + - "Service memory reservation (format: C([])). Number is a positive integer. + Unit can be C(B) (byte), C(K) (kibibyte, 1024B), C(M) (mebibyte), C(G) (gibibyte), + C(T) (tebibyte), or C(P) (pebibyte)." + - C(0) equals no reservation. + - Omitting the unit defaults to bytes. + - Corresponds to the C(--reserve-memory) option of C(docker service create). + type: str + type: dict + version_added: "2.8" + limits: + description: + - Configures service resource limits. + suboptions: + cpus: + description: + - Service CPU limit. C(0) equals no limit. + - Corresponds to the C(--limit-cpu) option of C(docker service create). + type: float + memory: + description: + - "Service memory reservation (format: C([])). Number is a positive integer. + Unit can be C(B) (byte), C(K) (kibibyte, 1024B), C(M) (mebibyte), C(G) (gibibyte), + C(T) (tebibyte), or C(P) (pebibyte)." + - C(0) equals no reservation. + - Omitting the unit defaults to bytes. + - Corresponds to the C(--reserve-memory) option of C(docker service create). + type: str type: dict + version_added: "2.8" limit_cpu: description: - Service CPU limit. C(0) equals no limit. - Corresponds to the C(--limit-cpu) option of C(docker service create). + - Deprecated in 2.8, will be removed in 2.12. Use parameter C(limits.cpus) instead. type: float reserve_cpu: description: - Service CPU reservation. C(0) equals no reservation. - Corresponds to the C(--reserve-cpu) option of C(docker service create). + - Deprecated in 2.8, will be removed in 2.12. Use parameter C(reservations.cpus) instead. type: float limit_memory: description: @@ -212,6 +283,7 @@ options: - C(0) equals no limit. - Omitting the unit defaults to bytes. - Corresponds to the C(--limit-memory) option of C(docker service create). + - Deprecated in 2.8, will be removed in 2.12. Use parameter C(limits.memory) instead. type: str reserve_memory: description: @@ -221,6 +293,7 @@ options: - C(0) equals no reservation. - Omitting the unit defaults to bytes. - Corresponds to the C(--reserve-memory) option of C(docker service create). + - Deprecated in 2.8, will be removed in 2.12. Use parameter C(reservations.memory) instead. type: str mode: description: @@ -340,10 +413,10 @@ options: type: list stop_grace_period: description: - - Time to wait before force killing a container. - - "Accepts a duration as a string in a format that look like: - C(5h34m56s), C(1m30s) etc. The supported units are C(us), C(ms), C(s), C(m) and C(h)." - - Corresponds to the C(--stop-grace-period) option of C(docker service create). + - Time to wait before force killing a container. + - "Accepts a duration as a string in a format that look like: + C(5h34m56s), C(1m30s) etc. The supported units are C(us), C(ms), C(s), C(m) and C(h)." + - Corresponds to the C(--stop-grace-period) option of C(docker service create). type: str version_added: "2.8" stop_signal: @@ -394,10 +467,45 @@ options: - Corresponds to the C(--replicas) option of C(docker service create). type: int default: -1 + restart_config: + description: + - Configures if and how to restart containers when they exit. + suboptions: + condition: + description: + - Restart condition of the service. + - Corresponds to the C(--restart-condition) option of C(docker service create). + type: str + choices: + - none + - on-failure + - any + delay: + description: + - Delay between restarts. + - "Accepts a a string in a format that look like: + C(5h34m56s), C(1m30s) etc. The supported units are C(us), C(ms), C(s), C(m) and C(h)." + - Corresponds to the C(--restart-delay) option of C(docker service create). + type: str + max_attempts: + description: + - Maximum number of service restarts. + - Corresponds to the C(--restart-condition) option of C(docker service create). + type: int + window: + description: + - Restart policy evaluation window. + - "Accepts a string in a format that look like: + C(5h34m56s), C(1m30s) etc. The supported units are C(us), C(ms), C(s), C(m) and C(h)." + - Corresponds to the C(--restart-window) option of C(docker service create). + type: str + type: dict + version_added: "2.8" restart_policy: description: - Restart condition of the service. - Corresponds to the C(--restart-condition) option of C(docker service create). + - Deprecated in 2.8, will be removed in 2.12. Use parameter C(restart_config.condition) instead. type: str choices: - none @@ -407,6 +515,7 @@ options: description: - Maximum number of service restarts. - Corresponds to the C(--restart-condition) option of C(docker service create). + - Deprecated in 2.8, will be removed in 2.12. Use parameter C(restart_config.max_attempts) instead. type: int restart_policy_delay: description: @@ -414,6 +523,7 @@ options: - "Accepts a duration as an integer in nanoseconds or as a string in a format that look like: C(5h34m56s), C(1m30s) etc. The supported units are C(us), C(ms), C(s), C(m) and C(h)." - Corresponds to the C(--restart-delay) option of C(docker service create). + - Deprecated in 2.8, will be removed in 2.12. Use parameter C(restart_config.delay) instead. type: raw restart_policy_window: description: @@ -421,7 +531,57 @@ options: - "Accepts a duration as an integer in nanoseconds or as a string in a format that look like: C(5h34m56s), C(1m30s) etc. The supported units are C(us), C(ms), C(s), C(m) and C(h)." - Corresponds to the C(--restart-window) option of C(docker service create). + - Deprecated in 2.8, will be removed in 2.12. Use parameter C(restart_config.window) instead. type: raw + update_config: + description: + - Configures how the service should be updated. Useful for configuring rolling updates. + suboptions: + parallelism: + description: + - Rolling update parallelism. + - Corresponds to the C(--update-parallelism) option of C(docker service create). + type: int + delay: + description: + - Rolling update delay. + - "Accepts a string in a format that look like: + C(5h34m56s), C(1m30s) etc. The supported units are C(us), C(ms), C(s), C(m) and C(h)." + - Corresponds to the C(--update-delay) option of C(docker service create). + type: str + failure_action: + description: + - Action to take in case of container failure. + - Corresponds to the C(--update-failure-action) option of C(docker service create). + type: str + choices: + - continue + - pause + monitor: + description: + - Time to monitor updated tasks for failures. + - "Accepts a string in a format that look like: + C(5h34m56s), C(1m30s) etc. The supported units are C(us), C(ms), C(s), C(m) and C(h)." + - Corresponds to the C(--update-monitor) option of C(docker service create). + - Requires API version >= 1.25. + type: str + max_failure_ratio: + description: + - Fraction of tasks that may fail during an update before the failure action is invoked. + - Corresponds to the C(--update-max-failure-ratio) option of C(docker service create). + - Requires API version >= 1.25. + type: float + order: + description: + - Specifies the order of operations when rolling out an updated task. + - Corresponds to the C(--update-order) option of C(docker service create). + - Requires API version >= 1.29. + type: str + choices: + - stop-first + - start-first + type: dict + version_added: "2.8" update_delay: description: - Rolling update delay. @@ -429,17 +589,20 @@ options: C(5h34m56s), C(1m30s) etc. The supported units are C(us), C(ms), C(s), C(m) and C(h)." - Corresponds to the C(--update-delay) option of C(docker service create). - Before Ansible 2.8, the default value for this option was C(10). + - Deprecated in 2.8, will be removed in 2.12. Use parameter C(update_config.delay) instead. type: raw update_parallelism: description: - Rolling update parallelism. - Corresponds to the C(--update-parallelism) option of C(docker service create). - Before Ansible 2.8, the default value for this option was C(1). + - Deprecated in 2.8, will be removed in 2.12. Use parameter C(update_config.parallelism) instead. type: int update_failure_action: description: - Action to take in case of container failure. - Corresponds to the C(--update-failure-action) option of C(docker service create). + - Deprecated in 2.8, will be removed in 2.12. Use parameter C(update_config.failure_action) instead. type: str choices: - continue @@ -451,22 +614,25 @@ options: C(5h34m56s), C(1m30s) etc. The supported units are C(us), C(ms), C(s), C(m) and C(h)." - Corresponds to the C(--update-monitor) option of C(docker service create). - Requires API version >= 1.25. + - Deprecated in 2.8, will be removed in 2.12. Use parameter C(update_config.monitor) instead. type: raw update_max_failure_ratio: description: - Fraction of tasks that may fail during an update before the failure action is invoked. - Corresponds to the C(--update-max-failure-ratio) option of C(docker service create). - Requires API version >= 1.25. + - Deprecated in 2.8, will be removed in 2.12. Use parameter C(update_config.max_failure_ratio) instead. type: float update_order: description: - Specifies the order of operations when rolling out an updated task. - Corresponds to the C(--update-order) option of C(docker service create). - Requires API version >= 1.29. + - Deprecated in 2.8, will be removed in 2.12. Use parameter C(update_config.order) instead. type: str choices: - - stop-first - - start-first + - stop-first + - start-first user: description: - Sets the username or UID used for the specified command. @@ -598,17 +764,19 @@ EXAMPLES = ''' docker_swarm_service: name: myservice image: alpine - restart_policy: any - restart_policy_attempts: 5 - restart_policy_delay: 5 - restart_policy_window: 30 + restart_config: + condition: any + max_attempts: 5 + delay: 5s + window: 30s - name: Set placement preferences docker_swarm_service: name: myservice image: alpine:edge - placement_preferences: - - spread: "node.labels.mylabel" + placement: + preferences: + - spread: "node.labels.mylabel" - name: Set configs docker_swarm_service: @@ -750,6 +918,11 @@ def get_nanoseconds_from_raw_option(name, value): ) +def get_value(key, values, default=None): + value = values.get(key) + return value if value is not None else default + + class DockerService(DockerBaseClass): def __init__(self): super(DockerService, self).__init__() @@ -850,12 +1023,178 @@ class DockerService(DockerBaseClass): } @staticmethod - def from_ansible_params(ap, old_service, image_digest, can_update_networks): + def get_restart_config_from_ansible_params(params): + restart_config = params['restart_config'] or {} + condition = get_value( + 'condition', + restart_config, + default=params['restart_policy'] + ) + delay = get_value( + 'delay', + restart_config, + default=params['restart_policy_delay'] + ) + delay = get_nanoseconds_from_raw_option( + 'restart_policy_delay', + delay + ) + max_attempts = get_value( + 'max_attempts', + restart_config, + default=params['restart_policy_attempts'] + ) + window = get_value( + 'window', + restart_config, + default=params['restart_policy_window'] + ) + window = get_nanoseconds_from_raw_option( + 'restart_policy_window', + window + ) + return { + 'restart_policy': condition, + 'restart_policy_delay': delay, + 'restart_policy_attempts': max_attempts, + 'restart_policy_window': window + } + + @staticmethod + def get_update_config_from_ansible_params(params): + update_config = params['update_config'] or {} + parallelism = get_value( + 'parallelism', + update_config, + default=params['update_parallelism'] + ) + delay = get_value( + 'delay', + update_config, + default=params['update_delay'] + ) + delay = get_nanoseconds_from_raw_option( + 'update_delay', + delay + ) + failure_action = get_value( + 'failure_action', + update_config, + default=params['update_failure_action'] + ) + monitor = get_value( + 'monitor', + update_config, + default=params['update_monitor'] + ) + monitor = get_nanoseconds_from_raw_option( + 'update_monitor', + monitor + ) + max_failure_ratio = get_value( + 'max_failure_ratio', + update_config, + default=params['update_max_failure_ratio'] + ) + order = get_value( + 'order', + update_config, + default=params['update_order'] + ) + return { + 'update_parallelism': parallelism, + 'update_delay': delay, + 'update_failure_action': failure_action, + 'update_monitor': monitor, + 'update_max_failure_ratio': max_failure_ratio, + 'update_order': order + } + + @staticmethod + def get_logging_from_ansible_params(params): + logging_config = params['logging'] or {} + driver = get_value( + 'driver', + logging_config, + default=params['log_driver'] + ) + options = get_value( + 'options', + logging_config, + default=params['log_driver_options'] + ) + return { + 'log_driver': driver, + 'log_driver_options': options, + } + + @staticmethod + def get_limits_from_ansible_params(params): + limits = params['limits'] or {} + cpus = get_value( + 'cpus', + limits, + default=params['limit_cpu'] + ) + memory = get_value( + 'memory', + limits, + default=params['limit_memory'] + ) + if memory is not None: + try: + memory = human_to_bytes(memory) + except ValueError as exc: + raise Exception('Failed to convert limit_memory to bytes: %s' % exc) + return { + 'limit_cpu': cpus, + 'limit_memory': memory, + } + + @staticmethod + def get_reservations_from_ansible_params(params): + reservations = params['reservations'] or {} + cpus = get_value( + 'cpus', + reservations, + default=params['reserve_cpu'] + ) + memory = get_value( + 'memory', + reservations, + default=params['reserve_memory'] + ) + + if memory is not None: + try: + memory = human_to_bytes(memory) + except ValueError as exc: + raise Exception('Failed to convert reserve_memory to bytes: %s' % exc) + return { + 'reserve_cpu': cpus, + 'reserve_memory': memory, + } + + @staticmethod + def get_placement_from_ansible_params(params): + placement = params['placement'] or {} + constraints = get_value( + 'constraints', + placement, + default=params['constraints'] + ) + + preferences = placement.get('preferences') + return { + 'constraints': constraints, + 'placement_preferences': preferences, + } + + @classmethod + def from_ansible_params(cls, ap, old_service, image_digest, can_update_networks): s = DockerService() s.image = image_digest s.can_update_networks = can_update_networks - s.constraints = ap['constraints'] - s.placement_preferences = ap['placement_preferences'] s.args = ap['args'] s.endpoint_mode = ap['endpoint_mode'] s.dns = ap['dns'] @@ -864,21 +1203,11 @@ class DockerService(DockerBaseClass): s.healthcheck, s.healthcheck_disabled = parse_healthcheck(ap['healthcheck']) s.hostname = ap['hostname'] s.tty = ap['tty'] - s.log_driver = ap['log_driver'] - s.log_driver_options = ap['log_driver_options'] s.labels = ap['labels'] s.container_labels = ap['container_labels'] - s.limit_cpu = ap['limit_cpu'] - s.reserve_cpu = ap['reserve_cpu'] s.mode = ap['mode'] s.networks = ap['networks'] s.stop_signal = ap['stop_signal'] - s.restart_policy = ap['restart_policy'] - s.restart_policy_attempts = ap['restart_policy_attempts'] - s.update_parallelism = ap['update_parallelism'] - s.update_failure_action = ap['update_failure_action'] - s.update_max_failure_ratio = ap['update_max_failure_ratio'] - s.update_order = ap['update_order'] s.user = ap['user'] s.working_dir = ap['working_dir'] @@ -913,24 +1242,32 @@ class DockerService(DockerBaseClass): s.env = get_docker_environment(ap['env'], ap['env_files']) - s.restart_policy_delay = get_nanoseconds_from_raw_option( - 'restart_policy_delay', - ap['restart_policy_delay'] - ) - s.restart_policy_window = get_nanoseconds_from_raw_option( - 'restart_policy_window', - ap['restart_policy_window'] - ) + update_config = cls.get_update_config_from_ansible_params(ap) + for key, value in update_config.items(): + setattr(s, key, value) + + restart_config = cls.get_restart_config_from_ansible_params(ap) + for key, value in restart_config.items(): + setattr(s, key, value) + + logging_config = cls.get_logging_from_ansible_params(ap) + for key, value in logging_config.items(): + setattr(s, key, value) + + limits = cls.get_limits_from_ansible_params(ap) + for key, value in limits.items(): + setattr(s, key, value) + + reservations = cls.get_reservations_from_ansible_params(ap) + for key, value in reservations.items(): + setattr(s, key, value) + + placement = cls.get_placement_from_ansible_params(ap) + for key, value in placement.items(): + setattr(s, key, value) + if ap['stop_grace_period'] is not None: s.stop_grace_period = convert_duration_to_nanosecond(ap['stop_grace_period']) - s.update_delay = get_nanoseconds_from_raw_option( - 'update_delay', - ap['update_delay'] - ) - s.update_monitor = get_nanoseconds_from_raw_option( - 'update_monitor', - ap['update_monitor'] - ) if ap['force_update']: s.force_update = int(str(time.time()).replace('.', '')) @@ -948,13 +1285,6 @@ class DockerService(DockerBaseClass): else: s.replicas = ap['replicas'] - for param_name in ['reserve_memory', 'limit_memory']: - if ap.get(param_name): - try: - setattr(s, param_name, human_to_bytes(ap[param_name])) - except ValueError as exc: - raise Exception('Failed to convert %s to bytes: %s' % (param_name, exc)) - if ap['publish'] is not None: s.publish = [] for param_p in ap['publish']: @@ -1752,16 +2082,23 @@ def main(): env_files=dict(type='list', elements='path'), force_update=dict(type='bool', default=False), groups=dict(type='list', elements='str'), - log_driver=dict(type='str'), - log_driver_options=dict(type='dict'), + logging=dict(type='dict', options=dict( + driver=dict(type='str'), + options=dict(type='dict'), + )), + log_driver=dict(type='str', removed_in_version='2.12'), + log_driver_options=dict(type='dict', removed_in_version='2.12'), publish=dict(type='list', elements='dict', options=dict( published_port=dict(type='int', required=True), target_port=dict(type='int', required=True), protocol=dict(type='str', default='tcp', choices=('tcp', 'udp')), mode=dict(type='str', choices=('ingress', 'host')), )), - constraints=dict(type='list'), - placement_preferences=dict(type='list'), + placement=dict(type='dict', options=dict( + constraints=dict(type='list'), + preferences=dict(type='list'), + )), + constraints=dict(type='list', removed_in_version='2.12'), tty=dict(type='bool'), dns=dict(type='list'), dns_search=dict(type='list'), @@ -1781,21 +2118,55 @@ def main(): endpoint_mode=dict(type='str', choices=['vip', 'dnsrr']), stop_grace_period=dict(type='str'), stop_signal=dict(type='str'), - limit_cpu=dict(type='float'), - limit_memory=dict(type='str'), - reserve_cpu=dict(type='float'), - reserve_memory=dict(type='str'), + limits=dict(type='dict', options=dict( + cpus=dict(type='float'), + memory=dict(type='str'), + )), + limit_cpu=dict(type='float', removed_in_version='2.12'), + limit_memory=dict(type='str', removed_in_version='2.12'), + reservations=dict(type='dict', options=dict( + cpus=dict(type='float'), + memory=dict(type='str'), + )), + reserve_cpu=dict(type='float', removed_in_version='2.12'), + reserve_memory=dict(type='str', removed_in_version='2.12'), resolve_image=dict(type='bool', default=True), - restart_policy=dict(type='str', choices=['none', 'on-failure', 'any']), - restart_policy_delay=dict(type='raw'), - restart_policy_attempts=dict(type='int'), - restart_policy_window=dict(type='raw'), - update_delay=dict(type='raw'), - update_parallelism=dict(type='int'), - update_failure_action=dict(type='str', choices=['continue', 'pause']), - update_monitor=dict(type='raw'), - update_max_failure_ratio=dict(type='float'), - update_order=dict(type='str', choices=['stop-first', 'start-first']), + restart_config=dict(type='dict', options=dict( + condition=dict(type='str', choices=['none', 'on-failure', 'any']), + delay=dict(type='str'), + max_attempts=dict(type='int'), + window=dict(type='str'), + )), + restart_policy=dict( + type='str', + choices=['none', 'on-failure', 'any'], + removed_in_version='2.12' + ), + restart_policy_delay=dict(type='raw', removed_in_version='2.12'), + restart_policy_attempts=dict(type='int', removed_in_version='2.12'), + restart_policy_window=dict(type='raw', removed_in_version='2.12'), + update_config=dict(type='dict', options=dict( + parallelism=dict(type='int'), + delay=dict(type='str'), + failure_action=dict(type='str', choices=['continue', 'pause']), + monitor=dict(type='str'), + max_failure_ratio=dict(type='float'), + order=dict(type='str'), + )), + update_delay=dict(type='raw', removed_in_version='2.12'), + update_parallelism=dict(type='int', removed_in_version='2.12'), + update_failure_action=dict( + type='str', + choices=['continue', 'pause'], + removed_in_version='2.12' + ), + update_monitor=dict(type='raw', removed_in_version='2.12'), + update_max_failure_ratio=dict(type='float', removed_in_version='2.12'), + update_order=dict( + type='str', + choices=['stop-first', 'start-first'], + removed_in_version='2.12' + ), user=dict(type='str'), working_dir=dict(type='str'), ) @@ -1816,7 +2187,6 @@ def main(): update_monitor=dict(docker_py_version='2.1.0', docker_api_version='1.25'), update_order=dict(docker_py_version='2.7.0', docker_api_version='1.29'), stop_signal=dict(docker_py_version='2.6.0', docker_api_version='1.28'), - placement_preferences=dict(docker_py_version='2.4.0', docker_api_version='1.27'), publish=dict(docker_py_version='3.0.0', docker_api_version='1.25'), # specials publish_mode=dict( @@ -1830,7 +2200,39 @@ def main(): docker_api_version='1.25', detect_usage=_detect_healthcheck_start_period, usage_msg='set healthcheck.start_period' - ) + ), + update_config_max_failure_ratio=dict( + docker_py_version='2.1.0', + docker_api_version='1.25', + detect_usage=lambda c: (c.module.params['update_config'] or {}).get( + 'max_failure_ratio' + ) is not None, + usage_msg='set update_config.max_failure_ratio' + ), + update_config_monitor=dict( + docker_py_version='2.1.0', + docker_api_version='1.25', + detect_usage=lambda c: (c.module.params['update_config'] or {}).get( + 'monitor' + ) is not None, + usage_msg='set update_config.monitor' + ), + update_config_order=dict( + docker_py_version='2.7.0', + docker_api_version='1.29', + detect_usage=lambda c: (c.module.params['update_config'] or {}).get( + 'order' + ) is not None, + usage_msg='set update_config.order' + ), + placement_config_preferences=dict( + docker_py_version='2.4.0', + docker_api_version='1.27', + detect_usage=lambda c: (c.module.params['placement'] or {}).get( + 'preferences' + ) is not None, + usage_msg='set placement.preferences' + ), ) required_if = [ diff --git a/test/integration/targets/docker_swarm_service/tasks/tests/logging.yml b/test/integration/targets/docker_swarm_service/tasks/tests/logging.yml new file mode 100644 index 00000000000..e847eb8418c --- /dev/null +++ b/test/integration/targets/docker_swarm_service/tasks/tests/logging.yml @@ -0,0 +1,148 @@ +--- + +- name: Registering service name + set_fact: + service_name: "{{ name_prefix ~ '-logging' }}" + +- name: Registering service name + set_fact: + service_names: "{{ service_names }} + [service_name]" + +#################################################################### +## logging.driver ################################################## +#################################################################### + +- name: logging.driver + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + logging: + driver: json-file + register: logging_driver_1 + +- name: logging.driver (idempotency) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + logging: + driver: json-file + register: logging_driver_2 + +- name: log_driver (idempotency, old name) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + log_driver: json-file + register: logging_driver_2b + +- name: logging.driver (change) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + logging: + driver: syslog + register: logging_driver_3 + +- name: cleanup + docker_swarm_service: + name: "{{ service_name }}" + state: absent + diff: no + +- assert: + that: + - logging_driver_1 is changed + - logging_driver_2 is not changed + - logging_driver_2b is not changed + - logging_driver_3 is changed + +#################################################################### +## logging.options ################################################# +#################################################################### + +- name: logging_options + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + logging: + driver: json-file + options: + labels: production_status + env: os,customer + register: logging_options_1 + +- name: logging_options (idempotency) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + logging: + driver: json-file + options: + env: os,customer + labels: production_status + register: logging_options_2 + +- name: log_driver_options (idempotency, old name) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + log_driver: json-file + log_driver_options: + env: os,customer + labels: production_status + register: logging_options_2b + +- name: logging_options (change) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + logging: + driver: json-file + options: + env: os,customer + labels: production_status + max-file: "1" + register: logging_options_3 + +- name: logging_options (empty) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + logging: + driver: json-file + options: {} + register: logging_options_4 + +- name: logging_options (empty idempotency) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + logging: + driver: json-file + options: {} + register: logging_options_5 + +- name: cleanup + docker_swarm_service: + name: "{{ service_name }}" + state: absent + diff: no + +- assert: + that: + - logging_options_1 is changed + - logging_options_2 is not changed + - logging_options_2b is not changed + - logging_options_3 is changed + - logging_options_4 is changed + - logging_options_5 is not changed diff --git a/test/integration/targets/docker_swarm_service/tasks/tests/options.yml b/test/integration/targets/docker_swarm_service/tasks/tests/options.yml index c964c4a2f1a..98e09153034 100644 --- a/test/integration/targets/docker_swarm_service/tasks/tests/options.yml +++ b/test/integration/targets/docker_swarm_service/tasks/tests/options.yml @@ -198,67 +198,6 @@ - "('version is ' ~ docker_api_version ~'. Minimum version required is 1.30') in configs_1.msg" when: docker_api_version is version('1.30', '<') -#################################################################### -## constraints ##################################################### -#################################################################### - -- name: constraints - docker_swarm_service: - name: "{{ service_name }}" - image: alpine:3.8 - command: '/bin/sh -v -c "sleep 10m"' - constraints: - - "node.role == manager" - register: constraints_1 - -- name: constraints (idempotency) - docker_swarm_service: - name: "{{ service_name }}" - image: alpine:3.8 - command: '/bin/sh -v -c "sleep 10m"' - constraints: - - "node.role == manager" - register: constraints_2 - -- name: constraints (change) - docker_swarm_service: - name: "{{ service_name }}" - image: alpine:3.8 - command: '/bin/sh -v -c "sleep 10m"' - constraints: - - "node.role == worker" - register: constraints_3 - -- name: constraints (empty) - docker_swarm_service: - name: "{{ service_name }}" - image: alpine:3.8 - command: '/bin/sh -v -c "sleep 10m"' - constraints: [] - register: constraints_4 - -- name: constraints (empty idempotency) - docker_swarm_service: - name: "{{ service_name }}" - image: alpine:3.8 - command: '/bin/sh -v -c "sleep 10m"' - constraints: [] - register: constraints_5 - -- name: cleanup - docker_swarm_service: - name: "{{ service_name }}" - state: absent - diff: no - -- assert: - that: - - constraints_1 is changed - - constraints_2 is not changed - - constraints_3 is changed - - constraints_4 is changed - - constraints_5 is not changed - #################################################################### ## command ######################################################### #################################################################### @@ -1226,196 +1165,6 @@ - labels_4 is changed - labels_5 is not changed -################################################################### -## limit_cpu ###################################################### -################################################################### - -- name: limit_cpu - docker_swarm_service: - name: "{{ service_name }}" - image: alpine:3.8 - command: '/bin/sh -v -c "sleep 10m"' - limit_cpu: 1 - register: limit_cpu_1 - -- name: limit_cpu (idempotency) - docker_swarm_service: - name: "{{ service_name }}" - image: alpine:3.8 - command: '/bin/sh -v -c "sleep 10m"' - limit_cpu: 1 - register: limit_cpu_2 - -- name: limit_cpu (change) - docker_swarm_service: - name: "{{ service_name }}" - image: alpine:3.8 - command: '/bin/sh -v -c "sleep 10m"' - limit_cpu: 2 - register: limit_cpu_3 - -- name: cleanup - docker_swarm_service: - name: "{{ service_name }}" - state: absent - diff: no - -- assert: - that: - - limit_cpu_1 is changed - - limit_cpu_2 is not changed - - limit_cpu_3 is changed - -################################################################### -## limit_memory ################################################### -################################################################### - -- name: limit_memory - docker_swarm_service: - name: "{{ service_name }}" - image: alpine:3.8 - command: '/bin/sh -v -c "sleep 10m"' - limit_memory: 64000000 - register: limit_memory_1 - -- name: limit_memory (idempotency) - docker_swarm_service: - name: "{{ service_name }}" - image: alpine:3.8 - command: '/bin/sh -v -c "sleep 10m"' - limit_memory: 64000000 - register: limit_memory_2 - -- name: limit_memory (change) - docker_swarm_service: - name: "{{ service_name }}" - image: alpine:3.8 - command: '/bin/sh -v -c "sleep 10m"' - limit_memory: 32000000 - register: limit_memory_3 - -- name: cleanup - docker_swarm_service: - name: "{{ service_name }}" - state: absent - diff: no - -- assert: - that: - - limit_memory_1 is changed - - limit_memory_2 is not changed - - limit_memory_3 is changed - -#################################################################### -## log_driver ###################################################### -#################################################################### - -- name: log_driver - docker_swarm_service: - name: "{{ service_name }}" - image: alpine:3.8 - command: '/bin/sh -v -c "sleep 10m"' - log_driver: json-file - register: log_driver_1 - -- name: log_driver (idempotency) - docker_swarm_service: - name: "{{ service_name }}" - image: alpine:3.8 - command: '/bin/sh -v -c "sleep 10m"' - log_driver: json-file - register: log_driver_2 - -- name: log_driver (change) - docker_swarm_service: - name: "{{ service_name }}" - image: alpine:3.8 - command: '/bin/sh -v -c "sleep 10m"' - log_driver: syslog - register: log_driver_3 - -- name: cleanup - docker_swarm_service: - name: "{{ service_name }}" - state: absent - diff: no - -- assert: - that: - - log_driver_1 is changed - - log_driver_2 is not changed - - log_driver_3 is changed - -#################################################################### -## log_driver_options ############################################## -#################################################################### - -- name: log_driver_options - docker_swarm_service: - name: "{{ service_name }}" - image: alpine:3.8 - command: '/bin/sh -v -c "sleep 10m"' - log_driver: json-file - log_driver_options: - labels: production_status - env: os,customer - register: log_driver_options_1 - -- name: log_driver_options (idempotency) - docker_swarm_service: - name: "{{ service_name }}" - image: alpine:3.8 - command: '/bin/sh -v -c "sleep 10m"' - log_driver: json-file - log_driver_options: - env: os,customer - labels: production_status - register: log_driver_options_2 - -- name: log_driver_options (change) - docker_swarm_service: - name: "{{ service_name }}" - image: alpine:3.8 - command: '/bin/sh -v -c "sleep 10m"' - log_driver: json-file - log_driver_options: - env: os,customer - labels: production_status - max-file: "1" - register: log_driver_options_3 - -- name: log_driver_options (empty) - docker_swarm_service: - name: "{{ service_name }}" - image: alpine:3.8 - command: '/bin/sh -v -c "sleep 10m"' - log_driver: json-file - log_driver_options: {} - register: log_driver_options_4 - -- name: log_driver_options (empty idempotency) - docker_swarm_service: - name: "{{ service_name }}" - image: alpine:3.8 - command: '/bin/sh -v -c "sleep 10m"' - log_driver: json-file - log_driver_options: {} - register: log_driver_options_5 - -- name: cleanup - docker_swarm_service: - name: "{{ service_name }}" - state: absent - diff: no - -- assert: - that: - - log_driver_options_1 is changed - - log_driver_options_2 is not changed - - log_driver_options_3 is changed - - log_driver_options_4 is changed - - log_driver_options_5 is not changed - ################################################################### ## mode ########################################################### ################################################################### @@ -1714,67 +1463,6 @@ - stop_signal_2 is not changed - stop_signal_3 is changed -#################################################################### -## placement_preferences ########################################### -#################################################################### - -- name: placement_preferences - docker_swarm_service: - name: "{{ service_name }}" - image: alpine:3.8 - command: '/bin/sh -v -c "sleep 10m"' - placement_preferences: - - spread: "node.labels.test" - register: placement_preferences_1 - -- name: placement_preferences (idempotency) - docker_swarm_service: - name: "{{ service_name }}" - image: alpine:3.8 - command: '/bin/sh -v -c "sleep 10m"' - placement_preferences: - - spread: "node.labels.test" - register: placement_preferences_2 - -- name: placement_preferences (change) - docker_swarm_service: - name: "{{ service_name }}" - image: alpine:3.8 - command: '/bin/sh -v -c "sleep 10m"' - placement_preferences: - - spread: "node.labels.test2" - register: placement_preferences_3 - -- name: placement_preferences (empty) - docker_swarm_service: - name: "{{ service_name }}" - image: alpine:3.8 - command: '/bin/sh -v -c "sleep 10m"' - placement_preferences: [] - register: placement_preferences_4 - -- name: placement_preferences (empty idempotency) - docker_swarm_service: - name: "{{ service_name }}" - image: alpine:3.8 - command: '/bin/sh -v -c "sleep 10m"' - placement_preferences: [] - register: placement_preferences_5 - -- name: cleanup - docker_swarm_service: - name: "{{ service_name }}" - state: absent - diff: no - -- assert: - that: - - placement_preferences_1 is changed - - placement_preferences_2 is not changed - - placement_preferences_3 is changed - - placement_preferences_4 is changed - - placement_preferences_5 is not changed - #################################################################### ## publish ######################################################### #################################################################### @@ -1931,32 +1619,32 @@ - replicas_3 is changed ################################################################### -## reserve_cpu #################################################### +# resolve_image ################################################### ################################################################### -- name: reserve_cpu +- name: resolve_image (false) docker_swarm_service: name: "{{ service_name }}" image: alpine:3.8 command: '/bin/sh -v -c "sleep 10m"' - reserve_cpu: 1 - register: reserve_cpu_1 + resolve_image: false + register: resolve_image_1 -- name: reserve_cpu (idempotency) +- name: resolve_image (false idempotency) docker_swarm_service: name: "{{ service_name }}" image: alpine:3.8 command: '/bin/sh -v -c "sleep 10m"' - reserve_cpu: 1 - register: reserve_cpu_2 + resolve_image: false + register: resolve_image_2 -- name: reserve_cpu (change) +- name: resolve_image (change) docker_swarm_service: name: "{{ service_name }}" image: alpine:3.8 command: '/bin/sh -v -c "sleep 10m"' - reserve_cpu: 2 - register: reserve_cpu_3 + resolve_image: true + register: resolve_image_3 - name: cleanup docker_swarm_service: @@ -1966,305 +1654,65 @@ - assert: that: - - reserve_cpu_1 is changed - - reserve_cpu_2 is not changed - - reserve_cpu_3 is changed + - resolve_image_1 is changed + - resolve_image_2 is not changed + - resolve_image_3 is changed -################################################################### -## reserve_memory ################################################# -################################################################### +#################################################################### +## secrets ######################################################### +#################################################################### -- name: reserve_memory +- name: secrets docker_swarm_service: name: "{{ service_name }}" image: alpine:3.8 command: '/bin/sh -v -c "sleep 10m"' - reserve_memory: 64000000 - register: reserve_memory_1 + secrets: + - secret_id: "{{ secret_result_1.secret_id }}" + secret_name: "{{ secret_name_1 }}" + filename: "/run/secrets/{{ secret_name_1 }}.txt" + register: secrets_1 -- name: reserve_memory (idempotency) +- name: secrets (idempotency) docker_swarm_service: name: "{{ service_name }}" image: alpine:3.8 command: '/bin/sh -v -c "sleep 10m"' - reserve_memory: 64000000 - register: reserve_memory_2 + secrets: + - secret_id: "{{ secret_result_1.secret_id }}" + secret_name: "{{ secret_name_1 }}" + filename: "/run/secrets/{{ secret_name_1 }}.txt" + register: secrets_2 -- name: reserve_memory (change) +- name: secrets (add) docker_swarm_service: name: "{{ service_name }}" image: alpine:3.8 command: '/bin/sh -v -c "sleep 10m"' - reserve_memory: 32000000 - register: reserve_memory_3 - -- name: cleanup - docker_swarm_service: - name: "{{ service_name }}" - state: absent - diff: no - -- assert: - that: - - reserve_memory_1 is changed - - reserve_memory_2 is not changed - - reserve_memory_3 is changed - -################################################################### -# resolve_image ################################################### -################################################################### + secrets: + - secret_id: "{{ secret_result_1.secret_id }}" + secret_name: "{{ secret_name_1 }}" + filename: "/run/secrets/{{ secret_name_1 }}.txt" + - secret_id: "{{ secret_result_2.secret_id }}" + secret_name: "{{ secret_name_2 }}" + filename: "/run/secrets/{{ secret_name_2 }}.txt" + register: secrets_3 -- name: resolve_image (false) +- name: secrets (empty) docker_swarm_service: name: "{{ service_name }}" image: alpine:3.8 command: '/bin/sh -v -c "sleep 10m"' - resolve_image: false - register: resolve_image_1 + secrets: [] + register: secrets_4 -- name: resolve_image (false idempotency) +- name: secrets (empty idempotency) docker_swarm_service: name: "{{ service_name }}" image: alpine:3.8 command: '/bin/sh -v -c "sleep 10m"' - resolve_image: false - register: resolve_image_2 - -- name: resolve_image (change) - docker_swarm_service: - name: "{{ service_name }}" - image: alpine:3.8 - command: '/bin/sh -v -c "sleep 10m"' - resolve_image: true - register: resolve_image_3 - -- name: cleanup - docker_swarm_service: - name: "{{ service_name }}" - state: absent - diff: no - -- assert: - that: - - resolve_image_1 is changed - - resolve_image_2 is not changed - - resolve_image_3 is changed - -################################################################### -## restart_policy ################################################# -################################################################### - -- name: restart_policy - docker_swarm_service: - name: "{{ service_name }}" - image: alpine:3.8 - command: '/bin/sh -v -c "sleep 10m"' - restart_policy: "on-failure" - register: restart_policy_1 - -- name: restart_policy (idempotency) - docker_swarm_service: - name: "{{ service_name }}" - image: alpine:3.8 - command: '/bin/sh -v -c "sleep 10m"' - restart_policy: "on-failure" - register: restart_policy_2 - -- name: restart_policy (change) - docker_swarm_service: - name: "{{ service_name }}" - image: alpine:3.8 - command: '/bin/sh -v -c "sleep 10m"' - restart_policy: "any" - register: restart_policy_3 - -- name: cleanup - docker_swarm_service: - name: "{{ service_name }}" - state: absent - diff: no - -- assert: - that: - - restart_policy_1 is changed - - restart_policy_2 is not changed - - restart_policy_3 is changed - -################################################################### -## restart_policy_attempts ######################################## -################################################################### - -- name: restart_policy_attempts - docker_swarm_service: - name: "{{ service_name }}" - image: alpine:3.8 - command: '/bin/sh -v -c "sleep 10m"' - restart_policy_attempts: 1 - register: restart_policy_attempts_1 - -- name: restart_policy_attempts (idempotency) - docker_swarm_service: - name: "{{ service_name }}" - image: alpine:3.8 - command: '/bin/sh -v -c "sleep 10m"' - restart_policy_attempts: 1 - register: restart_policy_attempts_2 - -- name: restart_policy_attempts (change) - docker_swarm_service: - name: "{{ service_name }}" - image: alpine:3.8 - command: '/bin/sh -v -c "sleep 10m"' - restart_policy_attempts: 2 - register: restart_policy_attempts_3 - -- name: cleanup - docker_swarm_service: - name: "{{ service_name }}" - state: absent - diff: no - -- assert: - that: - - restart_policy_attempts_1 is changed - - restart_policy_attempts_2 is not changed - - restart_policy_attempts_3 is changed - -################################################################### -## restart_policy_delay ########################################### -################################################################### - -- name: restart_policy_delay - docker_swarm_service: - name: "{{ service_name }}" - image: alpine:3.8 - command: '/bin/sh -v -c "sleep 10m"' - restart_policy_delay: 5000000000 - register: restart_policy_delay_1 - -- name: restart_policy_delay (idempotency) - docker_swarm_service: - name: "{{ service_name }}" - image: alpine:3.8 - command: '/bin/sh -v -c "sleep 10m"' - restart_policy_delay: 5s - register: restart_policy_delay_2 - -- name: restart_policy_delay (change) - docker_swarm_service: - name: "{{ service_name }}" - image: alpine:3.8 - command: '/bin/sh -v -c "sleep 10m"' - restart_policy_delay: 10000000000 - register: restart_policy_delay_3 - -- name: cleanup - docker_swarm_service: - name: "{{ service_name }}" - state: absent - diff: no - -- assert: - that: - - restart_policy_delay_1 is changed - - restart_policy_delay_2 is not changed - - restart_policy_delay_3 is changed - -################################################################### -## restart_policy_window ########################################## -################################################################### - -- name: restart_policy_window - docker_swarm_service: - name: "{{ service_name }}" - image: alpine:3.8 - command: '/bin/sh -v -c "sleep 10m"' - restart_policy_window: 10000000000 - register: restart_policy_window_1 - -- name: restart_policy_window (idempotency) - docker_swarm_service: - name: "{{ service_name }}" - image: alpine:3.8 - command: '/bin/sh -v -c "sleep 10m"' - restart_policy_window: 10s - register: restart_policy_window_2 - -- name: restart_policy_window (change) - docker_swarm_service: - name: "{{ service_name }}" - image: alpine:3.8 - command: '/bin/sh -v -c "sleep 10m"' - restart_policy_window: 20s - register: restart_policy_window_3 - -- name: cleanup - docker_swarm_service: - name: "{{ service_name }}" - state: absent - diff: no - -- assert: - that: - - restart_policy_window_1 is changed - - restart_policy_window_2 is not changed - - restart_policy_window_3 is changed - -#################################################################### -## secrets ######################################################### -#################################################################### - -- name: secrets - docker_swarm_service: - name: "{{ service_name }}" - image: alpine:3.8 - command: '/bin/sh -v -c "sleep 10m"' - secrets: - - secret_id: "{{ secret_result_1.secret_id }}" - secret_name: "{{ secret_name_1 }}" - filename: "/run/secrets/{{ secret_name_1 }}.txt" - register: secrets_1 - -- name: secrets (idempotency) - docker_swarm_service: - name: "{{ service_name }}" - image: alpine:3.8 - command: '/bin/sh -v -c "sleep 10m"' - secrets: - - secret_id: "{{ secret_result_1.secret_id }}" - secret_name: "{{ secret_name_1 }}" - filename: "/run/secrets/{{ secret_name_1 }}.txt" - register: secrets_2 - -- name: secrets (add) - docker_swarm_service: - name: "{{ service_name }}" - image: alpine:3.8 - command: '/bin/sh -v -c "sleep 10m"' - secrets: - - secret_id: "{{ secret_result_1.secret_id }}" - secret_name: "{{ secret_name_1 }}" - filename: "/run/secrets/{{ secret_name_1 }}.txt" - - secret_id: "{{ secret_result_2.secret_id }}" - secret_name: "{{ secret_name_2 }}" - filename: "/run/secrets/{{ secret_name_2 }}.txt" - register: secrets_3 - -- name: secrets (empty) - docker_swarm_service: - name: "{{ service_name }}" - image: alpine:3.8 - command: '/bin/sh -v -c "sleep 10m"' - secrets: [] - register: secrets_4 - -- name: secrets (empty idempotency) - docker_swarm_service: - name: "{{ service_name }}" - image: alpine:3.8 - command: '/bin/sh -v -c "sleep 10m"' - secrets: [] - register: secrets_5 + secrets: [] + register: secrets_5 - name: cleanup docker_swarm_service: @@ -2332,252 +1780,6 @@ - "('version is ' ~ docker_api_version ~'. Minimum version required is 1.25') in tty_1.msg" when: docker_api_version is version('1.25', '<') -################################################################### -## update_delay ################################################### -################################################################### - -- name: update_delay - docker_swarm_service: - name: "{{ service_name }}" - image: alpine:3.8 - command: '/bin/sh -v -c "sleep 10m"' - update_delay: 5000000000 - register: update_delay_1 - -- name: update_delay (idempotency) - docker_swarm_service: - name: "{{ service_name }}" - image: alpine:3.8 - command: '/bin/sh -v -c "sleep 10m"' - update_delay: 5s - register: update_delay_2 - -- name: update_delay (change) - docker_swarm_service: - name: "{{ service_name }}" - image: alpine:3.8 - command: '/bin/sh -v -c "sleep 10m"' - update_delay: 12000000000 - register: update_delay_3 - -- name: cleanup - docker_swarm_service: - name: "{{ service_name }}" - state: absent - diff: no - -- assert: - that: - - update_delay_1 is changed - - update_delay_2 is not changed - - update_delay_3 is changed - -################################################################### -## update_failure_action ########################################## -################################################################### - -- name: update_failure_action - docker_swarm_service: - name: "{{ service_name }}" - image: alpine:3.8 - command: '/bin/sh -v -c "sleep 10m"' - update_failure_action: "pause" - register: update_failure_action_1 - -- name: update_failure_action (idempotency) - docker_swarm_service: - name: "{{ service_name }}" - image: alpine:3.8 - command: '/bin/sh -v -c "sleep 10m"' - update_failure_action: "pause" - register: update_failure_action_2 - -- name: update_failure_action (change) - docker_swarm_service: - name: "{{ service_name }}" - image: alpine:3.8 - command: '/bin/sh -v -c "sleep 10m"' - update_failure_action: "continue" - register: update_failure_action_3 - -- name: cleanup - docker_swarm_service: - name: "{{ service_name }}" - state: absent - diff: no - -- assert: - that: - - update_failure_action_1 is changed - - update_failure_action_2 is not changed - - update_failure_action_3 is changed - -################################################################### -## update_max_failure_ratio ####################################### -################################################################### - -- name: update_max_failure_ratio - docker_swarm_service: - name: "{{ service_name }}" - image: alpine:3.8 - command: '/bin/sh -v -c "sleep 10m"' - update_max_failure_ratio: 0.25 - register: update_max_failure_ratio_1 - -- name: update_max_failure_ratio (idempotency) - docker_swarm_service: - name: "{{ service_name }}" - image: alpine:3.8 - command: '/bin/sh -v -c "sleep 10m"' - update_max_failure_ratio: 0.25 - register: update_max_failure_ratio_2 - -- name: update_max_failure_ratio (change) - docker_swarm_service: - name: "{{ service_name }}" - image: alpine:3.8 - command: '/bin/sh -v -c "sleep 10m"' - update_max_failure_ratio: 0.50 - register: update_max_failure_ratio_3 - -- name: cleanup - docker_swarm_service: - name: "{{ service_name }}" - state: absent - diff: no - -- assert: - that: - - update_max_failure_ratio_1 is changed - - update_max_failure_ratio_2 is not changed - - update_max_failure_ratio_3 is changed - -################################################################### -# update_monitor ################################################## -################################################################### - -- name: update_monitor - docker_swarm_service: - name: "{{ service_name }}" - image: alpine:3.8 - command: '/bin/sh -v -c "sleep 10m"' - update_monitor: 10000000000 - register: update_monitor_1 - -- name: update_monitor (idempotency) - docker_swarm_service: - name: "{{ service_name }}" - image: alpine:3.8 - command: '/bin/sh -v -c "sleep 10m"' - update_monitor: 10s - register: update_monitor_2 - -- name: update_monitor (change) - docker_swarm_service: - name: "{{ service_name }}" - image: alpine:3.8 - command: '/bin/sh -v -c "sleep 10m"' - update_monitor: 60s - register: update_monitor_3 - -- name: cleanup - docker_swarm_service: - name: "{{ service_name }}" - state: absent - diff: no - -- assert: - that: - - update_monitor_1 is changed - - update_monitor_2 is not changed - - update_monitor_3 is changed - -################################################################### -# update_order #################################################### -################################################################### - -- name: update_order - docker_swarm_service: - name: "{{ service_name }}" - image: alpine:3.8 - command: '/bin/sh -v -c "sleep 10m"' - update_order: "start-first" - register: update_order_1 - -- name: update_order (idempotency) - docker_swarm_service: - name: "{{ service_name }}" - image: alpine:3.8 - command: '/bin/sh -v -c "sleep 10m"' - update_order: "start-first" - register: update_order_2 - -- name: update_order (change) - docker_swarm_service: - name: "{{ service_name }}" - image: alpine:3.8 - command: '/bin/sh -v -c "sleep 10m"' - update_order: "stop-first" - register: update_order_3 - -- name: cleanup - docker_swarm_service: - name: "{{ service_name }}" - state: absent - diff: no - -- assert: - that: - - update_order_1 is changed - - update_order_2 is not changed - - update_order_3 is changed - when: docker_api_version is version('1.29', '>=') -- assert: - that: - - secrets_1 is failed - - "('version is ' ~ docker_api_version ~'. Minimum version required is 1.29') in update_order_1.msg" - when: docker_api_version is version('1.29', '<') - -################################################################### -## update_parallelism ############################################# -################################################################### - -- name: update_parallelism - docker_swarm_service: - name: "{{ service_name }}" - image: alpine:3.8 - command: '/bin/sh -v -c "sleep 10m"' - update_parallelism: 2 - register: update_parallelism_1 - -- name: update_parallelism (idempotency) - docker_swarm_service: - name: "{{ service_name }}" - image: alpine:3.8 - command: '/bin/sh -v -c "sleep 10m"' - update_parallelism: 2 - register: update_parallelism_2 - -- name: update_parallelism (change) - docker_swarm_service: - name: "{{ service_name }}" - image: alpine:3.8 - command: '/bin/sh -v -c "sleep 10m"' - update_parallelism: 1 - register: update_parallelism_3 - -- name: cleanup - docker_swarm_service: - name: "{{ service_name }}" - state: absent - diff: no - -- assert: - that: - - update_parallelism_1 is changed - - update_parallelism_2 is not changed - - update_parallelism_3 is changed - ################################################################### ## user ########################################################### ################################################################### diff --git a/test/integration/targets/docker_swarm_service/tasks/tests/placement.yml b/test/integration/targets/docker_swarm_service/tasks/tests/placement.yml new file mode 100644 index 00000000000..50404a294e0 --- /dev/null +++ b/test/integration/targets/docker_swarm_service/tasks/tests/placement.yml @@ -0,0 +1,152 @@ +--- + +- name: Registering service name + set_fact: + service_name: "{{ name_prefix ~ '-placement' }}" + +- name: Registering service name + set_fact: + service_names: "{{ service_names }} + [service_name]" + + +#################################################################### +## placement.preferences ########################################### +#################################################################### + +- name: placement.preferences + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + placement: + preferences: + - spread: "node.labels.test" + register: placement_preferences_1 + +- name: placement.preferences (idempotency) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + placement: + preferences: + - spread: "node.labels.test" + register: placement_preferences_2 + +- name: placement.preferences (change) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + placement: + preferences: + - spread: "node.labels.test2" + register: placement_preferences_3 + +- name: placement.preferences (empty) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + placement: + preferences: [] + register: placement_preferences_4 + +- name: placement.preferences (empty idempotency) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + placement: + preferences: [] + register: placement_preferences_5 + +- name: cleanup + docker_swarm_service: + name: "{{ service_name }}" + state: absent + diff: no + +- assert: + that: + - placement_preferences_1 is changed + - placement_preferences_2 is not changed + - placement_preferences_3 is changed + - placement_preferences_4 is changed + - placement_preferences_5 is not changed + +#################################################################### +## placement.constraints ##################################################### +#################################################################### + +- name: placement.constraints + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + placement: + constraints: + - "node.role == manager" + register: constraints_1 + +- name: placement.constraints (idempotency) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + placement: + constraints: + - "node.role == manager" + register: constraints_2 + +- name: constraints (idempotency, old name) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + constraints: + - "node.role == manager" + register: constraints_2b + +- name: placement.constraints (change) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + placement: + constraints: + - "node.role == worker" + register: constraints_3 + +- name: placement.constraints (empty) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + placement: + constraints: [] + register: constraints_4 + +- name: placement.constraints (empty idempotency) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + placement: + constraints: [] + register: constraints_5 + +- name: cleanup + docker_swarm_service: + name: "{{ service_name }}" + state: absent + diff: no + +- assert: + that: + - constraints_1 is changed + - constraints_2 is not changed + - constraints_2b is not changed + - constraints_3 is changed + - constraints_4 is changed + - constraints_5 is not changed diff --git a/test/integration/targets/docker_swarm_service/tasks/tests/resources.yml b/test/integration/targets/docker_swarm_service/tasks/tests/resources.yml new file mode 100644 index 00000000000..9dd31ed5843 --- /dev/null +++ b/test/integration/targets/docker_swarm_service/tasks/tests/resources.yml @@ -0,0 +1,214 @@ +--- + +- name: Registering service name + set_fact: + service_name: "{{ name_prefix ~ '-resources' }}" + +- name: Registering service name + set_fact: + service_names: "{{ service_names }} + [service_name]" + +#################################################################### +## limits.cpus ##################################################### +#################################################################### + +- name: limits.cpus + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + limits: + cpus: 1 + register: limit_cpu_1 + +- name: limits.cpus (idempotency) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + limits: + cpus: 1 + register: limit_cpu_2 + +- name: limit_cpu (idempotency, old name) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + limit_cpu: 1 + register: limit_cpu_2b + +- name: limits.cpus (change) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + limits: + cpus: 2 + register: limit_cpu_3 + +- name: cleanup + docker_swarm_service: + name: "{{ service_name }}" + state: absent + diff: no + +- assert: + that: + - limit_cpu_1 is changed + - limit_cpu_2 is not changed + - limit_cpu_2b is not changed + - limit_cpu_3 is changed + +################################################################### +## limits.memory ################################################## +################################################################### + +- name: limits.memory + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + limits: + memory: 64M + register: limit_memory_1 + +- name: limits.memory (idempotency) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + limits: + memory: 64M + register: limit_memory_2 + +- name: limit_memory (idempotency, old name) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + limit_memory: 67108864 + register: limit_memory_2b + +- name: limits.memory (change) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + limit_memory: 32M + register: limit_memory_3 + +- name: cleanup + docker_swarm_service: + name: "{{ service_name }}" + state: absent + diff: no + +- assert: + that: + - limit_memory_1 is changed + - limit_memory_2 is not changed + - limit_memory_2b is not changed + - limit_memory_3 is changed + +################################################################### +## reservations.cpus ############################################## +################################################################### + +- name: reserve_cpu + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + reservations: + cpus: 1 + register: reserve_cpu_1 + +- name: reserve_cpu (idempotency) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + reservations: + cpus: 1 + register: reserve_cpu_2 + +- name: reserve_cpu (idempotency, old name) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + reserve_cpu: 1 + register: reserve_cpu_2b + +- name: reserve_cpu (change) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + reservations: + cpus: 2 + register: reserve_cpu_3 + +- name: cleanup + docker_swarm_service: + name: "{{ service_name }}" + state: absent + diff: no + +- assert: + that: + - reserve_cpu_1 is changed + - reserve_cpu_2 is not changed + - reserve_cpu_2b is not changed + - reserve_cpu_3 is changed + +################################################################### +## reservations.memory ############################################ +################################################################### + +- name: reservations.memory + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + reservations: + memory: 64M + register: reserve_memory_1 + +- name: reservations.memory (idempotency) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + reserve_memory: 64M + register: reserve_memory_2 + +- name: reserve_memory (idempotency, old name) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + reserve_memory: 67108864 + register: reserve_memory_2b + +- name: reservations.memory (change) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + reserve_memory: 32M + register: reserve_memory_3 + +- name: cleanup + docker_swarm_service: + name: "{{ service_name }}" + state: absent + diff: no + +- assert: + that: + - reserve_memory_1 is changed + - reserve_memory_2 is not changed + - reserve_memory_2b is not changed + - reserve_memory_3 is changed diff --git a/test/integration/targets/docker_swarm_service/tasks/tests/restart_config.yml b/test/integration/targets/docker_swarm_service/tasks/tests/restart_config.yml new file mode 100644 index 00000000000..fd7e0bfb230 --- /dev/null +++ b/test/integration/targets/docker_swarm_service/tasks/tests/restart_config.yml @@ -0,0 +1,217 @@ +--- + +- name: Registering service name + set_fact: + service_name: "{{ name_prefix ~ '-restart_config' }}" + +- name: Registering service name + set_fact: + service_names: "{{ service_names }} + [service_name]" + +################################################################### +## restart_config.condition ####################################### +################################################################### + +- name: restart_config.condition + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + restart_config: + condition: "on-failure" + register: restart_policy_1 + +- name: restart_config.condition (idempotency) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + restart_config: + condition: "on-failure" + register: restart_policy_2 + +- name: restart_policy (idempotency, old name) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + restart_policy: "on-failure" + register: restart_policy_2b + +- name: restart_config.condition (change) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + restart_config: + condition: "any" + register: restart_policy_3 + +- name: cleanup + docker_swarm_service: + name: "{{ service_name }}" + state: absent + diff: no + +- assert: + that: + - restart_policy_1 is changed + - restart_policy_2 is not changed + - restart_policy_2b is not changed + - restart_policy_3 is changed + +################################################################### +## restart_config.max_attempts #################################### +################################################################### + +- name: restart_config.max_attempts + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + restart_config: + max_attempts: 1 + register: restart_policy_attempts_1 + +- name: restart_config.max_attempts (idempotency) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + restart_config: + max_attempts: 1 + register: restart_policy_attempts_2 + +- name: restart_policy_attempts (idempotency, old name) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + restart_policy_attempts: 1 + register: restart_policy_attempts_2b + +- name: restart_config.max_attempts (change) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + restart_config: + max_attempts: 2 + register: restart_policy_attempts_3 + +- name: cleanup + docker_swarm_service: + name: "{{ service_name }}" + state: absent + diff: no + +- assert: + that: + - restart_policy_attempts_1 is changed + - restart_policy_attempts_2 is not changed + - restart_policy_attempts_2b is not changed + - restart_policy_attempts_3 is changed + +################################################################### +## restart_config.delay ########################################### +################################################################### + +- name: restart_config.delay + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + restart_config: + delay: 5s + register: restart_policy_delay_1 + +- name: restart_config.delay (idempotency) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + restart_config: + delay: 5s + register: restart_policy_delay_2 + +- name: restart_policy_delay (idempotency, old name) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + restart_policy_delay: 5000000000 + register: restart_policy_delay_2b + +- name: restart_config.delay (change) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + restart_config: + delay: 10s + register: restart_policy_delay_3 + +- name: cleanup + docker_swarm_service: + name: "{{ service_name }}" + state: absent + diff: no + +- assert: + that: + - restart_policy_delay_1 is changed + - restart_policy_delay_2 is not changed + - restart_policy_delay_2b is not changed + - restart_policy_delay_3 is changed + +################################################################### +## restart_config.window ########################################## +################################################################### + +- name: restart_config.window + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + restart_config: + window: 10s + register: restart_policy_window_1 + +- name: restart_config.window (idempotency) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + restart_config: + window: 10s + register: restart_policy_window_2 + +- name: restart_policy_window (idempotency, old name) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + restart_policy_window: 10000000000 + register: restart_policy_window_2b + +- name: restart_config.window (change) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + restart_config: + window: 20s + register: restart_policy_window_3 + +- name: cleanup + docker_swarm_service: + name: "{{ service_name }}" + state: absent + diff: no + +- assert: + that: + - restart_policy_window_1 is changed + - restart_policy_window_2 is not changed + - restart_policy_window_2b is not changed + - restart_policy_window_3 is changed diff --git a/test/integration/targets/docker_swarm_service/tasks/tests/update_config.yml b/test/integration/targets/docker_swarm_service/tasks/tests/update_config.yml new file mode 100644 index 00000000000..fab0af85c85 --- /dev/null +++ b/test/integration/targets/docker_swarm_service/tasks/tests/update_config.yml @@ -0,0 +1,327 @@ +--- + +- name: Registering service name + set_fact: + service_name: "{{ name_prefix ~ '-update_config' }}" + +- name: Registering service name + set_fact: + service_names: "{{ service_names }} + [service_name]" + +################################################################### +## update_config.delay ############################################ +################################################################### + +- name: update_config.delay + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + update_config: + delay: 5s + register: update_delay_1 + +- name: update_config.delay (idempotency) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + update_config: + delay: 5s + register: update_delay_2 + +- name: update_delay (idempotency, old name) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + update_delay: 5000000000 + register: update_delay_2b + +- name: update_config.delay (change) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + update_config: + delay: 12s + register: update_delay_3 + +- name: cleanup + docker_swarm_service: + name: "{{ service_name }}" + state: absent + diff: no + +- assert: + that: + - update_delay_1 is changed + - update_delay_2 is not changed + - update_delay_2b is not changed + - update_delay_3 is changed + +################################################################### +## update_config.failure_action ################################### +################################################################### + +- name: update_config.failure_action + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + update_config: + failure_action: "pause" + register: update_failure_action_1 + +- name: update_config.failure_action (idempotency) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + update_config: + failure_action: "pause" + register: update_failure_action_2 + +- name: update_failure_action (idempotency, old name) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + update_failure_action: "pause" + register: update_failure_action_2b + +- name: update_config.failure_action (change) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + update_config: + failure_action: "continue" + register: update_failure_action_3 + +- name: cleanup + docker_swarm_service: + name: "{{ service_name }}" + state: absent + diff: no + +- assert: + that: + - update_failure_action_1 is changed + - update_failure_action_2 is not changed + - update_failure_action_2b is not changed + - update_failure_action_3 is changed + +################################################################### +## update_config.max_failure_ratio ################################ +################################################################### + +- name: update_config.max_failure_ratio + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + update_config: + max_failure_ratio: 0.25 + register: update_max_failure_ratio_1 + +- name: update_config.max_failure_ratio (idempotency) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + update_config: + max_failure_ratio: 0.25 + register: update_max_failure_ratio_2 + +- name: update_max_failure_ratio (idempotency, old name) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + update_max_failure_ratio: 0.25 + register: update_max_failure_ratio_2b + +- name: update_config.max_failure_ratio (change) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + update_config: + max_failure_ratio: 0.50 + register: update_max_failure_ratio_3 + +- name: cleanup + docker_swarm_service: + name: "{{ service_name }}" + state: absent + diff: no + +- assert: + that: + - update_max_failure_ratio_1 is changed + - update_max_failure_ratio_2 is not changed + - update_max_failure_ratio_2b is not changed + - update_max_failure_ratio_3 is changed + +################################################################### +# update_config.monitor ########################################### +################################################################### + +- name: update_config.monitor + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + update_config: + monitor: 10s + register: update_monitor_1 + +- name: update_config.monitor (idempotency) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + update_config: + monitor: 10s + register: update_monitor_2 + +- name: update_monitor (idempotency, old name) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + update_monitor: 10s + register: update_monitor_2b + +- name: update_config.monitor (change) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + update_config: + monitor: 60s + register: update_monitor_3 + +- name: cleanup + docker_swarm_service: + name: "{{ service_name }}" + state: absent + diff: no + +- assert: + that: + - update_monitor_1 is changed + - update_monitor_2 is not changed + - update_monitor_2b is not changed + - update_monitor_3 is changed + +################################################################### +# update_config.order ############################################# +################################################################### + +- name: update_config.order + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + update_config: + order: "start-first" + register: update_order_1 + +- name: update_config.order (idempotency) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + update_config: + order: "start-first" + register: update_order_2 + +- name: update_order (idempotency, old name) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + update_order: "start-first" + register: update_order_2b + +- name: update_config.order (change) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + update_config: + order: "stop-first" + register: update_order_3 + +- name: cleanup + docker_swarm_service: + name: "{{ service_name }}" + state: absent + diff: no + +- assert: + that: + - update_order_1 is changed + - update_order_2 is not changed + - update_order_2b is not changed + - update_order_3 is changed + when: docker_api_version is version('1.29', '>=') +- assert: + that: + - secrets_1 is failed + - "('version is ' ~ docker_api_version ~'. Minimum version required is 1.29') in update_order_1.msg" + when: docker_api_version is version('1.29', '<') + +################################################################### +## update_config.parallelism ###################################### +################################################################### + +- name: update_config.parallelism + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + update_config: + parallelism: 2 + register: update_parallelism_1 + +- name: update_config.parallelism (idempotency) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + update_config: + parallelism: 2 + register: update_parallelism_2 + +- name: update_parallelism (idempotency, old name) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + update_parallelism: 2 + register: update_parallelism_2b + +- name: update_config.parallelism (change) + docker_swarm_service: + name: "{{ service_name }}" + image: alpine:3.8 + command: '/bin/sh -v -c "sleep 10m"' + update_config: + parallelism: 1 + register: update_parallelism_3 + +- name: cleanup + docker_swarm_service: + name: "{{ service_name }}" + state: absent + diff: no + +- assert: + that: + - update_parallelism_1 is changed + - update_parallelism_2 is not changed + - update_parallelism_2b is not changed + - update_parallelism_3 is changed