Skip to content

Commit b4802ea

Browse files
committed
Handle untyped ContainerSpec dict in _check_api_features
Signed-off-by: Joffrey F <[email protected]>
1 parent d49c136 commit b4802ea

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

docker/api/service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def _check_api_features(version, task_template, update_config):
3838
'Placement.preferences is not supported in'
3939
' API version < 1.27'
4040
)
41-
if task_template.container_spec.get('TTY'):
41+
if task_template.get('ContainerSpec', {}).get('TTY'):
4242
if utils.version_lt(version, '1.25'):
4343
raise errors.InvalidVersion(
4444
'ContainerSpec.TTY is not supported in API version < 1.25'

tests/integration/api_service_test.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,23 @@ def test_create_service_with_tty(self):
376376
assert 'TTY' in con_spec
377377
assert con_spec['TTY'] is True
378378

379+
@requires_api_version('1.25')
380+
def test_create_service_with_tty_dict(self):
381+
container_spec = {
382+
'Image': BUSYBOX,
383+
'Command': ['true'],
384+
'TTY': True
385+
}
386+
task_tmpl = docker.types.TaskTemplate(container_spec)
387+
name = self.get_service_name()
388+
svc_id = self.client.create_service(task_tmpl, name=name)
389+
svc_info = self.client.inspect_service(svc_id)
390+
assert 'TaskTemplate' in svc_info['Spec']
391+
assert 'ContainerSpec' in svc_info['Spec']['TaskTemplate']
392+
con_spec = svc_info['Spec']['TaskTemplate']['ContainerSpec']
393+
assert 'TTY' in con_spec
394+
assert con_spec['TTY'] is True
395+
379396
def test_create_service_global_mode(self):
380397
container_spec = docker.types.ContainerSpec(
381398
BUSYBOX, ['echo', 'hello']

0 commit comments

Comments
 (0)