summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJoffrey F <f.joffrey@gmail.com>2016-02-24 18:00:06 -0800
committerJoffrey F <f.joffrey@gmail.com>2016-02-24 18:00:06 -0800
commit81d8caaf36159bf1accd86eab2e157bf8dd071a9 (patch)
treefe7d2d7ba279f076b57b6ce964d5c132a76a43a9 /tests
parentcdf6dc8c3c5a400721633cff0c0bdf056ec2b52a (diff)
parent7440603d98d2ceb1d0df372cbf4b1591588a6949 (diff)
downloaddocker-py-81d8caaf36159bf1accd86eab2e157bf8dd071a9.tar.gz
Merge pull request #916 from docker/container_update_feature
Support for container limits update
Diffstat (limited to 'tests')
-rw-r--r--tests/integration/container_test.py18
-rw-r--r--tests/unit/container_test.py18
-rw-r--r--tests/unit/fake_api.py7
3 files changed, 43 insertions, 0 deletions
diff --git a/tests/integration/container_test.py b/tests/integration/container_test.py
index aae7ad7..6120135 100644
--- a/tests/integration/container_test.py
+++ b/tests/integration/container_test.py
@@ -1044,3 +1044,21 @@ class GetContainerStatsTest(helpers.BaseTestCase):
for key in ['read', 'network', 'precpu_stats', 'cpu_stats',
'memory_stats', 'blkio_stats']:
self.assertIn(key, chunk)
+
+
+class ContainerUpdateTest(helpers.BaseTestCase):
+ @requires_api_version('1.22')
+ def test_update_container(self):
+ old_mem_limit = 400 * 1024 * 1024
+ new_mem_limit = 300 * 1024 * 1024
+ container = self.client.create_container(
+ BUSYBOX, 'top', host_config=self.client.create_host_config(
+ mem_limit=old_mem_limit
+ ), cpu_shares=102
+ )
+ self.tmp_containers.append(container)
+ self.client.start(container)
+ self.client.update_container(container, mem_limit=new_mem_limit)
+ inspect_data = self.client.inspect_container(container)
+ self.assertEqual(inspect_data['HostConfig']['Memory'], new_mem_limit)
+ self.assertEqual(inspect_data['HostConfig']['CpuShares'], 102)
diff --git a/tests/unit/container_test.py b/tests/unit/container_test.py
index d66eeed..6e23f89 100644
--- a/tests/unit/container_test.py
+++ b/tests/unit/container_test.py
@@ -1452,3 +1452,21 @@ class ContainerTest(DockerClientTest):
params={'ps_args': 'waux'},
timeout=DEFAULT_TIMEOUT_SECONDS
)
+
+ @requires_api_version('1.22')
+ def test_container_update(self):
+ self.client.update_container(
+ fake_api.FAKE_CONTAINER_ID, mem_limit='2k', cpu_shares=124,
+ blkio_weight=345
+ )
+ args = fake_request.call_args
+ self.assertEqual(
+ args[0][1], url_prefix + 'containers/3cc2351ab11b/update'
+ )
+ self.assertEqual(
+ json.loads(args[1]['data']),
+ {'Memory': 2 * 1024, 'CpuShares': 124, 'BlkioWeight': 345}
+ )
+ self.assertEqual(
+ args[1]['headers']['Content-Type'], 'application/json'
+ )
diff --git a/tests/unit/fake_api.py b/tests/unit/fake_api.py
index 8852da0..9952595 100644
--- a/tests/unit/fake_api.py
+++ b/tests/unit/fake_api.py
@@ -441,6 +441,11 @@ def get_fake_volume():
def fake_remove_volume():
return 204, None
+
+def post_fake_update_container():
+ return 200, {'Warnings': []}
+
+
# Maps real api url to fake response callback
prefix = 'http+docker://localunixsocket'
fake_responses = {
@@ -478,6 +483,8 @@ fake_responses = {
get_fake_diff,
'{1}/{0}/containers/3cc2351ab11b/export'.format(CURRENT_VERSION, prefix):
get_fake_export,
+ '{1}/{0}/containers/3cc2351ab11b/update'.format(CURRENT_VERSION, prefix):
+ post_fake_update_container,
'{1}/{0}/containers/3cc2351ab11b/exec'.format(CURRENT_VERSION, prefix):
post_fake_exec_create,
'{1}/{0}/exec/d5d177f121dc/start'.format(CURRENT_VERSION, prefix):