|
9 | 9 | logger = logging.getLogger(__name__)
|
10 | 10 |
|
11 | 11 |
|
12 |
| -def test_bgp_dev(duthost): |
| 12 | +def test_container_privileged(duthost): |
13 | 13 | """
|
14 |
| - Test bgp container has no access to /dev/vda* or /dev/sda* |
| 14 | + Test container without --privileged flag has no access to /dev/vda* or /dev/sda* |
15 | 15 | """
|
16 |
| - cmd = duthost.shell("docker exec bgp bash -c 'df -h | grep /etc/hosts' | awk '{print $1}'") |
17 |
| - rc, device = cmd['rc'], cmd['stdout'] |
18 |
| - if rc != 0: |
19 |
| - pytest_assert(False, 'Failed to get the device name.') |
20 |
| - if not device.startswith('/dev/'): |
21 |
| - pytest_assert(False, 'Invalid device {}.'.format(device)) |
22 |
| - output = duthost.shell("docker exec bgp bash -c 'ls {}'".format(device), module_ignore_errors=True)['stdout'] |
23 |
| - pytest_assert(not output, 'The partition {} exists.'.format(device)) |
| 16 | + container_names = duthost.shell(r'docker ps -a --format \{\{.Names\}\}')['stdout_lines'] |
| 17 | + for container_name in container_names: |
| 18 | + if container_name == 'bgp': |
| 19 | + docker_exec_cmd = 'docker exec {} bash -c '.format(container_name) |
| 20 | + cmd = duthost.shell(docker_exec_cmd + "'df -h | grep /etc/hosts' | awk '{print $1}'") |
| 21 | + rc, device = cmd['rc'], cmd['stdout'] |
| 22 | + pytest_assert(rc == 0, 'Failed to get the device name.') |
| 23 | + pytest_assert(device.startswith('/dev/'), 'Invalid device {}.'.format(device)) |
| 24 | + output = duthost.shell(docker_exec_cmd + "'ls {}'".format(device), module_ignore_errors=True)['stdout'] |
| 25 | + pytest_assert(not output, 'The partition {} exists.'.format(device)) |
0 commit comments