Exemplo n.º 1
0
    def cmd_init(self, options):
        """Creates and initializes a database"""
        # Create a database user before trying to connect
        if options.create_dbuser:
            if not options.username:
                raise SystemExit("This option requires a --username set")
            retval = self._create_dbuser(options.username)
            if retval != 0:
                return retval
        config = self._read_config(options,
                                   register_station=False,
                                   check_schema=False,
                                   load_plugins=False)

        from stoqlib.database.admin import initialize_system
        from stoqlib.database.settings import db_settings
        if options.dbname:
            db_settings.dbname = options.dbname
        if options.address:
            db_settings.address = options.address
        if options.port:
            db_settings.port = options.port
        if options.username:
            db_settings.username = options.username
        if options.password:
            db_settings.password = options.password

        try:
            initialize_system(password=unicode(options.password),
                              force=options.force,
                              empty=options.empty)
        except ValueError as e:
            # Database server is missing pg_trgm
            if 'pg_trgm' in str(e):
                return 31
            else:
                raise

        if options.create_examples or options.demo:
            from stoqlib.importers.stoqlibexamples import create
            create(utilities=True)

        if options.register_station and not options.empty:
            self._register_station()

        if options.plugins:
            self._enable_plugins(unicode(options.plugins).split(','))

        if options.demo:
            self._enable_demo()
        config.flush()
Exemplo n.º 2
0
    def cmd_init(self, options):
        """Creates and initializes a database"""
        # Create a database user before trying to connect
        if options.create_dbuser:
            if not options.username:
                raise SystemExit(
                    "This option requires a --username set")
            retval = self._create_dbuser(options.username)
            if retval != 0:
                return retval
        config = self._read_config(options, register_station=False,
                                   check_schema=False,
                                   load_plugins=False)

        from stoqlib.database.admin import initialize_system
        from stoqlib.database.settings import db_settings
        if options.dbname:
            db_settings.dbname = options.dbname
        if options.address:
            db_settings.address = options.address
        if options.port:
            db_settings.port = options.port
        if options.username:
            db_settings.username = options.username
        if options.password:
            db_settings.password = options.password

        try:
            initialize_system(password=unicode(options.password),
                              force=options.force, empty=options.empty)
        except ValueError as e:
            # Database server is missing pg_trgm
            if 'pg_trgm' in str(e):
                return 31
            else:
                raise

        if options.create_examples or options.demo:
            from stoqlib.importers.stoqlibexamples import create
            create(utilities=True)

        if options.register_station and not options.empty:
            self._register_station()

        if options.plugins:
            self._enable_plugins(unicode(options.plugins).split(','))

        if options.demo:
            self._enable_demo()
        config.flush()
Exemplo n.º 3
0
def bootstrap_suite(address=None,
                    dbname=None,
                    port=5432,
                    username=None,
                    password=u"",
                    station_name=None,
                    quick=False,
                    extra_plugins=None):
    """
    Test.
    :param address:
    :param dbname:
    :param port:
    :param username:
    :param password:
    :param station_name:
    :param quick:
    """
    os.environ['STOQ_TESTSUIT_RUNNING'] = '1'

    # This will only be required when we use uuid.UUID instances
    # for UUIDCol
    #import psycopg2.extras
    #psycopg2.extras.register_uuid()

    empty = provide_database_settings(dbname,
                                      address,
                                      port,
                                      username,
                                      password,
                                      createdb=not quick)

    # Reset the user settings (loaded from ~/.stoq/settings), so that user
    # preferences don't affect the tests.
    settings = get_settings()
    settings.reset()

    if quick and not empty:
        provide_utilities(station_name)
        _enable_plugins(extra_plugins=extra_plugins)
        return

    initialize_system(testsuite=True, force=True)

    # Commit before trying to apply patches which requires an exclusive lock
    # to all tables.
    _enable_plugins(extra_plugins=extra_plugins)
    ensure_admin_user(u"")
    create(utilities=True, create_users=True)
Exemplo n.º 4
0
def bootstrap_suite(address=None,
                    dbname=None,
                    port=5432,
                    username=None,
                    password=u"",
                    station_name=None,
                    quick=False):
    """
    Test.
    :param address:
    :param dbname:
    :param port:
    :param username:
    :param password:
    :param station_name:
    :param quick:
    """

    empty = provide_database_settings(dbname,
                                      address,
                                      port,
                                      username,
                                      password,
                                      create=not quick)

    # Reset the user settings (loaded from ~/.stoq/settings), so that user
    # preferences don't affect the tests.
    settings = get_settings()
    settings.reset()

    if quick and not empty:
        provide_utilities(station_name)
        return

    # XXX: Why clearing_cache if initialize_system will drop the
    # database?!
    ParameterAccess.clear_cache()

    initialize_system(testsuite=True, force=True)

    # Commit before trying to apply patches which requires an exclusive lock
    # to all tables.
    _enable_plugins()
    ensure_admin_user(u"")
    create(utilities=True)
Exemplo n.º 5
0
def bootstrap_suite(address=None, dbname=None, port=5432, username=None,
                    password=u"", station_name=None, quick=False):
    """
    Test.
    :param address:
    :param dbname:
    :param port:
    :param username:
    :param password:
    :param station_name:
    :param quick:
    """

    # This will only be required when we use uuid.UUID instances
    # for UUIDCol
    #import psycopg2.extras
    #psycopg2.extras.register_uuid()

    empty = provide_database_settings(dbname, address, port, username, password,
                                      create=not quick)

    # Reset the user settings (loaded from ~/.stoq/settings), so that user
    # preferences don't affect the tests.
    settings = get_settings()
    settings.reset()

    if quick and not empty:
        provide_utilities(station_name)
        _enable_plugins()
        return

    # XXX: Why clearing_cache if initialize_system will drop the
    # database?!
    ParameterAccess.clear_cache()

    initialize_system(testsuite=True, force=True)

    # Commit before trying to apply patches which requires an exclusive lock
    # to all tables.
    _enable_plugins()
    ensure_admin_user(u"")
    create(utilities=True)
Exemplo n.º 6
0
    def cmd_init(self, options):
        """Creates and initializes a database"""
        # Create a database user before trying to connect
        if options.create_dbuser:
            if not options.username:
                raise SystemExit("This option requires a --username set")
            retval = self._create_dbuser(options.username)
            if retval != 0:
                return retval
        config = self._read_config(options, register_station=False, check_schema=False, load_plugins=False)

        from stoqlib.database.admin import initialize_system
        from stoqlib.database.settings import db_settings

        if options.dbname:
            db_settings.dbname = options.dbname
        if options.address:
            db_settings.address = options.address
        if options.port:
            db_settings.port = options.port
        if options.username:
            db_settings.username = options.username
        if options.password:
            db_settings.password = options.password

        initialize_system(password=options.password or config.get_password(), force=options.force)

        if options.create_examples or options.demo:
            from stoqlib.importers.stoqlibexamples import create

            create(utilities=True)

        if options.register_station:
            self._register_station()

        if options.plugins:
            self._enable_plugins(unicode(options.plugins).split(","))

        if options.demo:
            self._enable_demo()
        config.flush()
Exemplo n.º 7
0
        def init():
            server = ServerProxy()
            running = yield server.check_running()
            if running:
                yield server.call('pause_tasks')
            # ServerProxy may have opened a store
            set_default_store(None)

            try:
                initialize_system(password=unicode(options.password),
                                  force=options.force, empty=options.empty)
            except ValueError as e:
                # Database server is missing pg_trgm
                if 'pg_trgm' in str(e):
                    api.asyncReturn(31)
                else:
                    raise

            if options.create_examples or options.demo:
                from stoqlib.importers.stoqlibexamples import create
                create(utilities=True)

            if options.register_station and not options.empty:
                self._register_station()

            if options.plugins:
                self._enable_plugins(unicode(options.plugins).split(','))

            if options.demo:
                self._enable_demo()

            config.flush()

            # The schema was upgraded. If it was running before,
            # restart it so it can load the new code
            if running:
                yield server.call('restart')
Exemplo n.º 8
0
    def cmd_init(self, options):
        """Creates and initializes a database"""
        # Create a database user before trying to connect
        if options.create_dbuser:
            if not options.username:
                raise SystemExit("This option requires a --username set")
            retval = self._create_dbuser(options.username)
            if retval != 0:
                return retval
        config = self._read_config(options,
                                   register_station=False,
                                   check_schema=False,
                                   load_plugins=False)

        from stoqlib.database.admin import initialize_system
        from stoqlib.database.runtime import set_default_store
        from stoqlib.database.settings import db_settings
        from stoqlib.lib.pgpass import write_pg_pass
        from stoqlib.net.server import ServerProxy
        if options.dbname:
            db_settings.dbname = options.dbname
        if options.address:
            db_settings.address = options.address
        if options.port:
            db_settings.port = options.port
        if options.username:
            db_settings.username = options.username
        if options.password:
            db_settings.password = options.password
            # a password was sent via command line. Make sure we can run psql by
            # setting up pgpass
            write_pg_pass(db_settings.dbname, db_settings.address,
                          db_settings.port, db_settings.username,
                          db_settings.password)

        server = ServerProxy()
        running = server.check_running()
        if running:
            server.call('pause_tasks')
        # ServerProxy may have opened a store
        set_default_store(None)

        try:
            initialize_system(password='',
                              force=options.force,
                              empty=options.empty)
        except ValueError as e:
            # Database server is missing pg_trgm
            if 'pg_trgm' in str(e):
                return 31
            else:
                raise

        if options.create_examples or options.demo:
            from stoqlib.importers.stoqlibexamples import create
            create(utilities=True)

        if options.register_station and not options.empty:
            self._register_station()

        if options.pre_plugins:
            self._register_plugins(str(options.pre_plugins).split(','))

        if options.plugins:
            self._enable_plugins(str(options.plugins).split(','))

        if options.demo:
            self._enable_demo()

        config.flush()

        # The schema was upgraded. If it was running before,
        # restart it so it can load the new code
        if running:
            server.call('restart')

        return 0
Exemplo n.º 9
0
    def cmd_init(self, options):
        """Creates and initializes a database"""
        # Create a database user before trying to connect
        if options.create_dbuser:
            if not options.username:
                raise SystemExit(
                    "This option requires a --username set")
            retval = self._create_dbuser(options.username)
            if retval != 0:
                return retval
        config = self._read_config(options, register_station=False,
                                   check_schema=False,
                                   load_plugins=False)

        from stoqlib.database.admin import initialize_system
        from stoqlib.database.runtime import set_default_store
        from stoqlib.database.settings import db_settings
        from stoqlib.net.server import ServerProxy
        if options.dbname:
            db_settings.dbname = options.dbname
        if options.address:
            db_settings.address = options.address
        if options.port:
            db_settings.port = options.port
        if options.username:
            db_settings.username = options.username
        if options.password:
            db_settings.password = options.password

        server = ServerProxy()
        running = server.check_running()
        if running:
            server.call('pause_tasks')
        # ServerProxy may have opened a store
        set_default_store(None)

        try:
            initialize_system(password=unicode(options.password),
                              force=options.force, empty=options.empty)
        except ValueError as e:
            # Database server is missing pg_trgm
            if 'pg_trgm' in str(e):
                return 31
            else:
                raise

        if options.create_examples or options.demo:
            from stoqlib.importers.stoqlibexamples import create
            create(utilities=True)

        if options.register_station and not options.empty:
            self._register_station()

        if options.pre_plugins:
            self._register_plugins(unicode(options.pre_plugins).split(','))

        if options.plugins:
            self._enable_plugins(unicode(options.plugins).split(','))

        if options.demo:
            self._enable_demo()

        config.flush()

        # The schema was upgraded. If it was running before,
        # restart it so it can load the new code
        if running:
            server.call('restart')

        return 0