Ejemplo n.º 1
0
 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
Ejemplo n.º 2
0
 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)
     return self._schema
Ejemplo n.º 3
0
    def __init__(self):
        paths = [vdsmapi.find_schema()]
        if _glusterEnabled:
            paths.append(vdsmapi.find_schema('vdsm-api-gluster'))
        self._schema = vdsmapi.Schema(paths)

        self._threadLocal = threading.local()
        self.log = logging.getLogger('DynamicBridge')
Ejemplo n.º 4
0
 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()
Ejemplo n.º 5
0
    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')
Ejemplo n.º 6
0
    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')
Ejemplo n.º 7
0
 def __init__(self, client, xml_compat):
     self._schema = vdsmapi.Schema([vdsmapi.find_schema()])
     self._client = client
     self._xml_compat = xml_compat
     self._default_timeout = CALL_TIMEOUT
     self._timeouts = {
         'migrationCreate': config.getint(
             'vars', 'migration_create_timeout'),
     }
Ejemplo n.º 8
0
 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'),
     }
Ejemplo n.º 9
0
 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'),
     }
Ejemplo n.º 10
0
    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)
Ejemplo n.º 11
0
 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
Ejemplo n.º 12
0
 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
Ejemplo n.º 13
0
    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)
Ejemplo n.º 14
0
 def _getAPI(self):
     paths = [vdsmapi.find_schema()]
     return vdsmapi.Schema(paths)
Ejemplo n.º 15
0
 def _getAPI(self):
     paths = [vdsmapi.find_schema()]
     return vdsmapi.Schema(paths, True)