This repository was archived by the owner on May 1, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathhelper.py
More file actions
54 lines (47 loc) · 1.44 KB
/
helper.py
File metadata and controls
54 lines (47 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import time
import requests
try:
import docker
except:
RuntimeError("Please run 'pip install docker' before using this module.")
class Helper(object):
def __init__(self, start=True, tb_ip=6006, server_ip=6007, name="crayon"):
self.client = docker.from_env()
self.tb_ip = tb_ip
self.server_ip = server_ip
self.name = name
if start:
self.start()
def start(self):
self.container = self.client.containers.run(
"alband/crayon:latest",
ports={6006: self.tb_ip,
6007: self.server_ip},
detach=True,
name=self.name)
# check server is working
running = False
retry = 50
while not running:
try:
assert(
requests.get("http://localhost:" + str(self.server_ip)).ok
)
running = True
except:
retry -= 1
if retry == 0:
# The test will trigger the not running server error
return
time.sleep(0.1)
def kill(self):
if hasattr(self, "container"):
self.container.kill()
def remove(self):
if hasattr(self, "container"):
self.container.remove()
self.container = None
def kill_remove(self):
# Could do with remove -f too
self.kill()
self.remove()