예제 #1
0
    def test_create_fileset_call(self):
        '''
        Tests the call parameters with which create_fileset calls create_dataset
        '''
        def mock_create_dataset(myself,
                                name,
                                dataset_type=DatasetType.FILESET,
                                properties=None,
                                metadata_properties=None,
                                mount_helper=None,
                                sparse=False,
                                size=None,
                                recursive=False):
            assert name == 'test/testfs'
            assert dataset_type == DatasetType.FILESET
            assert properties == {'test': 'test', 'mountpoint': '/test/testfs'}
            assert metadata_properties is None
            assert mount_helper is None
            assert sparse is False
            assert size is None
            assert recursive is False
            return Dataset(name='testfs',
                           full_path='test/testfs',
                           pool='test',
                           parent='test',
                           type=dataset_type)

        with patch.object(ZFS, 'create_dataset', new=mock_create_dataset):
            zfs = ZFS()
            ds = zfs.create_fileset('test/testfs',
                                    mountpoint='/test/testfs',
                                    properties=dict(test='test'),
                                    recursive=False)
            assert ds.name == 'testfs'
예제 #2
0
    def test_get_properties_poolname_nometa_happy(self):
        def mock_get_properties(myself, dataset, include_metadata):
            assert dataset == 'tank'
            assert include_metadata is False

        with patch.object(ZFS, '_get_properties', new=mock_get_properties):
            zfs = ZFS()
            zfs.get_properties('tank')
예제 #3
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)
예제 #4
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')
예제 #5
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)
예제 #6
0
    def test_set_property_poolname_invalid_nometa_unhappy(self):
        def mock_set_property(myself, dataset, key, value, is_metadata):
            assert False, 'This should not have been called'

        with patch.object(ZFS, '_set_property', new=mock_set_property):
            zfs = ZFS()
            with pytest.raises(ValidationError) as excinfo:
                zfs.set_property(' ', 'compression', 'lz4')
            assert 'malformed' in str(excinfo.value)
예제 #7
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')
예제 #8
0
    def test_set_property_nometa_happy(self):
        def mock_set_property(myself, dataset, key, value, is_metadata):
            assert dataset == 'tank/test'
            assert key == 'compression'
            assert value == 'lz4'
            assert not is_metadata

        with patch.object(ZFS, '_set_property', new=mock_set_property):
            zfs = ZFS()
            zfs.set_property('tank/test', 'compression', 'lz4')
예제 #9
0
    def test_set_property_all_meta_happy(self):
        def mock_set_property(myself, dataset, key, value, is_metadata):
            assert 'tank/test' == dataset
            assert 'testns:all' == key
            assert 'test' == value
            assert is_metadata

        with patch.object(ZFS, '_set_property', new=mock_set_property):
            zfs = ZFS(metadata_namespace='testns')
            zfs.set_property('tank/test', 'all', 'test', metadata=True)
예제 #10
0
    def test_get_properties_dataset_unhappy(self):
        '''
        Tests that it validates the dataset name
        '''
        def mock_get_properties(myself, dataset, include_metadata):
            assert False, 'this should not have been called'

        with patch.object(ZFS, '_get_properties', new=mock_get_properties):
            zfs = ZFS()
            with pytest.raises(ValidationError):
                zfs.get_properties('as#df/tank')
예제 #11
0
    def test_set_property_meta_ns_noflag_inalid(self):
        def mock_set_property(myself, dataset, key, value, is_metadata):
            assert False, 'This should not have been called'

        with patch.object(ZFS, '_set_property', new=mock_set_property):
            zfs = ZFS(metadata_namespace='testns')
            with pytest.raises(ValidationError):
                zfs.set_property('tank/test',
                                 'testns:testprop',
                                 'testval',
                                 metadata=False)
예제 #12
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)
예제 #13
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')
예제 #14
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)
예제 #15
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)
예제 #16
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)
예제 #17
0
    def test_set_property_meta_overwrite_invalidns_unhappy(self):
        def mock_set_property(myself, dataset, key, value, is_metadata):
            assert False, 'This should not have been called'

        with patch.object(ZFS, '_set_property', new=mock_set_property):
            zfs = ZFS(metadata_namespace='pytest')
            with pytest.raises(ValidationError) as excinfo:
                zfs.set_property('tank/test',
                                 'test',
                                 'test',
                                 metadata=True,
                                 overwrite_metadata_namespace=' ')
            assert 'not match' in str(excinfo.value)
예제 #18
0
    def test_set_property_nometa_nons_unhappy(self):
        def mock_set_property(myself, dataset, key, value, is_metadata):
            assert False, 'This should not have been called'

        with patch.object(ZFS, '_set_property', new=mock_set_property):
            zfs = ZFS()
            assert zfs.metadata_namespace is None
            with pytest.raises(ValidationError) as excinfo:
                zfs.set_property('tank/test',
                                 'testprop',
                                 'testval',
                                 metadata=True)
            assert 'no metadata namespace set' in str(excinfo.value)
예제 #19
0
    def test_set_property_meta_nsoverwrite_happy(self):
        def mock_set_property(myself, dataset, key, value, is_metadata):
            assert dataset == 'tank/test'
            assert key == 'testns:testprop'
            assert value == 'testval'
            assert is_metadata

        with patch.object(ZFS, '_set_property', new=mock_set_property):
            zfs = ZFS(metadata_namespace='pytest')
            zfs.set_property('tank/test',
                             'testprop',
                             'testval',
                             metadata=True,
                             overwrite_metadata_namespace='testns')
예제 #20
0
    def test_create_volume_call(self):
        '''
        Tests the call parameters with which create_volume calls create_dataset
        '''
        def mock_create_dataset(myself,
                                name,
                                dataset_type=DatasetType.FILESET,
                                properties=None,
                                metadata_properties=None,
                                mount_helper=None,
                                sparse=False,
                                size=None,
                                recursive=False):
            assert name == 'test/testvol'
            assert dataset_type == DatasetType.VOLUME
            assert properties == {'test': 'test', 'blocksize': str(64 * 1024)}
            assert metadata_properties is None
            assert mount_helper is None
            assert sparse is True
            assert size == 1024 * 1024 * 1024
            assert recursive is False
            return Dataset(name='testvol',
                           full_path='test/testvol',
                           pool='test',
                           parent='test',
                           type=dataset_type)

        with patch.object(ZFS, 'create_dataset', new=mock_create_dataset):
            zfs = ZFS()
            ds = zfs.create_volume('test/testvol',
                                   size=1024 * 1024 * 1024,
                                   sparse=True,
                                   blocksize=64 * 1024,
                                   properties=dict(test='test'),
                                   recursive=False)
            assert ds.name == 'testvol'
예제 #21
0
 def test_notimplemented(self):
     zfs = ZFS()
     with pytest.raises(NotImplementedError):
         zfs.get_dataset_info('name')
     with pytest.raises(NotImplementedError):
         zfs.create_bookmark('snap@shot', 'test')
     with pytest.raises(NotImplementedError):
         zfs.list_datasets()
     with pytest.raises(NotImplementedError):
         zfs.create_dataset('tank/test5')
     with pytest.raises(NotImplementedError):
         zfs.destroy_dataset('tank/test6')
예제 #22
0
 def test_get_property_notimplemented(self):
     zfs = ZFS()
     with pytest.raises(NotImplementedError):
         zfs.get_property('tank/test1', 'compression')
예제 #23
0
 def test_get_pe_helper_set_valid(self):
     zfs = ZFS()
     assert zfs.pe_helper is None
     zfs.pe_helper = PEHelperBase()
     assert zfs.pe_helper is not None
     assert isinstance(zfs.pe_helper, PEHelperBase)
예제 #24
0
 def test_get_properties_notimplemented(self):
     zfs = ZFS()
     with pytest.raises(NotImplementedError):
         zfs.get_properties('tank/test')
예제 #25
0
 def test_get_pe_helper_default(self):
     zfs = ZFS()
     assert zfs.pe_helper is None
예제 #26
0
 def test_set_metadata_namespace(self):
     zfs = ZFS(metadata_namespace='prod')
     zfs.metadata_namespace = 'pytest'
     assert zfs.metadata_namespace == 'pytest'
예제 #27
0
 def test_init_noparam(self):
     assert ZFS()
예제 #28
0
 def test_get_metadata_namespace(self):
     zfs = ZFS(metadata_namespace='pytest')
     assert zfs.metadata_namespace == 'pytest'
예제 #29
0
 def test_set_property_all_nometa_unhappy(self):
     zfs = ZFS()
     with pytest.raises(ValidationError) as excinfo:
         zfs.set_property('tank/test', 'all', 'test')
     assert 'valid property name' in str(excinfo.value)