Exemplo n.º 1
0
def _check_and_init_version_control(meta):
    try:
        for table in ('schedules', 'schedule_metadata', 'jobs', 'job_metadata',
                      'job_faults', 'workers'):
            assert table in meta.tables

        # NOTE(venkatesh): if the existing db has already got the base tables,
        # set the version for migration to '6' as the first six version_scripts
        # are used for creating the base tables.
        return version_control(6)
    except AssertionError:
        msg = _("Unable to get the db_version. Reason: Unknown DB State.")
        raise exception.QonosException(msg)
Exemplo n.º 2
0
def db_sync(version=None):
    """
    Place a database under migration control and perform an upgrade

    :retval version number
    """
    if version is not None:
        try:
            version = int(version)
        except ValueError:
            raise exception.QonosException(_("version should be an integer"))

    current_version = int(db_version())
    if version is None or version > current_version:
        return upgrade(version=version)
    else:
        return downgrade(version=version)
Exemplo n.º 3
0
    def __get_backend(self):
        if not self.__backend:
            if self.__config_group is None:
                backend_name = CONF[self.__pivot]
            else:
                backend_name = CONF[self.__config_group][self.__pivot]
            if backend_name not in self.__backends:
                msg = _('Invalid backend: %s') % backend_name
                raise exc.QonosException(msg)

            backend = self.__backends[backend_name]
            if isinstance(backend, tuple):
                name = backend[0]
                fromlist = backend[1]
            else:
                name = backend
                fromlist = backend

            self.__backend = __import__(name, None, None, fromlist)
        return self.__backend