def _init_schema(self, gluster_enabled): try: schema_paths = [vdsmapi.find_schema()] if gluster_enabled: schema_paths.append(vdsmapi.find_schema('vdsm-api-gluster')) self._schema = vdsmapi.Schema(schema_paths, False) self._event_schema = vdsmapi.Schema( [vdsmapi.find_schema('vdsm-events')], False) except vdsmapi.SchemaNotFound as e: raise MissingSchemaError(e)
def test_cached_schema(self): with namedTemporaryDir() as dir: with MonkeyPatchScope([(vdsmapi, "VDSM_CACHE_DIR", dir)]): paths = vdsmapi.find_all_schemas() # creates the schema files from yaml uncached_schema = vdsmapi.Schema(paths, True) # creates the schema files from cache vdsmapi.create_cache() cached_schema = vdsmapi.Schema(paths, True) self.assertEqual(cached_schema._methods, uncached_schema._methods) self.assertEqual(cached_schema._types, uncached_schema._types)
def __init__(self): paths = [vdsmapi.find_schema()] api_strict_mode = config.getboolean('devel', 'api_strict_mode') if _glusterEnabled: paths.append(vdsmapi.find_schema('vdsm-api-gluster')) self._schema = vdsmapi.Schema(paths, api_strict_mode) self._event_schema = vdsmapi.Schema( [vdsmapi.find_schema('vdsm-events')], api_strict_mode) self._threadLocal = threading.local() self.log = logging.getLogger('DynamicBridge')
def schema(self): if self._schema is None: paths = [vdsmapi.find_schema()] if _glusterEnabled: paths.append(vdsmapi.find_schema('vdsm-api-gluster')) self._schema = vdsmapi.Schema(paths, True) return self._schema
def find_schema(): try: schema_paths = [vdsmapi.find_schema()] schema = vdsmapi.Schema(schema_paths, False) except vdsmapi.SchemaNotFound as e: raise client.MissingSchemaError(e) return schema
def main(): schema = sys.argv[1] output = sys.argv[2] api_schema = vdsmapi.Schema([schema], False) create_doc(api_schema, output)
def find_schema(gluster_enabled=False): try: schema_paths = [vdsmapi.find_schema()] if gluster_enabled: schema_paths.append(vdsmapi.find_schema('vdsm-api-gluster')) schema = vdsmapi.Schema(schema_paths, False) except vdsmapi.SchemaNotFound as e: raise client.MissingSchemaError(e) return schema
def __init__(self, client, xml_compat): api_strict_mode = config.getboolean('devel', 'api_strict_mode') self._schema = vdsmapi.Schema([vdsmapi.find_schema()], api_strict_mode) self._client = client self._xml_compat = xml_compat self._default_timeout = CALL_TIMEOUT self._timeouts = { 'migrationCreate': config.getint('vars', 'migration_create_timeout'), }
def __init__(self, client, default_timeout, gluster_enabled=False): self._client = client self._default_timeout = default_timeout try: schema_paths = [vdsmapi.find_schema()] if gluster_enabled: schema_paths.append(vdsmapi.find_schema('vdsm-api-gluster')) self._schema = vdsmapi.Schema(schema_paths, False) except vdsmapi.SchemaNotFound as e: raise MissingSchemaError(e) self._create_namespaces()
def main(): parser = argparse.ArgumentParser( "A schema definition to HTML documentation converter") parser.add_argument("schema_type", choices=[st.value for st in vdsmapi.SchemaType]) parser.add_argument("html_path") args = parser.parse_args(sys.argv[1:]) schema_type = vdsmapi.SchemaType(args.schema_type) api_schema = vdsmapi.Schema((schema_type, ), strict_mode=False) create_doc(api_schema, args.html_path)
def events_schema(self): if self._events_schema is None: path = [vdsmapi.find_schema('vdsm-events')] self._events_schema = vdsmapi.Schema(path, True) return self._events_schema
def _getAPI(self): paths = [vdsmapi.find_schema()] return vdsmapi.Schema(paths, True)
def _validate(self, api_mod): with schema_not_found(): path = vdsmapi.find_schema() gluster_path = vdsmapi.find_schema('vdsm-api-gluster') schema = vdsmapi.Schema([path, gluster_path], True) for class_name, class_obj in self._get_api_classes(api_mod): apiObj = getattr(api_mod, class_name) ctorArgs = apiObj.ctorArgs ctor_defaults = [] spec_class = class_name if spec_class == 'Global': spec_class = 'Host' for method_name, method_obj in inspect.getmembers( class_obj, inspect.ismethod): cmd = '%s_%s' % (spec_class, method_name) if cmd in self.IGNORED_CMDS: continue # gather default args from ctor if method_name == '__init__': ctor_defaults = self._get_default_args(method_obj) continue # ignore private methods if method_name.startswith('_'): continue rep = vdsmapi.MethodRep(spec_class, method_name) try: # get args from schema method_args = schema.get_args(rep) except KeyError: raise AssertionError('Missing method %s' % rep) # inspect apiobj and gather args and default args args = ctorArgs + self._get_args(method_obj) default_args = ctor_defaults + self._get_default_args( method_obj) # check len equality if len(args) != len(method_args): raise AssertionError( self._prep_msg(rep, method_args, args)) for marg in method_args: # verify optional arg if 'defaultvalue' in marg: if not marg.get('name') in default_args: raise AssertionError( self._prep_msg(rep, method_args, args)) continue # verify args from schema in apiobj args if not marg.get('name') in args: raise AssertionError( self._prep_msg(rep, method_args, args)) try: # verify ret value with entry in command_info ret = schema.get_ret_param(rep) ret_info = Bridge.command_info.get(cmd, {}).get('ret') if not ret_info and not ret: continue if ret_info == 'status': continue if not ret_info or not ret: raise AssertionError('wrong return type: ' + cmd) except KeyError: raise AssertionError('Missing ret %s' % rep.id)