def perform_check(self, data): missing_keys = ContextSchemaChecker.get_missing_keys(self, data, self.req_keys) if missing_keys: msg = "Missing key(s): " + ', '.join(str(key) for key in missing_keys) raise SchemaError(msg) valid_keys = self.req_keys + self.opt_keys invalid_keys = ContextSchemaChecker.get_invalid_keys(self, data, valid_keys) if invalid_keys: msg = "Unknown key(s): " + ', '.join(str(key) for key in invalid_keys) raise SchemaError(msg) return True
def perform_check(self, data): missing_keys = ContextSchemaChecker.get_missing_keys( self, data, self.req_keys) if missing_keys: msg = "Missing key(s): " + ', '.join( str(key) for key in missing_keys) raise SchemaError(msg) valid_keys = self.req_keys + self.opt_keys invalid_keys = ContextSchemaChecker.get_invalid_keys( self, data, valid_keys) if invalid_keys: msg = "Unknown key(s): " + ', '.join( str(key) for key in invalid_keys) raise SchemaError(msg) return True
def check_node_def(node_defs): for nodename, node_def in list(node_defs.items()): if ':' not in nodename or nodename.split(':', 1)[0] != 'node_def': context = "[SchemaCheck] ERROR in node %r: " % nodename msg = "Node definition must begin with 'node_def:<nodename>'!" raise SchemaError(msg, context) realnodename = nodename.split(':', 1)[1] if type(node_def) != list: context = "[SchemaCheck] ERROR in node %r: " % realnodename msg = "Node definition has to be a list of dictionaries!" raise SchemaError(msg, context) for node in node_def: #check for invalid sections: for key in node: if key not in [ "resource", "config_management", "contextualisation", "health_check" ]: context = "[SchemaCheck] ERROR in node %r: " % realnodename msg = "Invalid section %r" % key raise SchemaError(msg, context) nodeindex = node_def.index(node) #resource section try: if 'resource' not in node: raise SchemaError("Missing 'resource' section!") else: resource = node['resource'] if 'type' not in resource: raise SchemaError("Missing key \'type\'") else: protocol = resource['type'] libname = "occo.plugins.resourcehandler." + protocol importlib.import_module(libname) checker = RHSchemaChecker.instantiate( protocol=protocol) checker.perform_check(resource) except SchemaError as e: context = "[SchemaCheck] ERROR in 'resource' section of node %r[%d]: " % ( realnodename, nodeindex) raise SchemaError(e.msg, context) #config_manager section try: if 'config_management' in node: cm = node['config_management'] if 'type' not in cm: raise SchemaError("Missing key \'type\'!") else: protocol = cm['type'] libname = "occo.plugins.configmanager." + protocol importlib.import_module(libname) checker = CMSchemaChecker.instantiate( protocol=protocol) checker.perform_check(cm) except SchemaError as e: context = "[SchemaCheck] ERROR in 'config_management' section of node %r[%d]: " % ( realnodename, nodeindex) raise SchemaError(e.msg, context) #contextualization section try: if 'contextualisation' in node: cont = node['contextualisation'] if 'type' not in cont: raise SchemaError("Missing key \'type\'!") else: protocol = cont['type'] libname = "occo.plugins.infraprocessor.node_resolution." + protocol importlib.import_module(libname) checker = ContextSchemaChecker.instantiate( protocol=protocol) checker.perform_check(cont) except SchemaError as e: context = "[SchemaCheck] ERROR in 'contextualisation' section of node %r[%d]: " % ( realnodename, nodeindex) raise SchemaError(e.msg, context) #health_check section try: if 'health_check' in node: hc = node['health_check'] if 'type' not in hc: hc['type'] = 'basic' if hc['type'] == 'basic': libname = "occo.infraprocessor.synchronization" else: libname = "occo.infraprocessor.synchronization." + hc[ 'type'] importlib.import_module(libname) checker = HCSchemaChecker.instantiate( protocol=hc['type']) checker.perform_check(hc) except SchemaError as e: context = "[SchemaCheck] ERROR in 'health_check' section of node %r[%d]: " % ( realnodename, nodeindex) raise SchemaError(e.msg, context)
def check_node_def(node_defs): for nodename, node_def in node_defs.iteritems(): if ':' not in nodename or nodename.split(':', 1)[0] != 'node_def': context = "[SchemaCheck] ERROR in node %r: " % nodename msg = "Node definition must begin with 'node_def:<nodename>'!" raise SchemaError(msg, context) realnodename = nodename.split(':', 1)[1] if type(node_def) != list: context = "[SchemaCheck] ERROR in node %r: " % realnodename msg = "Node definition has to be a list of dictionaries!" raise SchemaError(msg, context) for node in node_def: #check for invalid sections: for key in node: if key not in ["resource", "config_management", "contextualisation", "health_check"]: context = "[SchemaCheck] ERROR in node %r: " % realnodename msg = "Invalid section %r" % key raise SchemaError(msg, context) nodeindex = node_def.index(node) #resource section try: if 'resource' not in node: raise SchemaError("Missing 'resource' section!") else: resource = node['resource'] if 'type' not in resource: raise SchemaError("Missing key \'type\'") else: protocol = resource['type'] libname = "occo.plugins.resourcehandler." + protocol importlib.import_module(libname) checker = RHSchemaChecker.instantiate(protocol=protocol) checker.perform_check(resource) except SchemaError as e: context = "[SchemaCheck] ERROR in 'resource' section of node %r[%d]: " % (realnodename, nodeindex) raise SchemaError(e.msg, context) #config_manager section try: if 'config_management' in node: cm = node['config_management'] if 'type' not in cm: raise SchemaError("Missing key \'type\'!") else: protocol = cm['type'] libname = "occo.plugins.configmanager." + protocol importlib.import_module(libname) checker = CMSchemaChecker.instantiate(protocol=protocol) checker.perform_check(cm) except SchemaError as e: context = "[SchemaCheck] ERROR in 'config_management' section of node %r[%d]: " % (realnodename, nodeindex) raise SchemaError(e.msg, context) #contextualization section try: if 'contextualisation' in node: cont = node['contextualisation'] if 'type' not in cont: raise SchemaError("Missing key \'type\'!") else: protocol = cont['type'] libname = "occo.plugins.infraprocessor.node_resolution." + protocol importlib.import_module(libname) checker = ContextSchemaChecker.instantiate(protocol=protocol) checker.perform_check(cont) except SchemaError as e: context = "[SchemaCheck] ERROR in 'contextualisation' section of node %r[%d]: " % (realnodename, nodeindex) raise SchemaError(e.msg, context) #health_check section try: if 'health_check' in node: hc = node['health_check'] if 'type' not in hc: hc['type'] = 'basic' if hc['type'] == 'basic': libname = "occo.infraprocessor.synchronization" else: libname = "occo.infraprocessor.synchronization." + hc['type'] importlib.import_module(libname) checker = HCSchemaChecker.instantiate(protocol=hc['type']) checker.perform_check(hc) except SchemaError as e: context = "[SchemaCheck] ERROR in 'health_check' section of node %r[%d]: " % (realnodename, nodeindex) raise SchemaError(e.msg, context)