diff options
author | Tristan Maat <tristan.maat@codethink.co.uk> | 2017-08-15 11:51:15 +0100 |
---|---|---|
committer | Tristan Maat <tristan.maat@codethink.co.uk> | 2017-09-28 11:30:50 +0100 |
commit | 7fc58f72d6ae55b06e0d109f811050cb4020accc (patch) | |
tree | 23e541221241b8dbefcd1b90d7aa1143844cc45e | |
parent | eaebb794a37493e488930a3b1c36e195e45b2555 (diff) | |
download | buildstream-7fc58f72d6ae55b06e0d109f811050cb4020accc.tar.gz |
mount_simple.py: Add mount tests
-rw-r--r-- | tests/sandboxes/mounting/mount_simple.py | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/sandboxes/mounting/mount_simple.py b/tests/sandboxes/mounting/mount_simple.py new file mode 100644 index 000000000..6ac4f3a2d --- /dev/null +++ b/tests/sandboxes/mounting/mount_simple.py @@ -0,0 +1,52 @@ +import os +import tempfile +from contextlib import ExitStack + +import pytest + +from buildstream.sandbox._mount import Mount + + +@pytest.mark.skipif(not os.geteuid() == 0, reason="requires root permissions") +def test_bind_mount(): + with ExitStack() as stack: + src = stack.enter_context(tempfile.TemporaryDirectory()) + target = stack.enter_context(tempfile.TemporaryDirectory()) + + with open(os.path.join(src, 'test'), 'a') as test: + test.write('Test') + + with Mount.bind_mount(target, src) as dest: + # Ensure we get the correct path back + assert dest == target + + # Ensure we can access files from src from target + with open(os.path.join(target, 'test'), 'r') as test: + assert test.read() == 'Test' + + # Ensure the files from src are gone from target + with pytest.raises(FileNotFoundError): + with open(os.path.join(target, 'test'), 'r') as test: + # Actual contents don't matter + pass + + # Ensure the files in src are still in src + with open(os.path.join(src, 'test'), 'r') as test: + assert test.read() == 'Test' + + +@pytest.mark.skipif(not os.geteuid() == 0, reason="requires root permissions") +def test_mount_proc(): + with ExitStack() as stack: + src = '/proc' + target = stack.enter_context(tempfile.TemporaryDirectory()) + + with Mount.mount(target, src, mount_type='proc', ro=True) as dest: + # Ensure we get the correct path back + assert dest == target + + # Ensure /proc is actually mounted + assert os.listdir(src) == os.listdir(target) + + # Ensure /proc is unmounted correctly + assert os.listdir(target) == [] |