Skip to content

Commit 23cf16f

Browse files
authored
client: use 12 character short IDs (#2862)
Use 12 characters for Docker resource IDs for consistency with the Docker CLI. Signed-off-by: Ben Fasoli <[email protected]>
1 parent ab43018 commit 23cf16f

File tree

8 files changed

+99
-81
lines changed

8 files changed

+99
-81
lines changed

docker/models/images.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ def labels(self):
3131
@property
3232
def short_id(self):
3333
"""
34-
The ID of the image truncated to 10 characters, plus the ``sha256:``
34+
The ID of the image truncated to 12 characters, plus the ``sha256:``
3535
prefix.
3636
"""
3737
if self.id.startswith('sha256:'):
38-
return self.id[:17]
39-
return self.id[:10]
38+
return self.id[:19]
39+
return self.id[:12]
4040

4141
@property
4242
def tags(self):
@@ -141,10 +141,10 @@ def id(self):
141141
@property
142142
def short_id(self):
143143
"""
144-
The ID of the image truncated to 10 characters, plus the ``sha256:``
144+
The ID of the image truncated to 12 characters, plus the ``sha256:``
145145
prefix.
146146
"""
147-
return self.id[:17]
147+
return self.id[:19]
148148

149149
def pull(self, platform=None):
150150
"""

docker/models/resource.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ def id(self):
3535
@property
3636
def short_id(self):
3737
"""
38-
The ID of the object, truncated to 10 characters.
38+
The ID of the object, truncated to 12 characters.
3939
"""
40-
return self.id[:10]
40+
return self.id[:12]
4141

4242
def reload(self):
4343
"""

tests/unit/api_container_test.py

Lines changed: 50 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ def test_start_container(self):
2424
self.client.start(fake_api.FAKE_CONTAINER_ID)
2525

2626
args = fake_request.call_args
27-
assert args[0][1] == url_prefix + 'containers/3cc2351ab11b/start'
27+
assert args[0][1] == (url_prefix + 'containers/' +
28+
fake_api.FAKE_CONTAINER_ID + '/start')
2829
assert 'data' not in args[1]
2930
assert args[1]['timeout'] == DEFAULT_TIMEOUT_SECONDS
3031

@@ -117,7 +118,8 @@ def test_start_container_with_dict_instead_of_id(self):
117118
self.client.start({'Id': fake_api.FAKE_CONTAINER_ID})
118119

119120
args = fake_request.call_args
120-
assert args[0][1] == url_prefix + 'containers/3cc2351ab11b/start'
121+
assert args[0][1] == (url_prefix + 'containers/' +
122+
fake_api.FAKE_CONTAINER_ID + '/start')
121123
assert 'data' not in args[1]
122124
assert args[1]['timeout'] == DEFAULT_TIMEOUT_SECONDS
123125

@@ -1079,7 +1081,8 @@ def test_resize_container(self):
10791081

10801082
fake_request.assert_called_with(
10811083
'POST',
1082-
url_prefix + 'containers/3cc2351ab11b/resize',
1084+
(url_prefix + 'containers/' +
1085+
fake_api.FAKE_CONTAINER_ID + '/resize'),
10831086
params={'h': 15, 'w': 120},
10841087
timeout=DEFAULT_TIMEOUT_SECONDS
10851088
)
@@ -1092,7 +1095,8 @@ def test_rename_container(self):
10921095

10931096
fake_request.assert_called_with(
10941097
'POST',
1095-
url_prefix + 'containers/3cc2351ab11b/rename',
1098+
(url_prefix + 'containers/' +
1099+
fake_api.FAKE_CONTAINER_ID + '/rename'),
10961100
params={'name': 'foobar'},
10971101
timeout=DEFAULT_TIMEOUT_SECONDS
10981102
)
@@ -1102,7 +1106,7 @@ def test_wait(self):
11021106

11031107
fake_request.assert_called_with(
11041108
'POST',
1105-
url_prefix + 'containers/3cc2351ab11b/wait',
1109+
url_prefix + 'containers/' + fake_api.FAKE_CONTAINER_ID + '/wait',
11061110
timeout=None,
11071111
params={}
11081112
)
@@ -1112,7 +1116,7 @@ def test_wait_with_dict_instead_of_id(self):
11121116

11131117
fake_request.assert_called_with(
11141118
'POST',
1115-
url_prefix + 'containers/3cc2351ab11b/wait',
1119+
url_prefix + 'containers/' + fake_api.FAKE_CONTAINER_ID + '/wait',
11161120
timeout=None,
11171121
params={}
11181122
)
@@ -1124,7 +1128,7 @@ def test_logs(self):
11241128

11251129
fake_request.assert_called_with(
11261130
'GET',
1127-
url_prefix + 'containers/3cc2351ab11b/logs',
1131+
url_prefix + 'containers/' + fake_api.FAKE_CONTAINER_ID + '/logs',
11281132
params={'timestamps': 0, 'follow': 0, 'stderr': 1, 'stdout': 1,
11291133
'tail': 'all'},
11301134
timeout=DEFAULT_TIMEOUT_SECONDS,
@@ -1140,7 +1144,7 @@ def test_logs_with_dict_instead_of_id(self):
11401144

11411145
fake_request.assert_called_with(
11421146
'GET',
1143-
url_prefix + 'containers/3cc2351ab11b/logs',
1147+
url_prefix + 'containers/' + fake_api.FAKE_CONTAINER_ID + '/logs',
11441148
params={'timestamps': 0, 'follow': 0, 'stderr': 1, 'stdout': 1,
11451149
'tail': 'all'},
11461150
timeout=DEFAULT_TIMEOUT_SECONDS,
@@ -1157,7 +1161,7 @@ def test_log_streaming(self):
11571161

11581162
fake_request.assert_called_with(
11591163
'GET',
1160-
url_prefix + 'containers/3cc2351ab11b/logs',
1164+
url_prefix + 'containers/' + fake_api.FAKE_CONTAINER_ID + '/logs',
11611165
params={'timestamps': 0, 'follow': 0, 'stderr': 1, 'stdout': 1,
11621166
'tail': 'all'},
11631167
timeout=DEFAULT_TIMEOUT_SECONDS,
@@ -1172,7 +1176,7 @@ def test_log_following(self):
11721176

11731177
fake_request.assert_called_with(
11741178
'GET',
1175-
url_prefix + 'containers/3cc2351ab11b/logs',
1179+
url_prefix + 'containers/' + fake_api.FAKE_CONTAINER_ID + '/logs',
11761180
params={'timestamps': 0, 'follow': 1, 'stderr': 1, 'stdout': 1,
11771181
'tail': 'all'},
11781182
timeout=DEFAULT_TIMEOUT_SECONDS,
@@ -1186,7 +1190,7 @@ def test_log_following_backwards(self):
11861190

11871191
fake_request.assert_called_with(
11881192
'GET',
1189-
url_prefix + 'containers/3cc2351ab11b/logs',
1193+
url_prefix + 'containers/' + fake_api.FAKE_CONTAINER_ID + '/logs',
11901194
params={'timestamps': 0, 'follow': 1, 'stderr': 1, 'stdout': 1,
11911195
'tail': 'all'},
11921196
timeout=DEFAULT_TIMEOUT_SECONDS,
@@ -1201,7 +1205,7 @@ def test_log_streaming_and_following(self):
12011205

12021206
fake_request.assert_called_with(
12031207
'GET',
1204-
url_prefix + 'containers/3cc2351ab11b/logs',
1208+
url_prefix + 'containers/' + fake_api.FAKE_CONTAINER_ID + '/logs',
12051209
params={'timestamps': 0, 'follow': 1, 'stderr': 1, 'stdout': 1,
12061210
'tail': 'all'},
12071211
timeout=DEFAULT_TIMEOUT_SECONDS,
@@ -1217,7 +1221,7 @@ def test_log_tail(self):
12171221

12181222
fake_request.assert_called_with(
12191223
'GET',
1220-
url_prefix + 'containers/3cc2351ab11b/logs',
1224+
url_prefix + 'containers/' + fake_api.FAKE_CONTAINER_ID + '/logs',
12211225
params={'timestamps': 0, 'follow': 0, 'stderr': 1, 'stdout': 1,
12221226
'tail': 10},
12231227
timeout=DEFAULT_TIMEOUT_SECONDS,
@@ -1233,7 +1237,7 @@ def test_log_since(self):
12331237

12341238
fake_request.assert_called_with(
12351239
'GET',
1236-
url_prefix + 'containers/3cc2351ab11b/logs',
1240+
url_prefix + 'containers/' + fake_api.FAKE_CONTAINER_ID + '/logs',
12371241
params={'timestamps': 0, 'follow': 0, 'stderr': 1, 'stdout': 1,
12381242
'tail': 'all', 'since': ts},
12391243
timeout=DEFAULT_TIMEOUT_SECONDS,
@@ -1250,7 +1254,7 @@ def test_log_since_with_datetime(self):
12501254

12511255
fake_request.assert_called_with(
12521256
'GET',
1253-
url_prefix + 'containers/3cc2351ab11b/logs',
1257+
url_prefix + 'containers/' + fake_api.FAKE_CONTAINER_ID + '/logs',
12541258
params={'timestamps': 0, 'follow': 0, 'stderr': 1, 'stdout': 1,
12551259
'tail': 'all', 'since': ts},
12561260
timeout=DEFAULT_TIMEOUT_SECONDS,
@@ -1276,7 +1280,7 @@ def test_log_tty(self):
12761280
assert m.called
12771281
fake_request.assert_called_with(
12781282
'GET',
1279-
url_prefix + 'containers/3cc2351ab11b/logs',
1283+
url_prefix + 'containers/' + fake_api.FAKE_CONTAINER_ID + '/logs',
12801284
params={'timestamps': 0, 'follow': 1, 'stderr': 1, 'stdout': 1,
12811285
'tail': 'all'},
12821286
timeout=DEFAULT_TIMEOUT_SECONDS,
@@ -1288,7 +1292,8 @@ def test_diff(self):
12881292

12891293
fake_request.assert_called_with(
12901294
'GET',
1291-
url_prefix + 'containers/3cc2351ab11b/changes',
1295+
(url_prefix + 'containers/' +
1296+
fake_api.FAKE_CONTAINER_ID + '/changes'),
12921297
timeout=DEFAULT_TIMEOUT_SECONDS
12931298
)
12941299

@@ -1297,7 +1302,8 @@ def test_diff_with_dict_instead_of_id(self):
12971302

12981303
fake_request.assert_called_with(
12991304
'GET',
1300-
url_prefix + 'containers/3cc2351ab11b/changes',
1305+
(url_prefix + 'containers/' +
1306+
fake_api.FAKE_CONTAINER_ID + '/changes'),
13011307
timeout=DEFAULT_TIMEOUT_SECONDS
13021308
)
13031309

@@ -1306,7 +1312,7 @@ def test_port(self):
13061312

13071313
fake_request.assert_called_with(
13081314
'GET',
1309-
url_prefix + 'containers/3cc2351ab11b/json',
1315+
url_prefix + 'containers/' + fake_api.FAKE_CONTAINER_ID + '/json',
13101316
timeout=DEFAULT_TIMEOUT_SECONDS
13111317
)
13121318

@@ -1317,7 +1323,7 @@ def test_stop_container(self):
13171323

13181324
fake_request.assert_called_with(
13191325
'POST',
1320-
url_prefix + 'containers/3cc2351ab11b/stop',
1326+
url_prefix + 'containers/' + fake_api.FAKE_CONTAINER_ID + '/stop',
13211327
params={'t': timeout},
13221328
timeout=(DEFAULT_TIMEOUT_SECONDS + timeout)
13231329
)
@@ -1330,7 +1336,7 @@ def test_stop_container_with_dict_instead_of_id(self):
13301336

13311337
fake_request.assert_called_with(
13321338
'POST',
1333-
url_prefix + 'containers/3cc2351ab11b/stop',
1339+
url_prefix + 'containers/' + fake_api.FAKE_CONTAINER_ID + '/stop',
13341340
params={'t': timeout},
13351341
timeout=(DEFAULT_TIMEOUT_SECONDS + timeout)
13361342
)
@@ -1340,7 +1346,8 @@ def test_pause_container(self):
13401346

13411347
fake_request.assert_called_with(
13421348
'POST',
1343-
url_prefix + 'containers/3cc2351ab11b/pause',
1349+
(url_prefix + 'containers/' +
1350+
fake_api.FAKE_CONTAINER_ID + '/pause'),
13441351
timeout=(DEFAULT_TIMEOUT_SECONDS)
13451352
)
13461353

@@ -1349,7 +1356,8 @@ def test_unpause_container(self):
13491356

13501357
fake_request.assert_called_with(
13511358
'POST',
1352-
url_prefix + 'containers/3cc2351ab11b/unpause',
1359+
(url_prefix + 'containers/' +
1360+
fake_api.FAKE_CONTAINER_ID + '/unpause'),
13531361
timeout=(DEFAULT_TIMEOUT_SECONDS)
13541362
)
13551363

@@ -1358,7 +1366,7 @@ def test_kill_container(self):
13581366

13591367
fake_request.assert_called_with(
13601368
'POST',
1361-
url_prefix + 'containers/3cc2351ab11b/kill',
1369+
url_prefix + 'containers/' + fake_api.FAKE_CONTAINER_ID + '/kill',
13621370
params={},
13631371
timeout=DEFAULT_TIMEOUT_SECONDS
13641372
)
@@ -1368,7 +1376,7 @@ def test_kill_container_with_dict_instead_of_id(self):
13681376

13691377
fake_request.assert_called_with(
13701378
'POST',
1371-
url_prefix + 'containers/3cc2351ab11b/kill',
1379+
url_prefix + 'containers/' + fake_api.FAKE_CONTAINER_ID + '/kill',
13721380
params={},
13731381
timeout=DEFAULT_TIMEOUT_SECONDS
13741382
)
@@ -1378,7 +1386,7 @@ def test_kill_container_with_signal(self):
13781386

13791387
fake_request.assert_called_with(
13801388
'POST',
1381-
url_prefix + 'containers/3cc2351ab11b/kill',
1389+
url_prefix + 'containers/' + fake_api.FAKE_CONTAINER_ID + '/kill',
13821390
params={'signal': signal.SIGTERM},
13831391
timeout=DEFAULT_TIMEOUT_SECONDS
13841392
)
@@ -1388,7 +1396,8 @@ def test_restart_container(self):
13881396

13891397
fake_request.assert_called_with(
13901398
'POST',
1391-
url_prefix + 'containers/3cc2351ab11b/restart',
1399+
(url_prefix + 'containers/' +
1400+
fake_api.FAKE_CONTAINER_ID + '/restart'),
13921401
params={'t': 2},
13931402
timeout=(DEFAULT_TIMEOUT_SECONDS + 2)
13941403
)
@@ -1398,7 +1407,8 @@ def test_restart_container_with_dict_instead_of_id(self):
13981407

13991408
fake_request.assert_called_with(
14001409
'POST',
1401-
url_prefix + 'containers/3cc2351ab11b/restart',
1410+
(url_prefix + 'containers/' +
1411+
fake_api.FAKE_CONTAINER_ID + '/restart'),
14021412
params={'t': 2},
14031413
timeout=(DEFAULT_TIMEOUT_SECONDS + 2)
14041414
)
@@ -1408,7 +1418,7 @@ def test_remove_container(self):
14081418

14091419
fake_request.assert_called_with(
14101420
'DELETE',
1411-
url_prefix + 'containers/3cc2351ab11b',
1421+
url_prefix + 'containers/' + fake_api.FAKE_CONTAINER_ID,
14121422
params={'v': False, 'link': False, 'force': False},
14131423
timeout=DEFAULT_TIMEOUT_SECONDS
14141424
)
@@ -1418,7 +1428,7 @@ def test_remove_container_with_dict_instead_of_id(self):
14181428

14191429
fake_request.assert_called_with(
14201430
'DELETE',
1421-
url_prefix + 'containers/3cc2351ab11b',
1431+
url_prefix + 'containers/' + fake_api.FAKE_CONTAINER_ID,
14221432
params={'v': False, 'link': False, 'force': False},
14231433
timeout=DEFAULT_TIMEOUT_SECONDS
14241434
)
@@ -1428,7 +1438,8 @@ def test_export(self):
14281438

14291439
fake_request.assert_called_with(
14301440
'GET',
1431-
url_prefix + 'containers/3cc2351ab11b/export',
1441+
(url_prefix + 'containers/' +
1442+
fake_api.FAKE_CONTAINER_ID + '/export'),
14321443
stream=True,
14331444
timeout=DEFAULT_TIMEOUT_SECONDS
14341445
)
@@ -1438,7 +1449,8 @@ def test_export_with_dict_instead_of_id(self):
14381449

14391450
fake_request.assert_called_with(
14401451
'GET',
1441-
url_prefix + 'containers/3cc2351ab11b/export',
1452+
(url_prefix + 'containers/' +
1453+
fake_api.FAKE_CONTAINER_ID + '/export'),
14421454
stream=True,
14431455
timeout=DEFAULT_TIMEOUT_SECONDS
14441456
)
@@ -1448,7 +1460,7 @@ def test_inspect_container(self):
14481460

14491461
fake_request.assert_called_with(
14501462
'GET',
1451-
url_prefix + 'containers/3cc2351ab11b/json',
1463+
url_prefix + 'containers/' + fake_api.FAKE_CONTAINER_ID + '/json',
14521464
timeout=DEFAULT_TIMEOUT_SECONDS
14531465
)
14541466

@@ -1464,7 +1476,7 @@ def test_container_stats(self):
14641476

14651477
fake_request.assert_called_with(
14661478
'GET',
1467-
url_prefix + 'containers/3cc2351ab11b/stats',
1479+
url_prefix + 'containers/' + fake_api.FAKE_CONTAINER_ID + '/stats',
14681480
timeout=60,
14691481
stream=True
14701482
)
@@ -1474,7 +1486,7 @@ def test_container_top(self):
14741486

14751487
fake_request.assert_called_with(
14761488
'GET',
1477-
url_prefix + 'containers/3cc2351ab11b/top',
1489+
url_prefix + 'containers/' + fake_api.FAKE_CONTAINER_ID + '/top',
14781490
params={},
14791491
timeout=DEFAULT_TIMEOUT_SECONDS
14801492
)
@@ -1484,7 +1496,7 @@ def test_container_top_with_psargs(self):
14841496

14851497
fake_request.assert_called_with(
14861498
'GET',
1487-
url_prefix + 'containers/3cc2351ab11b/top',
1499+
url_prefix + 'containers/' + fake_api.FAKE_CONTAINER_ID + '/top',
14881500
params={'ps_args': 'waux'},
14891501
timeout=DEFAULT_TIMEOUT_SECONDS
14901502
)
@@ -1496,7 +1508,8 @@ def test_container_update(self):
14961508
blkio_weight=345
14971509
)
14981510
args = fake_request.call_args
1499-
assert args[0][1] == url_prefix + 'containers/3cc2351ab11b/update'
1511+
assert args[0][1] == (url_prefix + 'containers/' +
1512+
fake_api.FAKE_CONTAINER_ID + '/update')
15001513
assert json.loads(args[1]['data']) == {
15011514
'Memory': 2 * 1024, 'CpuShares': 124, 'BlkioWeight': 345
15021515
}

0 commit comments

Comments
 (0)