Skip to content

Commit c603002

Browse files
committed
Modernize exec_api.py
Signed-off-by: Joffrey F <[email protected]>
1 parent 13dfb13 commit c603002

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

docker/api/exec_api.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,19 @@ def exec_create(self, container, cmd, stdout=True, stderr=True,
3535
If the server returns an error.
3636
"""
3737

38-
if privileged and utils.compare_version('1.19', self._version) < 0:
38+
if privileged and utils.version_lt(self._version, '1.19'):
3939
raise errors.InvalidVersion(
4040
'Privileged exec is not supported in API < 1.19'
4141
)
42-
if user and utils.compare_version('1.19', self._version) < 0:
42+
if user and utils.version_lt(self._version, '1.19'):
4343
raise errors.InvalidVersion(
4444
'User-specific exec is not supported in API < 1.19'
4545
)
46-
if environment and utils.compare_version('1.25', self._version) < 0:
46+
if environment is not None and utils.version_lt(self._version, '1.25'):
4747
raise errors.InvalidVersion(
4848
'Setting environment for exec is not supported in API < 1.25'
4949
)
50+
5051
if isinstance(cmd, six.string_types):
5152
cmd = utils.split_command(cmd)
5253

@@ -109,6 +110,7 @@ def exec_resize(self, exec_id, height=None, width=None):
109110
self._raise_for_status(res)
110111

111112
@utils.minimum_version('1.15')
113+
@utils.check_resource
112114
def exec_start(self, exec_id, detach=False, tty=False, stream=False,
113115
socket=False):
114116
"""
@@ -130,8 +132,6 @@ def exec_start(self, exec_id, detach=False, tty=False, stream=False,
130132
If the server returns an error.
131133
"""
132134
# we want opened socket if socket == True
133-
if isinstance(exec_id, dict):
134-
exec_id = exec_id.get('Id')
135135

136136
data = {
137137
'Tty': tty,

tests/integration/api_exec_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def test_exec_command_with_env(self):
132132
self.tmp_containers.append(id)
133133

134134
res = self.client.exec_create(id, 'env', environment=["X=Y"])
135-
self.assertIn('Id', res)
135+
assert 'Id' in res
136136

137137
exec_log = self.client.exec_start(res)
138-
self.assertIn(b'X=Y\n', exec_log)
138+
assert b'X=Y\n' in exec_log

0 commit comments

Comments
 (0)