From d0c245ba83de157c0066dc6efe7a506135764329 Mon Sep 17 00:00:00 2001 From: bunkerity Date: Tue, 23 Aug 2022 16:41:56 +0200 Subject: [PATCH] tests - fix bug when testing if a swarm stack is healthy --- tests/SwarmTest.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/SwarmTest.py b/tests/SwarmTest.py index 345f0a66..2d137291 100644 --- a/tests/SwarmTest.py +++ b/tests/SwarmTest.py @@ -94,8 +94,18 @@ class SwarmTest(Test) : i = 0 healthy = False while i < self._timeout : - proc = run('docker stack ps --no-trunc --format "{{ .CurrentState }}" ' + self._name + ' | grep -v "Running"', cwd="/tmp/swarm", shell=True, capture_output=True) - if "" == proc.stdout.decode() : + proc = run('docker stack services --format "{{ .Name }}" ' + self._name, cwd="/tmp/swarm", shell=True, capture_output=True) + if proc.returncode != 0 : + raise(Exception("swarm stack is not healthy (cmd1 failed)")) + all_healthy = True + for service in proc.stdout.decode().splitlines() : + proc2 = run('docker service ps --format "{{ .CurrentState }}" ' + service, cwd="/tmp/swarm", shell=True, capture_output=True) + if proc2.returncode != 0 : + raise(Exception("swarm stack is not healthy (cmd2 failed)")) + if not "Running" in proc2.stdout.decode() : + all_healthy = False + break + if all_healthy : healthy = True break sleep(1)