Beispiel #1
0
    def test_property_dataset_validation_unhappy(self):
        def mock_get_property(myself, dataset, key, is_metadata):
            assert False, 'this should not have been called'

        with patch.object(ZFS, '_get_property', new=mock_get_property):
            zfs = ZFS()
            with pytest.raises(ValidationError):
                zfs.get_property('tan#k/test', 'compression')
Beispiel #2
0
 def test_get_property_all(self):
     '''
     Uses "all" and expects a ValidationError.
     '''
     zfs = ZFS()
     with pytest.raises(ValidationError) as excinfo:
         zfs.get_property('tank/test', 'all')
     assert 'get_properties' in str(excinfo.value)
Beispiel #3
0
    def test_get_property_meta_ns_happy(self):
        def mock_get_property(myself, dataset, key, is_metadata):
            assert dataset == 'tank/test'
            assert key == 'testns:testprop'
            assert is_metadata is True

        with patch.object(ZFS, '_get_property', new=mock_get_property):
            zfs = ZFS(metadata_namespace='testns')
            zfs.get_property('tank/test', 'testprop', metadata=True)
Beispiel #4
0
    def test_get_property_nometa_happy(self):
        def mock_get_property(myself, dataset: str, key: str,
                              is_metadata: bool):
            assert dataset == 'tank/test'
            assert key == 'compression'
            assert is_metadata is False

        with patch.object(ZFS, '_get_property', new=mock_get_property):
            zfs = ZFS()
            zfs.get_property('tank/test', 'compression')
Beispiel #5
0
    def test_get_property_meta_nooverwrite_invalidns_unhappy(self):
        '''
        Tests the validation of the metadata namespace, coming from the ctor.
        '''
        def mock_get_property(myself, dataset, key, is_metadata):
            assert False, 'This should not have been called'

        with patch.object(ZFS, '_get_property', new=mock_get_property):
            zfs = ZFS(metadata_namespace=' ')
            with pytest.raises(ValidationError) as excinfo:
                zfs.get_property('tank/test', 'test', metadata=True)
            assert 'not match' in str(excinfo.value)
Beispiel #6
0
    def test_get_property_all_meta(self):
        '''
        Tests that <namespace>:all is allowed.
        '''
        def mock_get_property(myself, dataset, key, is_metadata):
            assert dataset == 'tank/test'
            assert key == 'testns:all'
            assert is_metadata is True

        with patch.object(ZFS, '_get_property', new=mock_get_property):
            zfs = ZFS(metadata_namespace='testns')
            zfs.get_property('tank/test', 'all', metadata=True)
Beispiel #7
0
    def test_get_property_poolname_invalid_nometa_unhappy(self):
        '''
        Tests the pool name validation.
        '''
        def mock_get_property(myself, dataset, key, is_meta):
            assert False, 'This should not have been called'

        with patch.object(ZFS, '_get_property', new=mock_get_property):
            zfs = ZFS()
            with pytest.raises(ValidationError) as excinfo:
                zfs.get_property(' ', 'compression')
            assert 'malformed' in str(excinfo.value)
Beispiel #8
0
    def test_get_property_poolname_nometa_happy(self):
        '''
        Tests that the name of the pool (first or root dataset) can be queried.
        '''
        def mock_get_property(myself, dataset, key, is_metadata):
            assert dataset == 'tank'
            assert key == 'compression'
            assert is_metadata is False

        with patch.object(ZFS, '_get_property', new=mock_get_property):
            zfs = ZFS()
            zfs.get_property('tank', 'compression')
Beispiel #9
0
    def test_get_property_meta_ns_noflag_invalid(self):
        '''
        Tests that it bails out if the syntax indicates a metadata property is requested but metadata flag is false.
        '''
        def mock_get_property(myself, dataset, key, is_metadata):
            assert False, 'This should not have been called'

        with patch.object(ZFS, '_get_property', new=mock_get_property):
            zfs = ZFS(metadata_namespace='testns')
            with pytest.raises(ValidationError):
                zfs.get_property('tank/test',
                                 'testns:testprop',
                                 metadata=False)
Beispiel #10
0
    def test_get_property_nometa_nons_unhappy(self):
        '''
        Tests that it bails out if no metadata namespace has been set and none is given.
        '''
        def mock_get_property(myself, dataset, key, is_metadata):
            assert False, 'This should not have been called'

        with patch.object(ZFS, '_get_property', new=mock_get_property):
            zfs = ZFS()
            assert zfs.metadata_namespace is None
            with pytest.raises(ValidationError) as excinfo:
                zfs.get_property('tank/test', 'testprop', metadata=True)
            assert 'no metadata namespace set' == str(excinfo.value)
Beispiel #11
0
 def test_get_property_notimplemented(self):
     zfs = ZFS()
     with pytest.raises(NotImplementedError):
         zfs.get_property('tank/test1', 'compression')