Skip to content

Commit 4abda55

Browse files
chore: be sure that connectivity is restored in test_in_poor
Ticket: QA-1625 Signed-off-by: Peter Grzybowski <peter@northern.tech>
1 parent 123b1e7 commit 4abda55

2 files changed

Lines changed: 50 additions & 2 deletions

File tree

tests/tests/test_enterprise_mender_connect.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ def test_bogus_shell_message(self, docker_env):
189189
assert prot.typ == "bogusmessage"
190190

191191
@pytest.mark.order(-1)
192+
@flaky(max_runs=3)
192193
def test_in_poor_network_environment(self, docker_env):
193194
self.assert_env(docker_env)
194195

@@ -223,7 +224,7 @@ def detect_shell_prompt(shell):
223224
is_shell_working(shell)
224225

225226
docker_env.device.run("apt-get update")
226-
docker_env.device.run("apt-get install -y iptables")
227+
docker_env.device.run("apt-get install -y iptables curl")
227228
docker_env.device.run(
228229
"iptables -A OUTPUT -j DROP --destination docker.mender.io"
229230
)
@@ -237,6 +238,29 @@ def detect_shell_prompt(shell):
237238

238239
# Re-enable a good connection
239240
docker_env.device.run("iptables -D OUTPUT 1")
241+
docker_env.device.run("iptables -F OUTPUT")
242+
docker_env._docker_compose_cmd("exec mender-client iptables -F OUTPUT")
243+
connectivity_reestablished = False
244+
sleep_time_s = 8
245+
iteration = 0
246+
max_iteration = 64
247+
while not connectivity_reestablished:
248+
rc = docker_env._docker_compose_cmd(
249+
'exec mender-client curl -s -o /dev/null -w "%{http_code}" -k --connect-timeout 240 --keepalive-time 30 --max-time 300 --retry-delay 8 https://docker.mender.io'
250+
)
251+
if rc.startswith("20"):
252+
connectivity_reestablished = True
253+
break
254+
if rc.startswith("30"):
255+
connectivity_reestablished = True
256+
break
257+
time.sleep(sleep_time_s)
258+
iteration = iteration + 1
259+
if iteration > max_iteration:
260+
break
261+
assert (
262+
connectivity_reestablished
263+
), "connectivity was not reestablished; this is a test env failure"
240264
time.sleep(128)
241265

242266
# mender-connect should have "healed" now and be able to start a new shell

tests/tests/test_opensource_mender_connect.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ def test_bogus_shell_message(self, docker_env):
189189
assert prot.typ == "bogusmessage"
190190

191191
@pytest.mark.order(0)
192+
@flaky(max_runs=3)
192193
def test_in_poor_network_environment(self, docker_env):
193194
self.assert_env(docker_env)
194195

@@ -223,7 +224,7 @@ def detect_shell_prompt(shell):
223224
is_shell_working(shell)
224225

225226
docker_env.device.run("apt-get update")
226-
docker_env.device.run("apt-get install -y iptables")
227+
docker_env.device.run("apt-get install -y iptables curl")
227228
docker_env.device.run(
228229
"iptables -A OUTPUT -j DROP --destination docker.mender.io"
229230
)
@@ -237,6 +238,29 @@ def detect_shell_prompt(shell):
237238

238239
# Re-enable a good connection
239240
docker_env.device.run("iptables -D OUTPUT 1")
241+
docker_env.device.run("iptables -F OUTPUT")
242+
docker_env._docker_compose_cmd("exec mender-client iptables -F OUTPUT")
243+
connectivity_reestablished = False
244+
sleep_time_s = 8
245+
iteration = 0
246+
max_iteration = 64
247+
while not connectivity_reestablished:
248+
rc = docker_env._docker_compose_cmd(
249+
'exec mender-client curl -s -o /dev/null -w "%{http_code}" -k --connect-timeout 240 --keepalive-time 30 --max-time 300 --retry-delay 8 https://docker.mender.io'
250+
)
251+
if rc.startswith("20"):
252+
connectivity_reestablished = True
253+
break
254+
if rc.startswith("30"):
255+
connectivity_reestablished = True
256+
break
257+
time.sleep(sleep_time_s)
258+
iteration = iteration + 1
259+
if iteration > max_iteration:
260+
break
261+
assert (
262+
connectivity_reestablished
263+
), "connectivity was not reestablished; this is a test env failure"
240264
time.sleep(128)
241265

242266
# mender-connect should have "healed" now and be able to start a new shell

0 commit comments

Comments
 (0)