Skip to content

Commit 6804542

Browse files
committed
Merge pull request #477 from cevich/fix_run_env
run_env: Improve reliability & messaging
2 parents 1e9cd57 + acf6946 commit 6804542

File tree

1 file changed

+23
-20
lines changed

1 file changed

+23
-20
lines changed

subtests/docker_cli/run_env/run_env.py

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,20 @@
3636
---------------
3737
3838
Docker daemon and host-networking setup to allow ICC between containers.
39+
If iptables is involved, and bridge-networking is in use, verify these
40+
sysctl's are set to ``1``:
41+
42+
* net.bridge.bridge-nf-call-arptables
43+
* net.bridge.bridge-nf-call-ip6tables
44+
* net.bridge.bridge-nf-call-iptables
3945
"""
4046
import ast
4147
import os.path
4248
import random
4349
import re
4450

4551
from autotest.client import utils
46-
from dockertest import config, xceptions
52+
from dockertest import config
4753
from dockertest import docker_daemon
4854
from dockertest.containers import DockerContainers
4955
from dockertest.dockercmd import DockerCmd
@@ -52,6 +58,7 @@
5258
from dockertest.config import get_as_list
5359
from dockertest.images import DockerImage
5460
from dockertest.subtest import SubSubtestCaller, SubSubtest
61+
from dockertest.output import wait_for_output
5562

5663

5764
class InteractiveAsyncDockerCmd(AsyncDockerCmd):
@@ -229,16 +236,9 @@ def cleanup(self):
229236
super(run_env_base, self).cleanup()
230237
if not self.config['remove_after_test']:
231238
return
232-
for name in self.sub_stuff['containers']:
233-
conts = self.sub_stuff['dc'].list_containers_with_name(name)
234-
if conts == []:
235-
self.logdebug("Container %s was already removed",
236-
name)
237-
continue # Docker was already removed
238-
elif len(conts) > 1:
239-
msg = ("Multiple containers match name '%s', not removing any"
240-
" of them...", name)
241-
raise xceptions.DockerTestError(msg)
239+
for name in self.sub_stuff.get('containers', []):
240+
self.logdebug("Killing %s", name)
241+
DockerCmd(self, 'kill', [name]).execute()
242242
self.logdebug("Removing %s", name)
243243
DockerCmd(self, 'rm', ['--force', '--volumes', name],
244244
verbose=False).execute()
@@ -290,15 +290,10 @@ def remove_link(self, client_name, alias):
290290

291291
def wait_for(self, dkrcmd, what, fail_msg, negative=False, stderr=False):
292292
if stderr:
293-
func = lambda: dkrcmd.stderr.find(what) > -1
294-
else:
295-
func = lambda: dkrcmd.stdout.find(what) > -1
296-
result = utils.wait_for(func,
297-
self.config['docker_timeout'], step=0.1)
298-
if negative is False: # for clarity
299-
self.failif(result is None, fail_msg)
293+
func = lambda: dkrcmd.stderr
300294
else:
301-
self.failif(result > -1, fail_msg) # negative test!
295+
func = lambda: dkrcmd.stdout
296+
self.failif(negative == wait_for_output(func, what), fail_msg)
302297

303298

304299
class port(port_base):
@@ -319,20 +314,24 @@ def run_once(self):
319314
# Server needs to be listening before client tries to connect
320315
servercmd = self.start_server()
321316
# Container running properly when python prompt appears
317+
self.logdebug("Waiting for server's python prompt")
322318
self.wait_for(servercmd,
323319
'>>> ',
324320
"No python prompt from server\n%s" % servercmd,
325321
stderr=True)
326322
servercmd.stdin = str(self.python_server % params) # str() for clarity
327323
# Executed python prints this on stdout
324+
self.logdebug("Waiting for server to start listening")
328325
self.wait_for(servercmd, 'Server Listening', "Server not listening")
329326
clientcmd = self.start_client()
327+
self.logdebug("Waiting for client's python prompt")
330328
self.wait_for(clientcmd,
331329
'>>> ',
332330
"No python prompt from client\n%s" % clientcmd,
333331
stderr=True)
334332
clientcmd.stdin = str(self.python_client % params)
335333
# Executed python includes printing this on stdout
334+
self.logdebug("Waiting for client to connect")
336335
self.wait_for(clientcmd,
337336
"Client Connecting",
338337
"No client connect\n%s" % clientcmd)
@@ -413,29 +412,33 @@ def run_once(self):
413412
# Server needs to be listening before client tries to connect
414413
servercmd = self.start_server()
415414
# Container running properly when python prompt appears
415+
self.logdebug("Waiting for server's python prompt")
416416
self.wait_for(servercmd,
417417
'>>> ',
418418
"No python prompt from server\n%s" % servercmd,
419419
stderr=True)
420420
self.logdebug("Executing server code...")
421421
servercmd.stdin = str(self.python_server % params) # str() for clarity
422+
self.logdebug("Waiting for server to start listening")
422423
self.wait_for(servercmd, "Server Listening",
423424
"No 'Server Listenting' found in stdout")
424425
clientcmd = self.start_client()
426+
self.logdebug("Waiting for client's python prompt")
425427
self.wait_for(clientcmd,
426428
'>>> ',
427429
"No python prompt from client\n%s" % clientcmd,
428430
stderr=True)
429431

432+
# To help troubleshoot iptables related problems
430433
self.record_iptables('before_rmlink')
431434

432435
self.remove_link(self.sub_stuff['client_name'], 'server')
433436

434437
self.record_iptables('after_rmlink')
435438

436-
self.logdebug("Executing client code...")
437439
clientcmd.stdin = str(self.python_client % params)
438440
# Executed python includes printing this on stdout
441+
self.logdebug("Waiting for client to connect")
439442
self.wait_for(clientcmd,
440443
"Client Connecting",
441444
"No client connect\n%s" % clientcmd)

0 commit comments

Comments
 (0)