|
18 | 18 | parse_repository_tag, parse_host, convert_filters, kwargs_from_env,
|
19 | 19 | create_host_config, Ulimit, LogConfig, parse_bytes, parse_env_file,
|
20 | 20 | exclude_paths, convert_volume_binds, decode_json_header, tar,
|
21 |
| - split_command, create_ipam_config, create_ipam_pool, |
| 21 | + split_command, create_ipam_config, create_ipam_pool, parse_devices, |
22 | 22 | )
|
23 | 23 | from docker.utils.utils import create_endpoint_config
|
24 | 24 | from docker.utils.ports import build_port_bindings, split_port
|
@@ -406,6 +406,65 @@ def test_private_reg_image_sha(self):
|
406 | 406 | )
|
407 | 407 |
|
408 | 408 |
|
| 409 | +class ParseDeviceTest(base.BaseTestCase): |
| 410 | + def test_dict(self): |
| 411 | + devices = parse_devices([{ |
| 412 | + 'PathOnHost': '/dev/sda1', |
| 413 | + 'PathInContainer': '/dev/mnt1', |
| 414 | + 'CgroupPermissions': 'r' |
| 415 | + }]) |
| 416 | + self.assertEqual(devices[0], { |
| 417 | + 'PathOnHost': '/dev/sda1', |
| 418 | + 'PathInContainer': '/dev/mnt1', |
| 419 | + 'CgroupPermissions': 'r' |
| 420 | + }) |
| 421 | + |
| 422 | + def test_partial_string_definition(self): |
| 423 | + devices = parse_devices(['/dev/sda1']) |
| 424 | + self.assertEqual(devices[0], { |
| 425 | + 'PathOnHost': '/dev/sda1', |
| 426 | + 'PathInContainer': '/dev/sda1', |
| 427 | + 'CgroupPermissions': 'rwm' |
| 428 | + }) |
| 429 | + |
| 430 | + def test_permissionless_string_definition(self): |
| 431 | + devices = parse_devices(['/dev/sda1:/dev/mnt1']) |
| 432 | + self.assertEqual(devices[0], { |
| 433 | + 'PathOnHost': '/dev/sda1', |
| 434 | + 'PathInContainer': '/dev/mnt1', |
| 435 | + 'CgroupPermissions': 'rwm' |
| 436 | + }) |
| 437 | + |
| 438 | + def test_full_string_definition(self): |
| 439 | + devices = parse_devices(['/dev/sda1:/dev/mnt1:r']) |
| 440 | + self.assertEqual(devices[0], { |
| 441 | + 'PathOnHost': '/dev/sda1', |
| 442 | + 'PathInContainer': '/dev/mnt1', |
| 443 | + 'CgroupPermissions': 'r' |
| 444 | + }) |
| 445 | + |
| 446 | + def test_hybrid_list(self): |
| 447 | + devices = parse_devices([ |
| 448 | + '/dev/sda1:/dev/mnt1:rw', |
| 449 | + { |
| 450 | + 'PathOnHost': '/dev/sda2', |
| 451 | + 'PathInContainer': '/dev/mnt2', |
| 452 | + 'CgroupPermissions': 'r' |
| 453 | + } |
| 454 | + ]) |
| 455 | + |
| 456 | + self.assertEqual(devices[0], { |
| 457 | + 'PathOnHost': '/dev/sda1', |
| 458 | + 'PathInContainer': '/dev/mnt1', |
| 459 | + 'CgroupPermissions': 'rw' |
| 460 | + }) |
| 461 | + self.assertEqual(devices[1], { |
| 462 | + 'PathOnHost': '/dev/sda2', |
| 463 | + 'PathInContainer': '/dev/mnt2', |
| 464 | + 'CgroupPermissions': 'r' |
| 465 | + }) |
| 466 | + |
| 467 | + |
409 | 468 | class UtilsTest(base.BaseTestCase):
|
410 | 469 | longMessage = True
|
411 | 470 |
|
|
0 commit comments