def get_node_resource_adapter_config(self, node: Node) \ -> Dict[str, Any]: """ Deserialize resource adapter configuration to key/value pairs """ # # Default settings dict is blank # config: Dict[str, str] = {} # # Load settings from class settings definitions if any of them # have default values # config.update(self._load_config_from_class()) # # Load settings from default profile in database, if it exists # config.update(self._load_config_from_database()) # # Load node specific settings # override_config: Dict[str, Any] = {} if node.instance and \ node.instance.resource_adapter_configuration and \ node.instance.resource_adapter_configuration.name != 'Default': for c in node.instance.resource_adapter_configuration.configuration: override_config[c.key] = c.value config.update(override_config) # # Dump the config with transformed values. Don't bother validating # here, as we will consider the node already exists in it's current # state # try: validator = ConfigurationValidator(self.settings) validator.load(config) processed_config: Dict[str, Any] = validator.dump() except ValidationError as ex: raise ConfigurationError(str(ex)) # # Perform any required additional processing on the config # self.process_config(processed_config) return processed_config
def test_dump(): s = { 'bool': settings.BooleanSetting(), 'list_bool': settings.BooleanSetting(list=True), 'integer': settings.IntegerSetting(), 'list_integer': settings.IntegerSetting(list=True), 'string': settings.StringSetting(), 'list_string': settings.StringSetting(list=True), 'file': settings.FileSetting(must_exist=False) } p = ConfigurationValidator(s) # # Test data loading # data_to_load = { 'bool': 'True', 'list_bool': 'True, false', 'integer': '3', 'list_integer': '4, 5', 'string': 'abc', 'list_string': 'wz, yz', 'file': 'file.txt' } p.load(data_to_load) # # Perform full validation # p.validate(full=True) # # Assert that dumped data is properly transformed # expected_data = { 'bool': True, 'list_bool': [True, False], 'integer': 3, 'list_integer': [4, 5], 'string': 'abc', 'list_string': ['wz', 'yz'], 'file': 'file.txt' } assert p.dump() == expected_data