示例#1
0
def test__sharing_nfs_service__validate_hosts_and_networks__same_device_multiple_shares_alldir(
):
    with patch(
            "middlewared.plugins.nfs.os.stat", lambda dev: {
                "/mnt/data/a": Mock(st_dev=1),
                "/mnt/data/b": Mock(st_dev=1),
            }[dev]):
        middleware = Mock()

        verrors = Mock()

        SharingNFSService(middleware).validate_hosts_and_networks(
            [{
                "paths": ["/mnt/data/a"],
                "hosts": [],
                "networks": ["192.168.100.0/24"],
                "alldirs": True,
            }],
            {
                "paths": ["/mnt/data/b"],
                "hosts": [],
                "networks": ["192.168.200.0/24"],
                "alldirs": True,
            },
            "sharingnfs_update",
            verrors,
            {},
        )

        verrors.add.assert_called_once_with("sharingnfs_update.alldirs", ANY)
示例#2
0
def test__sharing_nfs_service__validate_hosts_and_networks__existing_for_everyone(
):
    with patch(
            "middlewared.plugins.nfs.os.stat", lambda dev: {
                "/mnt/data/a": Mock(st_dev=1),
                "/mnt/data/b": Mock(st_dev=1),
            }[dev]):
        middleware = Mock()

        verrors = Mock()

        SharingNFSService(middleware).validate_hosts_and_networks(
            [
                {
                    "paths": ["/mnt/data/a"],
                    "hosts": [],
                    "networks": [],
                    "alldirs": False,
                },
            ],
            {
                "paths": ["/mnt/data/b"],
                "hosts": [],
                "networks": ["192.168.0.0/24"],
                "alldirs": False,
            },
            "sharingnfs_update",
            verrors,
            {
                "192.168.0.1": "192.168.0.1",
            },
        )

        verrors.add.assert_called_once_with("sharingnfs_update.networks.0",
                                            ANY)
示例#3
0
def test__sharing_nfs_service__validate_user_networks__overlapping_networks():
    with patch(
            "middlewared.plugins.nfs.os.stat", lambda dev: {
                "/mnt/data/a": Mock(st_dev=1),
                "/mnt/data/b": Mock(st_dev=1),
            }[dev]):
        middleware = Mock()

        verrors = Mock()

        SharingNFSService(middleware).validate_user_networks(
            [{
                "paths": ["/mnt/data/a"],
                "networks": ["192.168.100.0/24"],
                "alldirs": False,
            }],
            {
                "paths": ["/mnt/data/b"],
                "networks": ["192.168.100.0/25"],
                "alldirs": False,
            },
            "sharingnfs_update",
            verrors,
        )

        verrors.add.assert_called_once_with("sharingnfs_update.networks.0",
                                            ANY)
示例#4
0
def test__sharing_nfs_service__validate_hosts_and_networks__fs_is_already_exported_for_world(
):
    with patch(
            "middlewared.plugins.nfs.os.stat", lambda dev: {
                "/mnt/data/a": Mock(st_dev=1),
                "/mnt/data/b": Mock(st_dev=1),
            }[dev]):
        middleware = Mock()

        verrors = Mock()

        SharingNFSService(middleware).validate_hosts_and_networks(
            [
                {
                    "path": "/mnt/data/a",
                    "hosts": ["192.168.0.1"],
                    "networks": [],
                },
            ],
            {
                "path": "/mnt/data/b",
                "hosts": [],
                "networks": [],
            },
            "sharingnfs_update",
            verrors,
            {
                "192.168.0.1": "192.168.0.1",
            },
        )

        verrors.add.assert_called_once_with("sharingnfs_update.networks", ANY)
示例#5
0
def test__sharing_nfs_service__validate_paths__same_filesystem():
    with patch(
            "middlewared.plugins.nfs.os.stat", lambda dev: {
                "/mnt/data-1": Mock(st_dev=1),
                "/mnt/data-1/a": Mock(st_dev=1),
                "/mnt/data-1/b": Mock(st_dev=1),
            }[dev]):
        middleware = Mock()

        verrors = Mock()

        SharingNFSService(middleware).validate_paths(
            {
                "paths": ["/mnt/data-1/a", "/mnt/data-1/b"],
            },
            "sharingnfs_update",
            verrors,
        )

        assert not verrors.add.called
示例#6
0
def test__sharing_nfs_service__validate_paths__alldirs_for_nonmountpoint():
    with patch(
            "middlewared.plugins.nfs.os.stat", lambda dev: {
                "/mnt": Mock(st_dev=0),
                "/mnt/data-1": Mock(st_dev=1),
                "/mnt/data-1/a": Mock(st_dev=1),
            }[dev]):
        middleware = Mock()

        verrors = Mock()

        SharingNFSService(middleware).validate_paths(
            {
                "paths": ["/mnt/data-1/a"],
                "alldirs": True,
            },
            "sharingnfs_update",
            verrors,
        )

        verrors.add.assert_called_once_with("sharingnfs_update.alldirs", ANY)
示例#7
0
def test__sharing_nfs_service__validate_hosts_and_networks__cant_share_overlapping(
):
    with patch(
            "middlewared.plugins.nfs.os.stat", lambda dev: {
                "/mnt/data/a": Mock(st_dev=1),
                "/mnt/data/b": Mock(st_dev=1),
            }[dev]):
        middleware = Mock()

        verrors = Mock()

        SharingNFSService(middleware).validate_hosts_and_networks(
            [{
                "paths": ["/mnt/data/a"],
                "hosts": [],
                "networks": ["192.168.100.0/24"],
                "alldirs": False,
            }],
            {
                "paths": ["/mnt/data/b"],
                "hosts": [],
                "networks": ["192.168.100.0/25", "192.168.100.128/25"],
                "alldirs": False,
            },
            "sharingnfs_update",
            verrors,
            {},
        )

        assert verrors.add.call_args_list == [
            call(
                'sharingnfs_update.networks.0',
                "You can't share same filesystem with overlapping networks 192.168.100.0/25 and 192.168.100.0/24. "
                "This is so because /etc/exports does not act like ACL and it is undefined which rule among all "
                "overlapping networks will be applied."),
            call(
                'sharingnfs_update.networks.1',
                "You can't share same filesystem with overlapping networks 192.168.100.128/25 and 192.168.100.0/24"
            )
        ]
示例#8
0
def test__sharing_nfs_service__validate_paths__mountpoint_and_subdirectory():
    with patch(
            "middlewared.plugins.nfs.os.stat", lambda dev: {
                "/mnt": Mock(st_dev=0),
                "/mnt/data-1": Mock(st_dev=1),
                "/mnt/data-1/a": Mock(st_dev=1),
            }[dev]):
        middleware = Mock()

        verrors = Mock()

        SharingNFSService(middleware).validate_paths(
            {
                "paths": ["/mnt/data-1", "/mnt/data-1/a"],
                "alldirs": False,
            },
            "sharingnfs_update",
            verrors,
        )

        verrors.add.assert_called_once_with(
            "sharingnfs_update.paths.0",
            "You cannot share a mount point and subdirectories all at once")
示例#9
0
def test__sharing_nfs_service__validate_paths__not_same_filesystem():
    with patch(
            "middlewared.plugins.nfs.os.stat", lambda dev: {
                "/mnt/data-1": Mock(st_dev=1),
                "/mnt/data-2": Mock(st_dev=2),
                "/mnt/data-1/d": Mock(st_dev=1),
                "/mnt/data-2/d": Mock(st_dev=2),
            }[dev]):
        middleware = Mock()

        verrors = Mock()

        SharingNFSService(middleware).validate_paths(
            {
                "paths": ["/mnt/data-1/d", "/mnt/data-2/d"],
            },
            "sharingnfs_update",
            verrors,
        )

        verrors.add.assert_called_once_with(
            "sharingnfs_update.paths.1",
            "Paths for a NFS share must reside within the same filesystem")