autotest/autotest-docker — pull request #77 by ldoktor (2014-04-18 08:49:41+00:00)
Title: RFC: Event handler

This is a RFC for event_handler class, which should help with timing
issues of docker. It parses /var/log/messages and allows you to wait
for given docker events, eg. "docker run" sequence.

You have to keep in mind, that by parsing events you don't directly interact with the container, thus you can't know, whether inside commands already finished.

Anyway, the beginnings, timings of the "run" and "attach" commands:

Without
09:39:28 INFO | 1.8835067749e-05
09:39:28 INFO | 3.00407409668e-05

With
09:57:34 INFO | 0.324712991714
09:57:34 INFO | 0.0300760269165

With + stress --timeout 240s -c 4 -m 1 -i 1 -d 1 in background:
10:37:04 INFO | 13.4338970184

you can see it waits until the container is really initialized. Anyway it doesn't wait for the inside command to be executed, as the modified `docker_cli/top` test demonstrates:

Without:
10:23:28 INFO | Exit status: -15
10:23:28 ERROR| Duration: 0.0262169837952

With:
10:23:59 INFO | Exit status: 255
10:23:59 INFO | Duration: 0.474253892899

With + sleep 0.1:
10:25:40 INFO | Exit status: 9
10:25:40 INFO | Duration: 4.45453619957

With + sleep 1 + stress --timeout 240s -c 4 -m 1 -i 1 -d 1:
10:37:09 INFO | Exit status: 9
10:37:09 INFO | Duration: 18.4349918365

You can see that without events it's very hard to set the timeouts correctly. With it it might be a bit easier, but still you'd need to add small wait for the command initialization. Anyway it should be guaranteed, that the container exists.

When you rely on the in-container-command, you should put "echo SOMETHING_UNIQUE" after the initialization and `utils.wait_for()` it. Then you have 100% guarantee it was executed. I'm considering some utils about this including the output starting from last_viewed or the whole history.

Regards,
Lukáš