123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746 |
- import pytest
- from render import Render
- from formatter import get_hashed_name_for_volume
- @pytest.fixture
- def mock_values():
- return {
- "images": {
- "test_image": {
- "repository": "nginx",
- "tag": "latest",
- }
- },
- }
- def test_add_volume_invalid_type(mock_values):
- render = Render(mock_values)
- c1 = render.add_container("test_container", "test_image")
- c1.healthcheck.disable()
- with pytest.raises(Exception):
- c1.add_storage("/some/path", {"type": "invalid_type"})
- def test_add_volume_empty_mount_path(mock_values):
- render = Render(mock_values)
- c1 = render.add_container("test_container", "test_image")
- c1.healthcheck.disable()
- with pytest.raises(Exception):
- c1.add_storage("", {"type": "tmpfs"})
- def test_add_volume_duplicate_mount_path(mock_values):
- render = Render(mock_values)
- c1 = render.add_container("test_container", "test_image")
- c1.healthcheck.disable()
- c1.add_storage("/some/path", {"type": "tmpfs"})
- with pytest.raises(Exception):
- c1.add_storage("/some/path", {"type": "tmpfs"})
- def test_add_volume_host_path_invalid_propagation(mock_values):
- render = Render(mock_values)
- c1 = render.add_container("test_container", "test_image")
- c1.healthcheck.disable()
- host_path_config = {
- "type": "host_path",
- "host_path_config": {"path": "/mnt/test", "propagation": "invalid_propagation"},
- }
- with pytest.raises(Exception):
- c1.add_storage("/some/path", host_path_config)
- def test_add_host_path_volume_no_host_path_config(mock_values):
- render = Render(mock_values)
- c1 = render.add_container("test_container", "test_image")
- c1.healthcheck.disable()
- host_path_config = {"type": "host_path"}
- with pytest.raises(Exception):
- c1.add_storage("/some/path", host_path_config)
- def test_add_host_path_volume_no_path(mock_values):
- render = Render(mock_values)
- c1 = render.add_container("test_container", "test_image")
- c1.healthcheck.disable()
- host_path_config = {"type": "host_path", "host_path_config": {"path": ""}}
- with pytest.raises(Exception):
- c1.add_storage("/some/path", host_path_config)
- def test_add_host_path_with_acl_no_path(mock_values):
- render = Render(mock_values)
- c1 = render.add_container("test_container", "test_image")
- c1.healthcheck.disable()
- host_path_config = {"type": "host_path", "host_path_config": {"acl_enable": True, "acl": {"path": ""}}}
- with pytest.raises(Exception):
- c1.add_storage("/some/path", host_path_config)
- def test_add_host_path_volume_mount(mock_values):
- render = Render(mock_values)
- c1 = render.add_container("test_container", "test_image")
- c1.healthcheck.disable()
- host_path_config = {"type": "host_path", "host_path_config": {"path": "/mnt/test"}}
- c1.add_storage("/some/path", host_path_config)
- output = render.render()
- assert output["services"]["test_container"]["volumes"] == [
- {
- "type": "bind",
- "source": "/mnt/test",
- "target": "/some/path",
- "read_only": False,
- "bind": {"create_host_path": False, "propagation": "rprivate"},
- }
- ]
- def test_add_host_path_volume_mount_with_acl(mock_values):
- render = Render(mock_values)
- c1 = render.add_container("test_container", "test_image")
- c1.healthcheck.disable()
- host_path_config = {
- "type": "host_path",
- "host_path_config": {"path": "/mnt/test", "acl_enable": True, "acl": {"path": "/mnt/test/acl"}},
- }
- c1.add_storage("/some/path", host_path_config)
- output = render.render()
- assert output["services"]["test_container"]["volumes"] == [
- {
- "type": "bind",
- "source": "/mnt/test/acl",
- "target": "/some/path",
- "read_only": False,
- "bind": {"create_host_path": False, "propagation": "rprivate"},
- }
- ]
- def test_add_host_path_volume_mount_with_propagation(mock_values):
- render = Render(mock_values)
- c1 = render.add_container("test_container", "test_image")
- c1.healthcheck.disable()
- host_path_config = {"type": "host_path", "host_path_config": {"path": "/mnt/test", "propagation": "slave"}}
- c1.add_storage("/some/path", host_path_config)
- output = render.render()
- assert output["services"]["test_container"]["volumes"] == [
- {
- "type": "bind",
- "source": "/mnt/test",
- "target": "/some/path",
- "read_only": False,
- "bind": {"create_host_path": False, "propagation": "slave"},
- }
- ]
- def test_add_host_path_volume_mount_with_create_host_path(mock_values):
- render = Render(mock_values)
- c1 = render.add_container("test_container", "test_image")
- c1.healthcheck.disable()
- host_path_config = {"type": "host_path", "host_path_config": {"path": "/mnt/test", "create_host_path": True}}
- c1.add_storage("/some/path", host_path_config)
- output = render.render()
- assert output["services"]["test_container"]["volumes"] == [
- {
- "type": "bind",
- "source": "/mnt/test",
- "target": "/some/path",
- "read_only": False,
- "bind": {"create_host_path": True, "propagation": "rprivate"},
- }
- ]
- def test_add_host_path_volume_mount_with_read_only(mock_values):
- render = Render(mock_values)
- c1 = render.add_container("test_container", "test_image")
- c1.healthcheck.disable()
- host_path_config = {"type": "host_path", "read_only": True, "host_path_config": {"path": "/mnt/test"}}
- c1.add_storage("/some/path", host_path_config)
- output = render.render()
- assert output["services"]["test_container"]["volumes"] == [
- {
- "type": "bind",
- "source": "/mnt/test",
- "target": "/some/path",
- "read_only": True,
- "bind": {"create_host_path": False, "propagation": "rprivate"},
- }
- ]
- def test_add_ix_volume_invalid_dataset_name(mock_values):
- mock_values["ix_volumes"] = {"test_dataset": "/mnt/test"}
- render = Render(mock_values)
- c1 = render.add_container("test_container", "test_image")
- c1.healthcheck.disable()
- ix_volume_config = {"type": "ix_volume", "ix_volume_config": {"dataset_name": "invalid_dataset"}}
- with pytest.raises(Exception):
- c1.add_storage("/some/path", ix_volume_config)
- def test_add_ix_volume_no_ix_volume_config(mock_values):
- mock_values["ix_volumes"] = {"test_dataset": "/mnt/test"}
- render = Render(mock_values)
- c1 = render.add_container("test_container", "test_image")
- c1.healthcheck.disable()
- ix_volume_config = {"type": "ix_volume"}
- with pytest.raises(Exception):
- c1.add_storage("/some/path", ix_volume_config)
- def test_add_ix_volume_volume_mount(mock_values):
- mock_values["ix_volumes"] = {"test_dataset": "/mnt/test"}
- render = Render(mock_values)
- c1 = render.add_container("test_container", "test_image")
- c1.healthcheck.disable()
- ix_volume_config = {"type": "ix_volume", "ix_volume_config": {"dataset_name": "test_dataset"}}
- c1.add_storage("/some/path", ix_volume_config)
- output = render.render()
- assert output["services"]["test_container"]["volumes"] == [
- {
- "type": "bind",
- "source": "/mnt/test",
- "target": "/some/path",
- "read_only": False,
- "bind": {"create_host_path": False, "propagation": "rprivate"},
- }
- ]
- def test_add_ix_volume_volume_mount_with_options(mock_values):
- mock_values["ix_volumes"] = {"test_dataset": "/mnt/test"}
- render = Render(mock_values)
- c1 = render.add_container("test_container", "test_image")
- c1.healthcheck.disable()
- ix_volume_config = {
- "type": "ix_volume",
- "ix_volume_config": {"dataset_name": "test_dataset", "propagation": "rslave", "create_host_path": True},
- }
- c1.add_storage("/some/path", ix_volume_config)
- output = render.render()
- assert output["services"]["test_container"]["volumes"] == [
- {
- "type": "bind",
- "source": "/mnt/test",
- "target": "/some/path",
- "read_only": False,
- "bind": {"create_host_path": True, "propagation": "rslave"},
- }
- ]
- def test_cifs_volume_missing_server(mock_values):
- render = Render(mock_values)
- c1 = render.add_container("test_container", "test_image")
- c1.healthcheck.disable()
- cifs_config = {"type": "cifs", "cifs_config": {"path": "/path", "username": "user", "password": "password"}}
- with pytest.raises(Exception):
- c1.add_storage("/some/path", cifs_config)
- def test_cifs_volume_missing_path(mock_values):
- render = Render(mock_values)
- c1 = render.add_container("test_container", "test_image")
- c1.healthcheck.disable()
- cifs_config = {"type": "cifs", "cifs_config": {"server": "server", "username": "user", "password": "password"}}
- with pytest.raises(Exception):
- c1.add_storage("/some/path", cifs_config)
- def test_cifs_volume_missing_username(mock_values):
- render = Render(mock_values)
- c1 = render.add_container("test_container", "test_image")
- c1.healthcheck.disable()
- cifs_config = {"type": "cifs", "cifs_config": {"server": "server", "path": "/path", "password": "password"}}
- with pytest.raises(Exception):
- c1.add_storage("/some/path", cifs_config)
- def test_cifs_volume_missing_password(mock_values):
- render = Render(mock_values)
- c1 = render.add_container("test_container", "test_image")
- c1.healthcheck.disable()
- cifs_config = {"type": "cifs", "cifs_config": {"server": "server", "path": "/path", "username": "user"}}
- with pytest.raises(Exception):
- c1.add_storage("/some/path", cifs_config)
- def test_cifs_volume_without_cifs_config(mock_values):
- render = Render(mock_values)
- c1 = render.add_container("test_container", "test_image")
- c1.healthcheck.disable()
- cifs_config = {"type": "cifs"}
- with pytest.raises(Exception):
- c1.add_storage("/some/path", cifs_config)
- def test_cifs_volume_duplicate_option(mock_values):
- render = Render(mock_values)
- c1 = render.add_container("test_container", "test_image")
- c1.healthcheck.disable()
- cifs_config = {
- "type": "cifs",
- "cifs_config": {
- "server": "server",
- "path": "/path",
- "username": "user",
- "password": "pas$word",
- "options": ["verbose=true", "verbose=true"],
- },
- }
- with pytest.raises(Exception):
- c1.add_storage("/some/path", cifs_config)
- def test_cifs_volume_disallowed_option(mock_values):
- render = Render(mock_values)
- c1 = render.add_container("test_container", "test_image")
- c1.healthcheck.disable()
- cifs_config = {
- "type": "cifs",
- "cifs_config": {
- "server": "server",
- "path": "/path",
- "username": "user",
- "password": "pas$word",
- "options": ["user=username"],
- },
- }
- with pytest.raises(Exception):
- c1.add_storage("/some/path", cifs_config)
- def test_cifs_volume_invalid_options(mock_values):
- render = Render(mock_values)
- c1 = render.add_container("test_container", "test_image")
- c1.healthcheck.disable()
- cifs_config = {
- "type": "cifs",
- "cifs_config": {
- "server": "server",
- "path": "/path",
- "username": "user",
- "password": "pas$word",
- "options": {"verbose": True},
- },
- }
- with pytest.raises(Exception):
- c1.add_storage("/some/path", cifs_config)
- def test_cifs_volume_invalid_options2(mock_values):
- render = Render(mock_values)
- c1 = render.add_container("test_container", "test_image")
- c1.healthcheck.disable()
- cifs_config = {
- "type": "cifs",
- "cifs_config": {
- "server": "server",
- "path": "/path",
- "username": "user",
- "password": "pas$word",
- "options": [{"verbose": True}],
- },
- }
- with pytest.raises(Exception):
- c1.add_storage("/some/path", cifs_config)
- def test_add_cifs_volume(mock_values):
- render = Render(mock_values)
- c1 = render.add_container("test_container", "test_image")
- c1.healthcheck.disable()
- cifs_inner_config = {"server": "server", "path": "/path", "username": "user", "password": "pas$word"}
- cifs_config = {"type": "cifs", "cifs_config": cifs_inner_config}
- c1.add_storage("/some/path", cifs_config)
- output = render.render()
- vol_name = get_hashed_name_for_volume("cifs", cifs_inner_config)
- assert output["volumes"] == {
- vol_name: {
- "driver_opts": {"type": "cifs", "device": "//server/path", "o": "noperm,password=pas$$word,user=user"}
- }
- }
- assert output["services"]["test_container"]["volumes"] == [
- {"type": "volume", "source": vol_name, "target": "/some/path", "read_only": False, "volume": {"nocopy": False}}
- ]
- def test_cifs_volume_with_options(mock_values):
- render = Render(mock_values)
- c1 = render.add_container("test_container", "test_image")
- c1.healthcheck.disable()
- cifs_inner_config = {
- "server": "server",
- "path": "/path",
- "username": "user",
- "password": "pas$word",
- "options": ["vers=3.0", "verbose=true"],
- }
- cifs_config = {"type": "cifs", "cifs_config": cifs_inner_config}
- c1.add_storage("/some/path", cifs_config)
- output = render.render()
- vol_name = get_hashed_name_for_volume("cifs", cifs_inner_config)
- assert output["volumes"] == {
- vol_name: {
- "driver_opts": {
- "type": "cifs",
- "device": "//server/path",
- "o": "noperm,password=pas$$word,user=user,verbose=true,vers=3.0",
- }
- }
- }
- assert output["services"]["test_container"]["volumes"] == [
- {"type": "volume", "source": vol_name, "target": "/some/path", "read_only": False, "volume": {"nocopy": False}}
- ]
- def test_nfs_volume_missing_server(mock_values):
- render = Render(mock_values)
- c1 = render.add_container("test_container", "test_image")
- c1.healthcheck.disable()
- nfs_config = {"type": "nfs", "nfs_config": {"path": "/path"}}
- with pytest.raises(Exception):
- c1.add_storage("/some/path", nfs_config)
- def test_nfs_volume_missing_path(mock_values):
- render = Render(mock_values)
- c1 = render.add_container("test_container", "test_image")
- c1.healthcheck.disable()
- nfs_config = {"type": "nfs", "nfs_config": {"server": "server"}}
- with pytest.raises(Exception):
- c1.add_storage("/some/path", nfs_config)
- def test_nfs_volume_without_nfs_config(mock_values):
- render = Render(mock_values)
- c1 = render.add_container("test_container", "test_image")
- c1.healthcheck.disable()
- nfs_config = {"type": "nfs"}
- with pytest.raises(Exception):
- c1.add_storage("/some/path", nfs_config)
- def test_nfs_volume_duplicate_option(mock_values):
- render = Render(mock_values)
- c1 = render.add_container("test_container", "test_image")
- c1.healthcheck.disable()
- nfs_config = {
- "type": "nfs",
- "nfs_config": {"server": "server", "path": "/path", "options": ["verbose=true", "verbose=true"]},
- }
- with pytest.raises(Exception):
- c1.add_storage("/some/path", nfs_config)
- def test_nfs_volume_disallowed_option(mock_values):
- render = Render(mock_values)
- c1 = render.add_container("test_container", "test_image")
- c1.healthcheck.disable()
- nfs_config = {"type": "nfs", "nfs_config": {"server": "server", "path": "/path", "options": ["addr=server"]}}
- with pytest.raises(Exception):
- c1.add_storage("/some/path", nfs_config)
- def test_nfs_volume_invalid_options(mock_values):
- render = Render(mock_values)
- c1 = render.add_container("test_container", "test_image")
- c1.healthcheck.disable()
- nfs_config = {"type": "nfs", "nfs_config": {"server": "server", "path": "/path", "options": {"verbose": True}}}
- with pytest.raises(Exception):
- c1.add_storage("/some/path", nfs_config)
- def test_nfs_volume_invalid_options2(mock_values):
- render = Render(mock_values)
- c1 = render.add_container("test_container", "test_image")
- c1.healthcheck.disable()
- nfs_config = {"type": "nfs", "nfs_config": {"server": "server", "path": "/path", "options": [{"verbose": True}]}}
- with pytest.raises(Exception):
- c1.add_storage("/some/path", nfs_config)
- def test_add_nfs_volume(mock_values):
- render = Render(mock_values)
- c1 = render.add_container("test_container", "test_image")
- c1.healthcheck.disable()
- nfs_inner_config = {"server": "server", "path": "/path"}
- nfs_config = {"type": "nfs", "nfs_config": nfs_inner_config}
- c1.add_storage("/some/path", nfs_config)
- output = render.render()
- vol_name = get_hashed_name_for_volume("nfs", nfs_inner_config)
- assert output["volumes"] == {vol_name: {"driver_opts": {"type": "nfs", "device": ":/path", "o": "addr=server"}}}
- assert output["services"]["test_container"]["volumes"] == [
- {"type": "volume", "source": vol_name, "target": "/some/path", "read_only": False, "volume": {"nocopy": False}}
- ]
- def test_nfs_volume_with_options(mock_values):
- render = Render(mock_values)
- c1 = render.add_container("test_container", "test_image")
- c1.healthcheck.disable()
- nfs_inner_config = {"server": "server", "path": "/path", "options": ["vers=3.0", "verbose=true"]}
- nfs_config = {"type": "nfs", "nfs_config": nfs_inner_config}
- c1.add_storage("/some/path", nfs_config)
- output = render.render()
- vol_name = get_hashed_name_for_volume("nfs", nfs_inner_config)
- assert output["volumes"] == {
- vol_name: {
- "driver_opts": {
- "type": "nfs",
- "device": ":/path",
- "o": "addr=server,verbose=true,vers=3.0",
- }
- }
- }
- assert output["services"]["test_container"]["volumes"] == [
- {"type": "volume", "source": vol_name, "target": "/some/path", "read_only": False, "volume": {"nocopy": False}}
- ]
- def test_tmpfs_invalid_size(mock_values):
- render = Render(mock_values)
- c1 = render.add_container("test_container", "test_image")
- c1.healthcheck.disable()
- vol_config = {"type": "tmpfs", "tmpfs_config": {"size": "2"}}
- with pytest.raises(Exception):
- c1.add_storage("/some/path", vol_config)
- def test_tmpfs_zero_size(mock_values):
- render = Render(mock_values)
- c1 = render.add_container("test_container", "test_image")
- c1.healthcheck.disable()
- vol_config = {"type": "tmpfs", "tmpfs_config": {"size": 0}}
- with pytest.raises(Exception):
- c1.add_storage("/some/path", vol_config)
- def test_tmpfs_invalid_mode(mock_values):
- render = Render(mock_values)
- c1 = render.add_container("test_container", "test_image")
- c1.healthcheck.disable()
- vol_config = {"type": "tmpfs", "tmpfs_config": {"mode": "invalid"}}
- with pytest.raises(Exception):
- c1.add_storage("/some/path", vol_config)
- def test_tmpfs_volume(mock_values):
- render = Render(mock_values)
- c1 = render.add_container("test_container", "test_image")
- c1.healthcheck.disable()
- c1.add_storage("/some/path", {"type": "tmpfs"})
- c1.add_storage("/some/other/path", {"type": "tmpfs", "tmpfs_config": {"size": 100}})
- c1.add_storage(
- "/some/other/path2", {"type": "tmpfs", "tmpfs_config": {"size": 100, "mode": "0777", "uid": 1000, "gid": 1000}}
- )
- output = render.render()
- assert output["services"]["test_container"]["tmpfs"] == [
- "/some/other/path2:gid=1000,mode=0777,size=104857600,uid=1000",
- "/some/other/path:size=104857600",
- "/some/path",
- ]
- def test_add_tmpfs_with_existing_volume(mock_values):
- render = Render(mock_values)
- c1 = render.add_container("test_container", "test_image")
- c1.healthcheck.disable()
- c1.add_storage("/some/path", {"type": "volume", "volume_config": {"volume_name": "test_volume"}})
- with pytest.raises(Exception):
- c1.add_storage("/some/path", {"type": "tmpfs", "tmpfs_config": {"size": 100}})
- def test_add_volume_with_existing_tmpfs(mock_values):
- render = Render(mock_values)
- c1 = render.add_container("test_container", "test_image")
- c1.healthcheck.disable()
- c1.add_storage("/some/path", {"type": "tmpfs", "tmpfs_config": {"size": 100}})
- with pytest.raises(Exception):
- c1.add_storage("/some/path", {"type": "volume", "volume_config": {"volume_name": "test_volume"}})
- def test_temporary_volume(mock_values):
- render = Render(mock_values)
- c1 = render.add_container("test_container", "test_image")
- c1.healthcheck.disable()
- vol_config = {"type": "temporary", "volume_config": {"volume_name": "test_temp_volume"}}
- c1.add_storage("/some/path", vol_config)
- output = render.render()
- assert output["services"]["test_container"]["volumes"] == [
- {
- "source": "test_temp_volume",
- "type": "volume",
- "target": "/some/path",
- "read_only": False,
- "volume": {"nocopy": False},
- }
- ]
- def test_docker_volume_missing_config(mock_values):
- render = Render(mock_values)
- c1 = render.add_container("test_container", "test_image")
- c1.healthcheck.disable()
- vol_config = {"type": "volume", "volume_config": {}}
- with pytest.raises(Exception):
- c1.add_storage("/some/path", vol_config)
- def test_docker_volume_missing_volume_name(mock_values):
- render = Render(mock_values)
- c1 = render.add_container("test_container", "test_image")
- c1.healthcheck.disable()
- vol_config = {"type": "volume", "volume_config": {"volume_name": ""}}
- with pytest.raises(Exception):
- c1.add_storage("/some/path", vol_config)
- def test_docker_volume(mock_values):
- render = Render(mock_values)
- c1 = render.add_container("test_container", "test_image")
- c1.healthcheck.disable()
- vol_config = {"type": "volume", "volume_config": {"volume_name": "test_volume"}}
- c1.add_storage("/some/path", vol_config)
- output = render.render()
- assert output["services"]["test_container"]["volumes"] == [
- {
- "type": "volume",
- "source": "test_volume",
- "target": "/some/path",
- "read_only": False,
- "volume": {"nocopy": False},
- }
- ]
- assert output["volumes"] == {"test_volume": {}}
- def test_anonymous_volume(mock_values):
- render = Render(mock_values)
- c1 = render.add_container("test_container", "test_image")
- c1.healthcheck.disable()
- vol_config = {"type": "anonymous", "volume_config": {"nocopy": True}}
- c1.add_storage("/some/path", vol_config)
- output = render.render()
- assert output["services"]["test_container"]["volumes"] == [
- {"type": "volume", "target": "/some/path", "read_only": False, "volume": {"nocopy": True}}
- ]
- assert "volumes" not in output
- def test_add_udev(mock_values):
- render = Render(mock_values)
- c1 = render.add_container("test_container", "test_image")
- c1.healthcheck.disable()
- c1.add_udev()
- output = render.render()
- assert output["services"]["test_container"]["volumes"] == [
- {
- "type": "bind",
- "source": "/run/udev",
- "target": "/run/udev",
- "read_only": True,
- "bind": {"create_host_path": False, "propagation": "rprivate"},
- }
- ]
- def test_add_udev_not_read_only(mock_values):
- render = Render(mock_values)
- c1 = render.add_container("test_container", "test_image")
- c1.healthcheck.disable()
- c1.add_udev(read_only=False)
- output = render.render()
- assert output["services"]["test_container"]["volumes"] == [
- {
- "type": "bind",
- "source": "/run/udev",
- "target": "/run/udev",
- "read_only": False,
- "bind": {"create_host_path": False, "propagation": "rprivate"},
- }
- ]
- def test_add_docker_socket(mock_values):
- render = Render(mock_values)
- c1 = render.add_container("test_container", "test_image")
- c1.healthcheck.disable()
- c1.storage._add_docker_socket(mount_path="/var/run/docker.sock")
- output = render.render()
- assert output["services"]["test_container"]["volumes"] == [
- {
- "type": "bind",
- "source": "/var/run/docker.sock",
- "target": "/var/run/docker.sock",
- "read_only": True,
- "bind": {"create_host_path": False, "propagation": "rprivate"},
- }
- ]
- def test_add_docker_socket_not_read_only(mock_values):
- render = Render(mock_values)
- c1 = render.add_container("test_container", "test_image")
- c1.healthcheck.disable()
- c1.storage._add_docker_socket(read_only=False, mount_path="/var/run/docker.sock")
- output = render.render()
- assert output["services"]["test_container"]["volumes"] == [
- {
- "type": "bind",
- "source": "/var/run/docker.sock",
- "target": "/var/run/docker.sock",
- "read_only": False,
- "bind": {"create_host_path": False, "propagation": "rprivate"},
- }
- ]
- def test_add_docker_socket_mount_path(mock_values):
- render = Render(mock_values)
- c1 = render.add_container("test_container", "test_image")
- c1.healthcheck.disable()
- c1.storage._add_docker_socket(mount_path="/some/path")
- output = render.render()
- assert output["services"]["test_container"]["volumes"] == [
- {
- "type": "bind",
- "source": "/var/run/docker.sock",
- "target": "/some/path",
- "read_only": True,
- "bind": {"create_host_path": False, "propagation": "rprivate"},
- }
- ]
- def test_host_path_with_disallowed_path(mock_values):
- render = Render(mock_values)
- c1 = render.add_container("test_container", "test_image")
- c1.healthcheck.disable()
- host_path_config = {"type": "host_path", "host_path_config": {"path": "/mnt"}}
- with pytest.raises(Exception):
- c1.add_storage("/some/path", host_path_config)
- def test_host_path_without_disallowed_path(mock_values):
- render = Render(mock_values)
- c1 = render.add_container("test_container", "test_image")
- c1.healthcheck.disable()
- host_path_config = {"type": "host_path", "host_path_config": {"path": "/mnt/test"}}
- c1.add_storage("/mnt", host_path_config)
- output = render.render()
- assert output["services"]["test_container"]["volumes"] == [
- {
- "type": "bind",
- "source": "/mnt/test",
- "target": "/mnt",
- "read_only": False,
- "bind": {"create_host_path": False, "propagation": "rprivate"},
- }
- ]
|