diff options
author | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2018-02-27 22:14:37 +0900 |
---|---|---|
committer | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2018-02-28 00:07:10 +0900 |
commit | 0d5b0955a66eed0ef67137f45276bd3a292341b0 (patch) | |
tree | e7118c697a0418df019d512974b66906a904db89 | |
parent | ce6ea0e1ae6b95a5d623c4b4aa0c777e4b4eb98c (diff) | |
download | buildstream-0d5b0955a66eed0ef67137f45276bd3a292341b0.tar.gz |
tests/integration/shell.py: Added tests for host-files
Newly added tests:
o Test that bind mounting a file works
o Test that bind mounting a file into a non-existing directory works
o Test that bind mounting is disabled in an isolated shell
o Test that the shell still works, but a warning is printed and
the mount is refused in case the specified file on the host
was found to be a directory
o Test that the shell still works, but a warning is printed
in the case that the file specified on the host does not exist
-rw-r--r-- | tests/integration/project/files/shell-mount/pony.txt | 1 | ||||
-rw-r--r-- | tests/integration/shell.py | 97 |
2 files changed, 98 insertions, 0 deletions
diff --git a/tests/integration/project/files/shell-mount/pony.txt b/tests/integration/project/files/shell-mount/pony.txt new file mode 100644 index 000000000..f62144808 --- /dev/null +++ b/tests/integration/project/files/shell-mount/pony.txt @@ -0,0 +1 @@ +pony diff --git a/tests/integration/shell.py b/tests/integration/shell.py index 18f2968fd..08dda0d22 100644 --- a/tests/integration/shell.py +++ b/tests/integration/shell.py @@ -147,3 +147,100 @@ def test_no_shell(cli, tmpdir, datafiles): result = execute_shell(cli, project, ['/bin/echo', 'Pegasissies!'], element=element_name) assert result.exit_code == 0 assert result.output == "Pegasissies!\n" + + +# Test that bind mounts defined in project.conf work +@pytest.mark.parametrize("path", [("/etc/pony.conf"), ("/usr/share/pony/pony.txt")]) +@pytest.mark.datafiles(DATA_DIR) +def test_host_files(cli, tmpdir, datafiles, path): + project = os.path.join(datafiles.dirname, datafiles.basename) + ponyfile = os.path.join(project, 'files', 'shell-mount', 'pony.txt') + + create_project_conf(project, { + 'shell': { + 'host-files': [ + { + 'host': ponyfile, + 'sandbox': path + } + ] + } + }) + + result = execute_shell(cli, project, ['cat', path]) + assert result.exit_code == 0 + assert result.output == 'pony\n' + + +# Test that bind mounts defined in project.conf dont mount in isolation +@pytest.mark.parametrize("path", [("/etc/pony.conf"), ("/usr/share/pony/pony.txt")]) +@pytest.mark.datafiles(DATA_DIR) +def test_isolated_no_mount(cli, tmpdir, datafiles, path): + project = os.path.join(datafiles.dirname, datafiles.basename) + ponyfile = os.path.join(project, 'files', 'shell-mount', 'pony.txt') + + create_project_conf(project, { + 'shell': { + 'host-files': [ + { + 'host': ponyfile, + 'sandbox': path + } + ] + } + }) + + result = execute_shell(cli, project, ['cat', path], isolate=True) + assert result.exit_code != 0 + + +# Test that bind mounts which specify directories dont get mounted +@pytest.mark.datafiles(DATA_DIR) +def test_host_files_refuse_dir(cli, tmpdir, datafiles): + project = os.path.join(datafiles.dirname, datafiles.basename) + ponydir = os.path.join(project, 'files', 'shell-mount') + + create_project_conf(project, { + 'shell': { + 'host-files': [ + { + 'host': ponydir, + 'sandbox': '/usr/share/pony' + } + ] + } + }) + + # Assert that we did successfully run something in the shell anyway + result = execute_shell(cli, project, ['echo', 'Hello']) + assert result.exit_code == 0 + assert result.output == 'Hello\n' + + # Assert that there was some warning about refusing to mount + assert ponydir in result.stderr + + +# Test that we warn about non-existing files on the host, but execute the shell anyway +@pytest.mark.datafiles(DATA_DIR) +def test_host_files_non_existing(cli, tmpdir, datafiles): + project = os.path.join(datafiles.dirname, datafiles.basename) + ponyfile = os.path.join(project, 'files', 'shell-mount', 'horsy.txt') + + create_project_conf(project, { + 'shell': { + 'host-files': [ + { + 'host': ponyfile, + 'sandbox': '/etc/pony.conf' + } + ] + } + }) + + # Assert that we did successfully run something in the shell anyway + result = execute_shell(cli, project, ['echo', 'Hello']) + assert result.exit_code == 0 + assert result.output == 'Hello\n' + + # Assert that there was some warning about refusing to mount + assert ponyfile in result.stderr |