Пример #1
0
 def test_validation(self):
     config = Config(ad_hoc_config=self.CONFIG)
     module_configuration = {'path': '/var/tmp'}
     self.assertEqual(
         {
             'bandwidthRead': 0,
             'bandwidthWrite': 0,
             'consistencyCheckWrites': False,
             'path': '/var/tmp',
             'simultaneousReads': 3,
             'simultaneousWrites': 3,
             'simultaneousRemovals': 5,
         },
         config.validate(module='benji.storage.file',
                         config=module_configuration))
     module_configuration = {'asdasdas': 'dasdasd'}
     self.assertRaises(
         ConfigurationError,
         lambda: config.validate(module='benji.storage.file',
                                 config=module_configuration))
     module_configuration = {}
     self.assertRaises(
         ConfigurationError,
         lambda: config.validate(module='benji.storage.file',
                                 config=module_configuration))
     module_configuration = {'path': '/var/tmp', 'bandwidthRead': -1}
     self.assertRaises(
         ConfigurationError,
         lambda: config.validate(module='benji.storage.file',
                                 config=module_configuration))
     module_configuration = {'path': [1, 2, 3]}
     self.assertRaises(
         ConfigurationError,
         lambda: config.validate(module='benji.storage.file',
                                 config=module_configuration))
Пример #2
0
    def _import_modules(cls, config: Config, modules: ConfigList) -> None:
        for index, module_dict in enumerate(modules):
            module = Config.get_from_dict(module_dict,
                                          'module',
                                          types=str,
                                          full_name_override=modules.full_name,
                                          index=index)
            name = Config.get_from_dict(module_dict,
                                        'name',
                                        types=str,
                                        full_name_override=modules.full_name,
                                        index=index)
            configuration = Config.get_from_dict(module_dict,
                                                 'configuration',
                                                 None,
                                                 types=dict,
                                                 full_name_override=modules.full_name,
                                                 index=index)

            if name in cls._modules:
                raise ConfigurationError('Duplicate name "{}" in list {}.'.format(name, modules.full_name))

            module = importlib.import_module('{}.{}'.format(__package__, module))
            try:
                configuration = config.validate(module=module.__name__, config=configuration)
            except ConfigurationError as exception:
                raise ConfigurationError('Configuration for IO {} is invalid.'.format(name)) from exception
            cls._modules[name] = _IOFactoryModule(module=module,
                                                  arguments={
                                                      'config': config,
                                                      'name': name,
                                                      'module_configuration': configuration
                                                  })
Пример #3
0
    def _import_modules(cls, config: Config, modules: ConfigList) -> None:
        for index, module_dict in enumerate(modules):
            module = Config.get_from_dict(module_dict,
                                          'module',
                                          types=str,
                                          full_name_override=modules.full_name,
                                          index=index)
            name = Config.get_from_dict(module_dict,
                                        'name',
                                        types=str,
                                        full_name_override=modules.full_name,
                                        index=index)
            storage_id = Config.get_from_dict(
                module_dict,
                'storageId',
                types=int,
                full_name_override=modules.full_name,
                index=index)
            configuration = Config.get_from_dict(
                module_dict,
                'configuration',
                None,
                types=dict,
                full_name_override=modules.full_name,
                index=index)

            if name in cls._name_to_storage_id:
                raise ConfigurationError(
                    'Duplicate name "{}" in list {}.'.format(
                        name, modules.full_name))

            if storage_id in cls._storage_id_to_name:
                raise ConfigurationError('Duplicate id {} in list {}.'.format(
                    storage_id, modules.full_name))

            module = importlib.import_module('{}.{}.{}'.format(
                __package__, cls._MODULE, module))
            try:
                configuration = config.validate(module=module.__name__,
                                                config=configuration)
            except ConfigurationError as exception:
                raise ConfigurationError(
                    'Configuration for storage {} is invalid.'.format(
                        name)) from exception
            cls._modules[storage_id] = _StorageFactoryModule(
                module=module,
                arguments={
                    'config': config,
                    'name': name,
                    'storage_id': storage_id,
                    'module_configuration': configuration
                })
            cls._name_to_storage_id[name] = storage_id
            cls._storage_id_to_name[storage_id] = name
Пример #4
0
 def test_validation_io_rbd(self):
     config = Config(ad_hoc_config=self.CONFIG)
     module_configuration = config.get('ios')[0]['configuration']
     self.assertEqual(
         {
             'cephConfigFile':
             '/etc/ceph/ceph.conf',
             'clientIdentifier':
             'admin',
             'newImageFeatures':
             ['RBD_FEATURE_LAYERING', 'RBD_FEATURE_EXCLUSIVE_LOCK'],
             'simultaneousReads':
             10,
             'simultaneousWrites':
             10,
         },
         config.validate(module='benji.io.rbd',
                         config=module_configuration))
     module_configuration['newImageFeatures'] = ['ASASA', 'DDASAD']
     self.assertRaises(
         ConfigurationError,
         lambda: config.validate(module='benji.io.rbd',
                                 config=module_configuration))