mirror of https://github.com/docker/docker-py.git
Refactor timeout passing and standardize with keyword parameters
Standardize all HTTP request calls to use keyword parameters for all but the URL. This makes the refactoring of including the timeout in these requests' parameters easier and more uniform-looking. Tweaks to the tests to comply with this new parameter passing scheme, in particular to the API calls assertions. Signed-off-by: Maxime Petazzoni <max@signalfuse.com>
This commit is contained in:
parent
a451119e4a
commit
cc3c455629
114
docker/client.py
114
docker/client.py
|
|
@ -78,6 +78,21 @@ class Client(requests.Session):
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def _set_request_timeout(self, kwargs):
|
||||||
|
"""Prepare the kwargs for an HTTP request by inserting the timeout
|
||||||
|
parameter, if not already present."""
|
||||||
|
kwargs.setdefault('timeout', self._timeout)
|
||||||
|
return kwargs
|
||||||
|
|
||||||
|
def _post(self, url, **kwargs):
|
||||||
|
return self.post(url, **self._set_request_timeout(kwargs))
|
||||||
|
|
||||||
|
def _get(self, url, **kwargs):
|
||||||
|
return self.get(url, **self._set_request_timeout(kwargs))
|
||||||
|
|
||||||
|
def _delete(self, url, **kwargs):
|
||||||
|
return self.delete(url, **self._set_request_timeout(kwargs))
|
||||||
|
|
||||||
def _url(self, path):
|
def _url(self, path):
|
||||||
return '{0}/v{1}{2}'.format(self.base_url, self._version, path)
|
return '{0}/v{1}{2}'.format(self.base_url, self._version, path)
|
||||||
|
|
||||||
|
|
@ -148,8 +163,7 @@ class Client(requests.Session):
|
||||||
if 'headers' not in kwargs:
|
if 'headers' not in kwargs:
|
||||||
kwargs['headers'] = {}
|
kwargs['headers'] = {}
|
||||||
kwargs['headers']['Content-Type'] = 'application/json'
|
kwargs['headers']['Content-Type'] = 'application/json'
|
||||||
return self.post(url, json.dumps(data2),
|
return self._post(url, data=json.dumps(data2), **kwargs)
|
||||||
timeout=self._timeout, **kwargs)
|
|
||||||
|
|
||||||
def attach_socket(self, container, params=None, ws=False):
|
def attach_socket(self, container, params=None, ws=False):
|
||||||
if ws:
|
if ws:
|
||||||
|
|
@ -158,8 +172,8 @@ class Client(requests.Session):
|
||||||
if isinstance(container, dict):
|
if isinstance(container, dict):
|
||||||
container = container.get('Id')
|
container = container.get('Id')
|
||||||
u = self._url("/containers/{0}/attach".format(container))
|
u = self._url("/containers/{0}/attach".format(container))
|
||||||
res = self.post(u, None, params=self._attach_params(params),
|
res = self._post(u, params=self._attach_params(params),
|
||||||
stream=True, timeout=self._timeout)
|
stream=True)
|
||||||
self._raise_for_status(res)
|
self._raise_for_status(res)
|
||||||
# hijack the underlying socket from requests, icky
|
# hijack the underlying socket from requests, icky
|
||||||
# but for some reason requests.iter_contents and ilk
|
# but for some reason requests.iter_contents and ilk
|
||||||
|
|
@ -220,9 +234,8 @@ class Client(requests.Session):
|
||||||
}
|
}
|
||||||
if context is not None:
|
if context is not None:
|
||||||
headers = {'Content-Type': 'application/tar'}
|
headers = {'Content-Type': 'application/tar'}
|
||||||
res = self._result(self.post(u, context, params=params,
|
res = self._result(self._post(u, data=context, params=params,
|
||||||
headers=headers, stream=True,
|
headers=headers, stream=True))
|
||||||
timeout=self._timeout))
|
|
||||||
if context is not None:
|
if context is not None:
|
||||||
context.close()
|
context.close()
|
||||||
srch = r'Successfully built ([0-9a-f]+)'
|
srch = r'Successfully built ([0-9a-f]+)'
|
||||||
|
|
@ -241,7 +254,7 @@ class Client(requests.Session):
|
||||||
'author': author
|
'author': author
|
||||||
}
|
}
|
||||||
u = self._url("/commit")
|
u = self._url("/commit")
|
||||||
return self._result(self._post_json(u, conf, params=params), json=True)
|
return self._result(self._post_json(u, data=conf, params=params), json=True)
|
||||||
|
|
||||||
def containers(self, quiet=False, all=False, trunc=True, latest=False,
|
def containers(self, quiet=False, all=False, trunc=True, latest=False,
|
||||||
since=None, before=None, limit=-1):
|
since=None, before=None, limit=-1):
|
||||||
|
|
@ -253,8 +266,7 @@ class Client(requests.Session):
|
||||||
'before': before
|
'before': before
|
||||||
}
|
}
|
||||||
u = self._url("/containers/ps")
|
u = self._url("/containers/ps")
|
||||||
res = self._result(self.get(u, params=params, timeout=self._timeout),
|
res = self._result(self._get(u, params=params), True)
|
||||||
True)
|
|
||||||
if quiet:
|
if quiet:
|
||||||
return [{'Id': x['Id']} for x in res]
|
return [{'Id': x['Id']} for x in res]
|
||||||
return res
|
return res
|
||||||
|
|
@ -262,7 +274,7 @@ class Client(requests.Session):
|
||||||
def copy(self, container, resource):
|
def copy(self, container, resource):
|
||||||
res = self._post_json(
|
res = self._post_json(
|
||||||
self._url("/containers/{0}/copy".format(container)),
|
self._url("/containers/{0}/copy".format(container)),
|
||||||
{"Resource": resource},
|
data={"Resource": resource},
|
||||||
stream=True
|
stream=True
|
||||||
)
|
)
|
||||||
self._raise_for_status(res)
|
self._raise_for_status(res)
|
||||||
|
|
@ -285,40 +297,37 @@ class Client(requests.Session):
|
||||||
params = {
|
params = {
|
||||||
'name': name
|
'name': name
|
||||||
}
|
}
|
||||||
res = self._post_json(u, config, params=params)
|
res = self._post_json(u, data=config, params=params)
|
||||||
return self._result(res, True)
|
return self._result(res, True)
|
||||||
|
|
||||||
def diff(self, container):
|
def diff(self, container):
|
||||||
if isinstance(container, dict):
|
if isinstance(container, dict):
|
||||||
container = container.get('Id')
|
container = container.get('Id')
|
||||||
return self._result(self.get(self._url("/containers/{0}/changes".
|
return self._result(self._get(self._url("/containers/{0}/changes".
|
||||||
format(container)), timeout=self._timeout), True)
|
format(container))), True)
|
||||||
|
|
||||||
def export(self, container):
|
def export(self, container):
|
||||||
if isinstance(container, dict):
|
if isinstance(container, dict):
|
||||||
container = container.get('Id')
|
container = container.get('Id')
|
||||||
res = self.get(self._url("/containers/{0}/export".format(container)),
|
res = self._get(self._url("/containers/{0}/export".format(container)),
|
||||||
stream=True, timeout=self._timeout)
|
stream=True)
|
||||||
self._raise_for_status(res)
|
self._raise_for_status(res)
|
||||||
return res.raw
|
return res.raw
|
||||||
|
|
||||||
def history(self, image):
|
def history(self, image):
|
||||||
res = self.get(self._url("/images/{0}/history".format(image)),
|
res = self._get(self._url("/images/{0}/history".format(image)))
|
||||||
timeout=self._timeout)
|
|
||||||
self._raise_for_status(res)
|
self._raise_for_status(res)
|
||||||
return self._result(res)
|
return self._result(res)
|
||||||
|
|
||||||
def images(self, name=None, quiet=False, all=False, viz=False):
|
def images(self, name=None, quiet=False, all=False, viz=False):
|
||||||
if viz:
|
if viz:
|
||||||
return self._result(self.get(self._url("images/viz"),
|
return self._result(self._get(self._url("images/viz")))
|
||||||
timeout=self._timeout))
|
|
||||||
params = {
|
params = {
|
||||||
'filter': name,
|
'filter': name,
|
||||||
'only_ids': 1 if quiet else 0,
|
'only_ids': 1 if quiet else 0,
|
||||||
'all': 1 if all else 0,
|
'all': 1 if all else 0,
|
||||||
}
|
}
|
||||||
res = self._result(self.get(self._url("/images/json"), params=params,
|
res = self._result(self._get(self._url("/images/json"), params=params),
|
||||||
timeout=self._timeout),
|
|
||||||
True)
|
True)
|
||||||
if quiet:
|
if quiet:
|
||||||
return [x['Id'] for x in res]
|
return [x['Id'] for x in res]
|
||||||
|
|
@ -342,15 +351,12 @@ class Client(requests.Session):
|
||||||
data = None
|
data = None
|
||||||
if isinstance(src, six.string_types):
|
if isinstance(src, six.string_types):
|
||||||
params['fromSrc'] = src
|
params['fromSrc'] = src
|
||||||
return self._result(self.post(u, data, params=params,
|
return self._result(self._post(u, data=data, params=params))
|
||||||
timeout=self._timeout))
|
|
||||||
|
|
||||||
return self._result(self.post(u, src, params=params,
|
return self._result(self._post(u, data=src, params=params))
|
||||||
timeout=self._timeout))
|
|
||||||
|
|
||||||
def info(self):
|
def info(self):
|
||||||
return self._result(self.get(self._url("/info"),
|
return self._result(self._get(self._url("/info")),
|
||||||
timeout=self._timeout),
|
|
||||||
True)
|
True)
|
||||||
|
|
||||||
def insert(self, image, url, path):
|
def insert(self, image, url, path):
|
||||||
|
|
@ -359,26 +365,23 @@ class Client(requests.Session):
|
||||||
'url': url,
|
'url': url,
|
||||||
'path': path
|
'path': path
|
||||||
}
|
}
|
||||||
return self._result(self.post(api_url, None, params=params,
|
return self._result(self._post(api_url, params=params))
|
||||||
timeout=self._timeout))
|
|
||||||
|
|
||||||
def inspect_container(self, container):
|
def inspect_container(self, container):
|
||||||
if isinstance(container, dict):
|
if isinstance(container, dict):
|
||||||
container = container.get('Id')
|
container = container.get('Id')
|
||||||
return self._result(self.get(self._url("/containers/{0}/json".format(container)),
|
return self._result(self._get(self._url("/containers/{0}/json".format(container))),
|
||||||
timeout=self._timeout),
|
|
||||||
True)
|
True)
|
||||||
|
|
||||||
def inspect_image(self, image_id):
|
def inspect_image(self, image_id):
|
||||||
return self._result(self.get(self._url("/images/{0}/json".format(image_id)),
|
return self._result(self._get(self._url("/images/{0}/json".format(image_id))),
|
||||||
timeout=self._timeout),
|
|
||||||
True)
|
True)
|
||||||
|
|
||||||
def kill(self, container):
|
def kill(self, container):
|
||||||
if isinstance(container, dict):
|
if isinstance(container, dict):
|
||||||
container = container.get('Id')
|
container = container.get('Id')
|
||||||
url = self._url("/containers/{0}/kill".format(container))
|
url = self._url("/containers/{0}/kill".format(container))
|
||||||
res = self.post(url, None, timeout=self._timeout)
|
res = self._post(url)
|
||||||
self._raise_for_status(res)
|
self._raise_for_status(res)
|
||||||
|
|
||||||
def login(self, username, password=None, email=None, registry=None):
|
def login(self, username, password=None, email=None, registry=None):
|
||||||
|
|
@ -395,7 +398,7 @@ class Client(requests.Session):
|
||||||
'password': password,
|
'password': password,
|
||||||
'email': email
|
'email': email
|
||||||
}
|
}
|
||||||
res = self._result(self._post_json(url, req_data), True)
|
res = self._result(self._post_json(url, data=req_data), True)
|
||||||
if res['Status'] == 'Login Succeeded':
|
if res['Status'] == 'Login Succeeded':
|
||||||
self._cfg['Configs'][registry] = req_data
|
self._cfg['Configs'][registry] = req_data
|
||||||
return res
|
return res
|
||||||
|
|
@ -409,14 +412,12 @@ class Client(requests.Session):
|
||||||
'stderr': 1
|
'stderr': 1
|
||||||
}
|
}
|
||||||
u = self._url("/containers/{0}/attach".format(container))
|
u = self._url("/containers/{0}/attach".format(container))
|
||||||
return self._result(self.post(u, None, params=params,
|
return self._result(self._post(u, params=params))
|
||||||
timeout=self._timeout))
|
|
||||||
|
|
||||||
def port(self, container, private_port):
|
def port(self, container, private_port):
|
||||||
if isinstance(container, dict):
|
if isinstance(container, dict):
|
||||||
container = container.get('Id')
|
container = container.get('Id')
|
||||||
res = self.get(self._url("/containers/{0}/json".format(container)),
|
res = self._get(self._url("/containers/{0}/json".format(container)))
|
||||||
timeout=self._timeout)
|
|
||||||
self._raise_for_status(res)
|
self._raise_for_status(res)
|
||||||
json_ = res.json()
|
json_ = res.json()
|
||||||
s_port = str(private_port)
|
s_port = str(private_port)
|
||||||
|
|
@ -448,8 +449,7 @@ class Client(requests.Session):
|
||||||
if authcfg:
|
if authcfg:
|
||||||
headers['X-Registry-Auth'] = auth.encode_header(authcfg)
|
headers['X-Registry-Auth'] = auth.encode_header(authcfg)
|
||||||
u = self._url("/images/create")
|
u = self._url("/images/create")
|
||||||
return self._result(self.post(u, params=params, headers=headers,
|
return self._result(self._post(u, params=params, headers=headers))
|
||||||
timeout=self._timeout))
|
|
||||||
|
|
||||||
def push(self, repository):
|
def push(self, repository):
|
||||||
registry, repo_name = auth.resolve_repository_name(repository)
|
registry, repo_name = auth.resolve_repository_name(repository)
|
||||||
|
|
@ -463,19 +463,18 @@ class Client(requests.Session):
|
||||||
# for this specific registry as we can have an anon push
|
# for this specific registry as we can have an anon push
|
||||||
if authcfg:
|
if authcfg:
|
||||||
headers['X-Registry-Auth'] = auth.encode_header(authcfg)
|
headers['X-Registry-Auth'] = auth.encode_header(authcfg)
|
||||||
return self._result(self._post_json(u, None, headers=headers))
|
return self._result(self._post_json(u, headers=headers))
|
||||||
return self._result(self._post_json(u, authcfg))
|
return self._result(self._post_json(u, data=authcfg))
|
||||||
|
|
||||||
def remove_container(self, container, v=False):
|
def remove_container(self, container, v=False):
|
||||||
if isinstance(container, dict):
|
if isinstance(container, dict):
|
||||||
container = container.get('Id')
|
container = container.get('Id')
|
||||||
params = {'v': v}
|
params = {'v': v}
|
||||||
res = self.delete(self._url("/containers/" + container), params=params,
|
res = self._delete(self._url("/containers/" + container), params=params)
|
||||||
timeout=self._timeout)
|
|
||||||
self._raise_for_status(res)
|
self._raise_for_status(res)
|
||||||
|
|
||||||
def remove_image(self, image):
|
def remove_image(self, image):
|
||||||
res = self.delete(self._url("/images/" + image), timeout=self._timeout)
|
res = self._delete(self._url("/images/" + image))
|
||||||
self._raise_for_status(res)
|
self._raise_for_status(res)
|
||||||
|
|
||||||
def restart(self, container, timeout=10):
|
def restart(self, container, timeout=10):
|
||||||
|
|
@ -483,13 +482,12 @@ class Client(requests.Session):
|
||||||
container = container.get('Id')
|
container = container.get('Id')
|
||||||
params = {'t': timeout}
|
params = {'t': timeout}
|
||||||
url = self._url("/containers/{0}/restart".format(container))
|
url = self._url("/containers/{0}/restart".format(container))
|
||||||
res = self.post(url, None, params=params, timeout=self._timeout)
|
res = self._post(url, params=params)
|
||||||
self._raise_for_status(res)
|
self._raise_for_status(res)
|
||||||
|
|
||||||
def search(self, term):
|
def search(self, term):
|
||||||
return self._result(self.get(self._url("/images/search"),
|
return self._result(self._get(self._url("/images/search"),
|
||||||
params={'term': term},
|
params={'term': term}),
|
||||||
timeout=self._timeout),
|
|
||||||
True)
|
True)
|
||||||
|
|
||||||
def start(self, container, binds=None, port_bindings=None, lxc_conf=None):
|
def start(self, container, binds=None, port_bindings=None, lxc_conf=None):
|
||||||
|
|
@ -515,7 +513,7 @@ class Client(requests.Session):
|
||||||
start_config['PortBindings'] = port_bindings
|
start_config['PortBindings'] = port_bindings
|
||||||
|
|
||||||
url = self._url("/containers/{0}/start".format(container))
|
url = self._url("/containers/{0}/start".format(container))
|
||||||
res = self._post_json(url, start_config)
|
res = self._post_json(url, data=start_config)
|
||||||
self._raise_for_status(res)
|
self._raise_for_status(res)
|
||||||
|
|
||||||
def stop(self, container, timeout=10):
|
def stop(self, container, timeout=10):
|
||||||
|
|
@ -523,7 +521,7 @@ class Client(requests.Session):
|
||||||
container = container.get('Id')
|
container = container.get('Id')
|
||||||
params = {'t': timeout}
|
params = {'t': timeout}
|
||||||
url = self._url("/containers/{0}/stop".format(container))
|
url = self._url("/containers/{0}/stop".format(container))
|
||||||
res = self.post(url, None, params=params, timeout=self._timeout)
|
res = self._post(url, params=params)
|
||||||
self._raise_for_status(res)
|
self._raise_for_status(res)
|
||||||
|
|
||||||
def tag(self, image, repository, tag=None, force=False):
|
def tag(self, image, repository, tag=None, force=False):
|
||||||
|
|
@ -533,24 +531,22 @@ class Client(requests.Session):
|
||||||
'force': 1 if force else 0
|
'force': 1 if force else 0
|
||||||
}
|
}
|
||||||
url = self._url("/images/{0}/tag".format(image))
|
url = self._url("/images/{0}/tag".format(image))
|
||||||
res = self.post(url, None, params=params, timeout=self._timeout)
|
res = self._post(url, params=params)
|
||||||
self._raise_for_status(res)
|
self._raise_for_status(res)
|
||||||
return res.status_code == 201
|
return res.status_code == 201
|
||||||
|
|
||||||
def top(self, container):
|
def top(self, container):
|
||||||
u = self._url("/containers/{0}/top".format(container))
|
u = self._url("/containers/{0}/top".format(container))
|
||||||
return self._result(self.get(u, timeout=self._timeout), True)
|
return self._result(self._get(u), True)
|
||||||
|
|
||||||
def version(self):
|
def version(self):
|
||||||
return self._result(self.get(self._url("/version"),
|
return self._result(self._get(self._url("/version")), True)
|
||||||
timeout=self._timeout),
|
|
||||||
True)
|
|
||||||
|
|
||||||
def wait(self, container):
|
def wait(self, container):
|
||||||
if isinstance(container, dict):
|
if isinstance(container, dict):
|
||||||
container = container.get('Id')
|
container = container.get('Id')
|
||||||
url = self._url("/containers/{0}/wait".format(container))
|
url = self._url("/containers/{0}/wait".format(container))
|
||||||
res = self.post(url, None, timeout=None)
|
res = self._post(url, timeout=None)
|
||||||
self._raise_for_status(res)
|
self._raise_for_status(res)
|
||||||
json_ = res.json()
|
json_ = res.json()
|
||||||
if 'StatusCode' in json_:
|
if 'StatusCode' in json_:
|
||||||
|
|
|
||||||
|
|
@ -156,16 +156,16 @@ class DockerClientTest(unittest.TestCase):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.fail('Command should not raise exception: {0}'.format(e))
|
self.fail('Command should not raise exception: {0}'.format(e))
|
||||||
|
|
||||||
args = fake_request.call_args
|
args, kwargs = fake_request.call_args
|
||||||
self.assertEqual(args[0][0],
|
self.assertEqual(args[0],
|
||||||
'unix://var/run/docker.sock/v1.4/containers/create')
|
'unix://var/run/docker.sock/v1.4/containers/create')
|
||||||
self.assertEqual(json.loads(args[0][1]),
|
self.assertEqual(json.loads(kwargs['data']),
|
||||||
json.loads('''
|
json.loads('''
|
||||||
{"Tty": false, "Image": "busybox", "Cmd": ["true"],
|
{"Tty": false, "Image": "busybox", "Cmd": ["true"],
|
||||||
"AttachStdin": false, "Memory": 0,
|
"AttachStdin": false, "Memory": 0,
|
||||||
"AttachStderr": true, "Privileged": false,
|
"AttachStderr": true, "Privileged": false,
|
||||||
"AttachStdout": true, "OpenStdin": false}'''))
|
"AttachStdout": true, "OpenStdin": false}'''))
|
||||||
self.assertEqual(args[1]['headers'],
|
self.assertEqual(kwargs['headers'],
|
||||||
{'Content-Type': 'application/json'})
|
{'Content-Type': 'application/json'})
|
||||||
|
|
||||||
def test_create_container_with_binds(self):
|
def test_create_container_with_binds(self):
|
||||||
|
|
@ -178,17 +178,17 @@ class DockerClientTest(unittest.TestCase):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.fail('Command should not raise exception: {0}'.format(e))
|
self.fail('Command should not raise exception: {0}'.format(e))
|
||||||
|
|
||||||
args = fake_request.call_args
|
args, kwargs = fake_request.call_args
|
||||||
self.assertEqual(args[0][0],
|
self.assertEqual(args[0],
|
||||||
'unix://var/run/docker.sock/v1.4/containers/create')
|
'unix://var/run/docker.sock/v1.4/containers/create')
|
||||||
self.assertEqual(json.loads(args[0][1]),
|
self.assertEqual(json.loads(kwargs['data']),
|
||||||
json.loads('''
|
json.loads('''
|
||||||
{"Tty": false, "Image": "busybox",
|
{"Tty": false, "Image": "busybox",
|
||||||
"Cmd": ["ls", "/mnt"], "AttachStdin": false,
|
"Cmd": ["ls", "/mnt"], "AttachStdin": false,
|
||||||
"Volumes": {"/mnt": {}}, "Memory": 0,
|
"Volumes": {"/mnt": {}}, "Memory": 0,
|
||||||
"AttachStderr": true, "Privileged": false,
|
"AttachStderr": true, "Privileged": false,
|
||||||
"AttachStdout": true, "OpenStdin": false}'''))
|
"AttachStdout": true, "OpenStdin": false}'''))
|
||||||
self.assertEqual(args[1]['headers'],
|
self.assertEqual(kwargs['headers'],
|
||||||
{'Content-Type': 'application/json'})
|
{'Content-Type': 'application/json'})
|
||||||
|
|
||||||
def test_create_container_privileged(self):
|
def test_create_container_privileged(self):
|
||||||
|
|
@ -197,16 +197,16 @@ class DockerClientTest(unittest.TestCase):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.fail('Command should not raise exception: {0}'.format(e))
|
self.fail('Command should not raise exception: {0}'.format(e))
|
||||||
|
|
||||||
args = fake_request.call_args
|
args, kwargs = fake_request.call_args
|
||||||
self.assertEqual(args[0][0],
|
self.assertEqual(args[0],
|
||||||
'unix://var/run/docker.sock/v1.4/containers/create')
|
'unix://var/run/docker.sock/v1.4/containers/create')
|
||||||
self.assertEqual(json.loads(args[0][1]),
|
self.assertEqual(json.loads(kwargs['data']),
|
||||||
json.loads('''
|
json.loads('''
|
||||||
{"Tty": false, "Image": "busybox", "Cmd": ["true"],
|
{"Tty": false, "Image": "busybox", "Cmd": ["true"],
|
||||||
"AttachStdin": false, "Memory": 0,
|
"AttachStdin": false, "Memory": 0,
|
||||||
"AttachStderr": true, "Privileged": true,
|
"AttachStderr": true, "Privileged": true,
|
||||||
"AttachStdout": true, "OpenStdin": false}'''))
|
"AttachStdout": true, "OpenStdin": false}'''))
|
||||||
self.assertEqual(args[1]['headers'],
|
self.assertEqual(kwargs['headers'],
|
||||||
{'Content-Type': 'application/json'})
|
{'Content-Type': 'application/json'})
|
||||||
|
|
||||||
def test_create_named_container(self):
|
def test_create_named_container(self):
|
||||||
|
|
@ -216,18 +216,18 @@ class DockerClientTest(unittest.TestCase):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.fail('Command should not raise exception: {0}'.format(e))
|
self.fail('Command should not raise exception: {0}'.format(e))
|
||||||
|
|
||||||
args = fake_request.call_args
|
args, kwargs = fake_request.call_args
|
||||||
self.assertEqual(args[0][0],
|
self.assertEqual(args[0],
|
||||||
'unix://var/run/docker.sock/v1.4/containers/create')
|
'unix://var/run/docker.sock/v1.4/containers/create')
|
||||||
self.assertEqual(json.loads(args[0][1]),
|
self.assertEqual(json.loads(kwargs['data']),
|
||||||
json.loads('''
|
json.loads('''
|
||||||
{"Tty": false, "Image": "busybox", "Cmd": ["true"],
|
{"Tty": false, "Image": "busybox", "Cmd": ["true"],
|
||||||
"AttachStdin": false, "Memory": 0,
|
"AttachStdin": false, "Memory": 0,
|
||||||
"AttachStderr": true, "Privileged": false,
|
"AttachStderr": true, "Privileged": false,
|
||||||
"AttachStdout": true, "OpenStdin": false}'''))
|
"AttachStdout": true, "OpenStdin": false}'''))
|
||||||
self.assertEqual(args[1]['headers'],
|
self.assertEqual(kwargs['headers'],
|
||||||
{'Content-Type': 'application/json'})
|
{'Content-Type': 'application/json'})
|
||||||
self.assertEqual(args[1]['params'], {'name': 'marisa-kirisame'})
|
self.assertEqual(kwargs['params'], {'name': 'marisa-kirisame'})
|
||||||
|
|
||||||
def test_start_container(self):
|
def test_start_container(self):
|
||||||
try:
|
try:
|
||||||
|
|
@ -237,7 +237,7 @@ class DockerClientTest(unittest.TestCase):
|
||||||
|
|
||||||
fake_request.assert_called_with(
|
fake_request.assert_called_with(
|
||||||
'unix://var/run/docker.sock/v1.4/containers/3cc2351ab11b/start',
|
'unix://var/run/docker.sock/v1.4/containers/3cc2351ab11b/start',
|
||||||
'{}',
|
data='{}',
|
||||||
headers={'Content-Type': 'application/json'},
|
headers={'Content-Type': 'application/json'},
|
||||||
timeout=docker.client.DEFAULT_TIMEOUT_SECONDS
|
timeout=docker.client.DEFAULT_TIMEOUT_SECONDS
|
||||||
)
|
)
|
||||||
|
|
@ -250,14 +250,14 @@ class DockerClientTest(unittest.TestCase):
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.fail('Command should not raise exception: {0}'.format(e))
|
self.fail('Command should not raise exception: {0}'.format(e))
|
||||||
args = fake_request.call_args
|
args, kwargs = fake_request.call_args
|
||||||
self.assertEqual(args[0][0], 'unix://var/run/docker.sock/v1.4/'
|
self.assertEqual(args[0], 'unix://var/run/docker.sock/v1.4/'
|
||||||
'containers/3cc2351ab11b/start')
|
'containers/3cc2351ab11b/start')
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
json.loads(args[0][1]),
|
json.loads(kwargs['data']),
|
||||||
{"LxcConf": [{"Value": "lxc.conf.value", "Key": "lxc.conf.k"}]}
|
{"LxcConf": [{"Value": "lxc.conf.value", "Key": "lxc.conf.k"}]}
|
||||||
)
|
)
|
||||||
self.assertEqual(args[1]['headers'],
|
self.assertEqual(kwargs['headers'],
|
||||||
{'Content-Type': 'application/json'})
|
{'Content-Type': 'application/json'})
|
||||||
|
|
||||||
def test_start_container_with_lxc_conf_compat(self):
|
def test_start_container_with_lxc_conf_compat(self):
|
||||||
|
|
@ -268,14 +268,14 @@ class DockerClientTest(unittest.TestCase):
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.fail('Command should not raise exception: {0}'.format(e))
|
self.fail('Command should not raise exception: {0}'.format(e))
|
||||||
args = fake_request.call_args
|
args, kwargs = fake_request.call_args
|
||||||
self.assertEqual(args[0][0], 'unix://var/run/docker.sock/v1.4/'
|
self.assertEqual(args[0], 'unix://var/run/docker.sock/v1.4/'
|
||||||
'containers/3cc2351ab11b/start')
|
'containers/3cc2351ab11b/start')
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
json.loads(args[0][1]),
|
json.loads(kwargs['data']),
|
||||||
{"LxcConf": [{"Value": "lxc.conf.value", "Key": "lxc.conf.k"}]}
|
{"LxcConf": [{"Value": "lxc.conf.value", "Key": "lxc.conf.k"}]}
|
||||||
)
|
)
|
||||||
self.assertEqual(args[1]['headers'],
|
self.assertEqual(kwargs['headers'],
|
||||||
{'Content-Type': 'application/json'})
|
{'Content-Type': 'application/json'})
|
||||||
|
|
||||||
def test_start_container_with_binds(self):
|
def test_start_container_with_binds(self):
|
||||||
|
|
@ -289,7 +289,7 @@ class DockerClientTest(unittest.TestCase):
|
||||||
|
|
||||||
fake_request.assert_called_with(
|
fake_request.assert_called_with(
|
||||||
'unix://var/run/docker.sock/v1.4/containers/3cc2351ab11b/start',
|
'unix://var/run/docker.sock/v1.4/containers/3cc2351ab11b/start',
|
||||||
'{"Binds": ["/tmp:/mnt"]}',
|
data='{"Binds": ["/tmp:/mnt"]}',
|
||||||
headers={'Content-Type': 'application/json'},
|
headers={'Content-Type': 'application/json'},
|
||||||
timeout=docker.client.DEFAULT_TIMEOUT_SECONDS
|
timeout=docker.client.DEFAULT_TIMEOUT_SECONDS
|
||||||
)
|
)
|
||||||
|
|
@ -301,7 +301,8 @@ class DockerClientTest(unittest.TestCase):
|
||||||
self.fail('Command should not raise exception: {0}'.format(e))
|
self.fail('Command should not raise exception: {0}'.format(e))
|
||||||
fake_request.assert_called_with(
|
fake_request.assert_called_with(
|
||||||
'unix://var/run/docker.sock/v1.4/containers/3cc2351ab11b/start',
|
'unix://var/run/docker.sock/v1.4/containers/3cc2351ab11b/start',
|
||||||
'{}', headers={'Content-Type': 'application/json'},
|
data='{}',
|
||||||
|
headers={'Content-Type': 'application/json'},
|
||||||
timeout=docker.client.DEFAULT_TIMEOUT_SECONDS
|
timeout=docker.client.DEFAULT_TIMEOUT_SECONDS
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -313,7 +314,6 @@ class DockerClientTest(unittest.TestCase):
|
||||||
|
|
||||||
fake_request.assert_called_with(
|
fake_request.assert_called_with(
|
||||||
'unix://var/run/docker.sock/v1.4/containers/3cc2351ab11b/wait',
|
'unix://var/run/docker.sock/v1.4/containers/3cc2351ab11b/wait',
|
||||||
None,
|
|
||||||
timeout=None
|
timeout=None
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -325,7 +325,6 @@ class DockerClientTest(unittest.TestCase):
|
||||||
|
|
||||||
fake_request.assert_called_with(
|
fake_request.assert_called_with(
|
||||||
'unix://var/run/docker.sock/v1.4/containers/3cc2351ab11b/wait',
|
'unix://var/run/docker.sock/v1.4/containers/3cc2351ab11b/wait',
|
||||||
None,
|
|
||||||
timeout=None
|
timeout=None
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -337,7 +336,6 @@ class DockerClientTest(unittest.TestCase):
|
||||||
|
|
||||||
fake_request.assert_called_with(
|
fake_request.assert_called_with(
|
||||||
'unix://var/run/docker.sock/v1.4/containers/3cc2351ab11b/attach',
|
'unix://var/run/docker.sock/v1.4/containers/3cc2351ab11b/attach',
|
||||||
None,
|
|
||||||
params={'logs': 1, 'stderr': 1, 'stdout': 1},
|
params={'logs': 1, 'stderr': 1, 'stdout': 1},
|
||||||
timeout=docker.client.DEFAULT_TIMEOUT_SECONDS
|
timeout=docker.client.DEFAULT_TIMEOUT_SECONDS
|
||||||
)
|
)
|
||||||
|
|
@ -350,7 +348,6 @@ class DockerClientTest(unittest.TestCase):
|
||||||
|
|
||||||
fake_request.assert_called_with(
|
fake_request.assert_called_with(
|
||||||
'unix://var/run/docker.sock/v1.4/containers/3cc2351ab11b/attach',
|
'unix://var/run/docker.sock/v1.4/containers/3cc2351ab11b/attach',
|
||||||
None,
|
|
||||||
params={'logs': 1, 'stderr': 1, 'stdout': 1},
|
params={'logs': 1, 'stderr': 1, 'stdout': 1},
|
||||||
timeout=docker.client.DEFAULT_TIMEOUT_SECONDS
|
timeout=docker.client.DEFAULT_TIMEOUT_SECONDS
|
||||||
)
|
)
|
||||||
|
|
@ -383,7 +380,6 @@ class DockerClientTest(unittest.TestCase):
|
||||||
|
|
||||||
fake_request.assert_called_with(
|
fake_request.assert_called_with(
|
||||||
'unix://var/run/docker.sock/v1.4/containers/3cc2351ab11b/stop',
|
'unix://var/run/docker.sock/v1.4/containers/3cc2351ab11b/stop',
|
||||||
None,
|
|
||||||
params={'t': 2},
|
params={'t': 2},
|
||||||
timeout=docker.client.DEFAULT_TIMEOUT_SECONDS
|
timeout=docker.client.DEFAULT_TIMEOUT_SECONDS
|
||||||
)
|
)
|
||||||
|
|
@ -396,7 +392,6 @@ class DockerClientTest(unittest.TestCase):
|
||||||
|
|
||||||
fake_request.assert_called_with(
|
fake_request.assert_called_with(
|
||||||
'unix://var/run/docker.sock/v1.4/containers/3cc2351ab11b/stop',
|
'unix://var/run/docker.sock/v1.4/containers/3cc2351ab11b/stop',
|
||||||
None,
|
|
||||||
params={'t': 2},
|
params={'t': 2},
|
||||||
timeout=docker.client.DEFAULT_TIMEOUT_SECONDS
|
timeout=docker.client.DEFAULT_TIMEOUT_SECONDS
|
||||||
)
|
)
|
||||||
|
|
@ -409,7 +404,6 @@ class DockerClientTest(unittest.TestCase):
|
||||||
|
|
||||||
fake_request.assert_called_with(
|
fake_request.assert_called_with(
|
||||||
'unix://var/run/docker.sock/v1.4/containers/3cc2351ab11b/kill',
|
'unix://var/run/docker.sock/v1.4/containers/3cc2351ab11b/kill',
|
||||||
None,
|
|
||||||
timeout=docker.client.DEFAULT_TIMEOUT_SECONDS
|
timeout=docker.client.DEFAULT_TIMEOUT_SECONDS
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -421,7 +415,6 @@ class DockerClientTest(unittest.TestCase):
|
||||||
|
|
||||||
fake_request.assert_called_with(
|
fake_request.assert_called_with(
|
||||||
'unix://var/run/docker.sock/v1.4/containers/3cc2351ab11b/kill',
|
'unix://var/run/docker.sock/v1.4/containers/3cc2351ab11b/kill',
|
||||||
None,
|
|
||||||
timeout=docker.client.DEFAULT_TIMEOUT_SECONDS
|
timeout=docker.client.DEFAULT_TIMEOUT_SECONDS
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -433,7 +426,6 @@ class DockerClientTest(unittest.TestCase):
|
||||||
|
|
||||||
fake_request.assert_called_with(
|
fake_request.assert_called_with(
|
||||||
'unix://var/run/docker.sock/v1.4/containers/3cc2351ab11b/restart',
|
'unix://var/run/docker.sock/v1.4/containers/3cc2351ab11b/restart',
|
||||||
None,
|
|
||||||
params={'t': 2},
|
params={'t': 2},
|
||||||
timeout=docker.client.DEFAULT_TIMEOUT_SECONDS
|
timeout=docker.client.DEFAULT_TIMEOUT_SECONDS
|
||||||
)
|
)
|
||||||
|
|
@ -446,7 +438,6 @@ class DockerClientTest(unittest.TestCase):
|
||||||
|
|
||||||
fake_request.assert_called_with(
|
fake_request.assert_called_with(
|
||||||
'unix://var/run/docker.sock/v1.4/containers/3cc2351ab11b/restart',
|
'unix://var/run/docker.sock/v1.4/containers/3cc2351ab11b/restart',
|
||||||
None,
|
|
||||||
params={'t': 2},
|
params={'t': 2},
|
||||||
timeout=docker.client.DEFAULT_TIMEOUT_SECONDS
|
timeout=docker.client.DEFAULT_TIMEOUT_SECONDS
|
||||||
)
|
)
|
||||||
|
|
@ -500,7 +491,7 @@ class DockerClientTest(unittest.TestCase):
|
||||||
|
|
||||||
fake_request.assert_called_with(
|
fake_request.assert_called_with(
|
||||||
'unix://var/run/docker.sock/v1.4/commit',
|
'unix://var/run/docker.sock/v1.4/commit',
|
||||||
'{}',
|
data='{}',
|
||||||
headers={'Content-Type': 'application/json'},
|
headers={'Content-Type': 'application/json'},
|
||||||
params={
|
params={
|
||||||
'repo': None,
|
'repo': None,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue