Skip to content
This repository was archived by the owner on Jul 17, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docker-stress
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def main():
except KeyboardInterrupt:
pass
finally:
print "Terminating workers and cleaning up..."
print "Terminating workers and cleaning up...(in background)"
kill_workers()
destroy_containers(client, nametag)

Expand Down
5 changes: 1 addition & 4 deletions jobs.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
[
{"image": "ubuntu:12.04", "command": ["sh", "-c", "apt-get update; while :; do sleep 1; done"]},
{"image": "ubuntu:12.04", "command": ["sh", "-c", "apt-get install nmap -qq --force-yes && while :; do ncat -e /bin/cat -k -l 4711; done"], "ports": [4711]},
{"image": "linux/postgres", "command": [], "ports": [5432]},
{"image": "tutum/wordpress", "command": [], "ports": [80, 3306]},
{"image": "dockerfile/nginx", "command": [], "ports": [80]},
{"image": "skxskx/memcached", "command": [], "ports": [11211]},
{"image": "dockerfile/redis", "command": [], "ports": [6379]},
{"image": "johannesh/bind10", "command": [], "ports": [53]},
{"image": "dockerfiles/django-uwsgi-nginx", "command": [], "ports": [80]},
{"image": "jacksoncage/varnish", "command": [], "ports": [80]},
{"image": "sameersbn/redmine", "command": [], "ports": [80]}
{"image": "isnog00d/rubydummyapp", "command": ["sh", "-c", "ruby /dummyapp/hw.rb"], "ports": [860]}
]
13 changes: 11 additions & 2 deletions spotify/docker_stress/docker_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,20 @@ def destroy(self, container_id):
log.debug('destroy %s', container_id)
self.cli_check('rm', container_id)

def list_containers(self, needle=''):
def list_containers(self, needle='', _all=False):
if not needle:
return self.cli_check('ps', '-q').splitlines()
else:
lines = self.cli_check('ps').splitlines()[1:]
if _all:
lines = self.cli_check('ps', '-a').splitlines()[1:]
else:
lines = self.cli_check('ps').splitlines()[1:]
matches = [word for line in lines for word in line.split() if needle in word]
log.debug('list_containers: needle=%s, matches=%s', needle, matches)
return matches

def list_all_exited(self, needle):
lines = self.cli_check('ps', '-a').splitlines()[1:]
lines = [line for line in lines if 'Exited' in line]
matches = [word for line in lines for word in line.split() if needle in word]
return matches
21 changes: 17 additions & 4 deletions spotify/docker_stress/docker_util.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import logging
from socket import create_connection
from time import sleep
from time import time, sleep
from urlparse import urlparse

from docker_client import DockerClientError
Expand Down Expand Up @@ -49,22 +50,34 @@ def connectable(client, container_id, hostname, ports):


def destroy_containers(client, nametag):
while True:
timeout = time() + 60 * 60
try:
if os.fork():
return
except OSError, e:
log.debug('failed to fork: %s', e)
return

while time() < timeout:
sleep(1)
containers = client.list_containers(needle=nametag)
containers = client.list_containers(needle=nametag, _all=True)
if not containers:
break
containers = client.list_containers(needle=nametag)
for container in containers:
try:
client.kill(container)
except Exception, e:
log.debug('kill failed: %s', e)
containers = client.list_all_exited(needle=nametag)
for container in containers:
try:
client.destroy(container)
except Exception, e:
log.debug('destroy failed: %s', e)

sleep(99)
if time() > timeout:
log.debug('Reached timeout for container destroy')

def endpoint_address(endpoint):
if '://' not in endpoint:
Expand Down