From 1a4cacdfb63f0fbf2299962732c75484c24ad8b0 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Fri, 29 Jul 2022 19:57:30 +0200 Subject: api: add platform to container create (#2927) Add platform parameter for container creation/run Signed-off-by: Felix Fontein Signed-off-by: Milas Bowman Co-authored-by: Milas Bowman --- tests/unit/api_container_test.py | 16 ++++++++++++++++ tests/unit/models_containers_test.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) (limited to 'tests') diff --git a/tests/unit/api_container_test.py b/tests/unit/api_container_test.py index 7030841..3a2fbde 100644 --- a/tests/unit/api_container_test.py +++ b/tests/unit/api_container_test.py @@ -348,6 +348,22 @@ class CreateContainerTest(BaseAPIClientTest): assert args[1]['headers'] == {'Content-Type': 'application/json'} assert args[1]['params'] == {'name': 'marisa-kirisame'} + def test_create_container_with_platform(self): + self.client.create_container('busybox', 'true', + platform='linux') + + args = fake_request.call_args + assert args[0][1] == url_prefix + 'containers/create' + assert json.loads(args[1]['data']) == json.loads(''' + {"Tty": false, "Image": "busybox", "Cmd": ["true"], + "AttachStdin": false, + "AttachStderr": true, "AttachStdout": true, + "StdinOnce": false, + "OpenStdin": false, "NetworkDisabled": false} + ''') + assert args[1]['headers'] == {'Content-Type': 'application/json'} + assert args[1]['params'] == {'name': None, 'platform': 'linux'} + def test_create_container_with_mem_limit_as_int(self): self.client.create_container( 'busybox', 'true', host_config=self.client.create_host_config( diff --git a/tests/unit/models_containers_test.py b/tests/unit/models_containers_test.py index 785a849..e4ee074 100644 --- a/tests/unit/models_containers_test.py +++ b/tests/unit/models_containers_test.py @@ -77,6 +77,7 @@ class ContainerCollectionTest(unittest.TestCase): oom_score_adj=5, pid_mode='host', pids_limit=500, + platform='linux', ports={ 1111: 4567, 2222: None @@ -186,6 +187,7 @@ class ContainerCollectionTest(unittest.TestCase): name='somename', network_disabled=False, networking_config={'foo': None}, + platform='linux', ports=[('1111', 'tcp'), ('2222', 'tcp')], stdin_open=True, stop_signal=9, @@ -314,6 +316,33 @@ class ContainerCollectionTest(unittest.TestCase): 'NetworkMode': 'default'} ) + def test_run_platform(self): + client = make_fake_client() + + # raise exception on first call, then return normal value + client.api.create_container.side_effect = [ + docker.errors.ImageNotFound(""), + client.api.create_container.return_value + ] + + client.containers.run(image='alpine', platform='linux/arm64') + + client.api.pull.assert_called_with( + 'alpine', + tag='latest', + all_tags=False, + stream=True, + platform='linux/arm64', + ) + + client.api.create_container.assert_called_with( + detach=False, + platform='linux/arm64', + image='alpine', + command=None, + host_config={'NetworkMode': 'default'}, + ) + def test_create(self): client = make_fake_client() container = client.containers.create( -- cgit v1.2.1