Exemple #1
0
    def setUp(self):
        # orm session wrapping
        config.init_config([])
        self.connection = self.engine.connect()
        self.trans = self.connection.begin()

        self.Session.configure(
            bind=self.connection
        )
        self.session = self.Session()

        test_sets = self.session.query(models.TestSet).all()

        # need this if start unit tests in conjuction with integration
        if not test_sets:
            discovery(path=TEST_PATH, session=self.session)

        mixins.cache_test_repository(self.session)

        # mocking
        # request mocking
        self.request_mock = MagicMock()

        self.request_patcher = patch(
            'fuel_plugin.ostf_adapter.wsgi.controllers.request',
            self.request_mock
        )
        self.request_patcher.start()

        # engine.get_session mocking
        self.request_mock.session = self.session
Exemple #2
0
def main():

    settings = Ostf_Config()

    cli_args = cli_config.parse_cli()

    config = {
        'server': {
            'host': settings.adapter.server_host or cli_args.host,
            'port': settings.adapter.server_port or cli_args.port
        },
        'dbpath': settings.adapter.dbpath or cli_args.dbpath,
        'debug': cli_args.debug,
        'debug_tests': cli_args.debug_tests,
        'lock_dir': settings.adapter.lock_dir or cli_args.lock_dir,
        'nailgun': {
            'host': settings.adapter.nailgun_host or cli_args.nailgun_host,
            'port': settings.adapter.nailgun_port or cli_args.nailgun_port
        }
    }
    logger.setup(log_file=(
        settings.adapter.log_file or cli_args.log_file))

    log = logging.getLogger(__name__)

    root = app.setup_app(config=config)

    if settings.adapter.after_init_hook or\
            getattr(cli_args, 'after_init_hook'):
        return nailgun_hooks.after_initialization_environment_hook()

    with engine.contexted_session(pecan.conf.dbpath) as session:
        # performing cleaning of expired data (if any) in db
        mixins.clean_db(session)

        # discover testsets and their tests
        CORE_PATH = pecan.conf.debug_tests if \
            pecan.conf.get('debug_tests') else 'fuel_health'

        nose_discovery.discovery(path=CORE_PATH, session=session)

        # cache needed data from test repository
        mixins.cache_test_repository(session)

    host, port = pecan.conf.server.host, pecan.conf.server.port
    srv = pywsgi.WSGIServer((host, int(port)), root)

    log.info('Starting server in PID %s', os.getpid())
    log.info("serving on http://%s:%s", host, port)

    try:
        signal.signal(signal.SIGCHLD, signal.SIG_IGN)
        srv.serve_forever()
    except KeyboardInterrupt:
        pass
Exemple #3
0
def main():

    ostf_config.init_config(sys.argv[1:])

    logger.setup(log_file=CONF.adapter.log_file)

    log = logging.getLogger(__name__)
    log.info('Start app configuration')

    root = app.setup_app({})

    # completely clean db (drop tables, constraints and types)
    # plus drop alembic_version table (needed if, for example, head migration
    # script was changed after applying)
    if CONF.clear_db:
        return nailgun_hooks.clear_db(CONF.adapter.dbpath)

    if CONF.after_initialization_environment_hook:
        return nailgun_hooks.after_initialization_environment_hook()

    with engine.contexted_session(CONF.adapter.dbpath) as session:
        # performing cleaning of expired data (if any) in db
        mixins.delete_db_data(session)
        log.info('Cleaned up database.')
        # discover testsets and their tests
        CORE_PATH = CONF.debug_tests or 'fuel_health'

        log.info('Performing nose discovery with {0}.'.format(CORE_PATH))

        nose_discovery.discovery(path=CORE_PATH, session=session)

        # cache needed data from test repository
        mixins.cache_test_repository(session)

    log.info('Discovery is completed')
    host, port = CONF.adapter.server_host, CONF.adapter.server_port
    srv = pywsgi.WSGIServer((host, port), root)

    log.info('Starting server in PID %s', os.getpid())
    log.info("serving on http://%s:%s", host, port)

    try:
        signal.signal(signal.SIGCHLD, signal.SIG_IGN)
        srv.serve_forever()
    except KeyboardInterrupt:
        pass
Exemple #4
0
def main():

    ostf_config.init_config(sys.argv[1:])

    logger.setup(log_file=CONF.adapter.log_file)

    log = logging.getLogger(__name__)
    log.info('Start app configuration')

    root = app.setup_app({})

    # completely clean db (drop tables, constraints and types)
    # plus drop alembic_version table (needed if, for example, head migration
    # script was changed after applying)
    if CONF.clear_db:
        return nailgun_hooks.clear_db(CONF.adapter.dbpath)

    if CONF.after_initialization_environment_hook:
        return nailgun_hooks.after_initialization_environment_hook()

    with engine.contexted_session(CONF.adapter.dbpath) as session:
        # performing cleaning of expired data (if any) in db
        mixins.delete_db_data(session)
        log.info('Cleaned up database.')
        # discover testsets and their tests
        CORE_PATH = CONF.debug_tests or 'fuel_health'

        log.info('Performing nose discovery with {0}.'.format(CORE_PATH))

        nose_discovery.discovery(path=CORE_PATH, session=session)

        # cache needed data from test repository
        mixins.cache_test_repository(session)

    log.info('Discovery is completed')
    host, port = CONF.adapter.server_host, CONF.adapter.server_port
    srv = pywsgi.WSGIServer((host, port), root)

    log.info('Starting server in PID %s', os.getpid())
    log.info("serving on http://%s:%s", host, port)

    try:
        signal.signal(signal.SIGCHLD, signal.SIG_IGN)
        srv.serve_forever()
    except KeyboardInterrupt:
        pass
Exemple #5
0
    def setUp(self):
        #orm session wrapping
        self.connection = self.engine.connect()
        self.trans = self.connection.begin()

        self.Session.configure(
            bind=self.connection
        )
        self.session = self.Session(autocommit=True)

        with self.session.begin(subtransactions=True):
            test_sets = self.session.query(models.TestSet).all()

        #need this if start unit tests in conjuction with integration
        if not test_sets:
            discovery(path=TEST_PATH, session=self.session)

        mixins.cache_test_repository(self.session)

        #mocking
        #request mocking
        self.request_mock = MagicMock()

        self.request_patcher = patch(
            'fuel_plugin.ostf_adapter.wsgi.controllers.request',
            self.request_mock
        )
        self.request_patcher.start()

        #pecan conf mocking
        self.pecan_conf_mock = MagicMock()
        self.pecan_conf_mock.nailgun.host = '127.0.0.1'
        self.pecan_conf_mock.nailgun.port = 8888

        self.pecan_conf_patcher = patch(
            'fuel_plugin.ostf_adapter.mixins.conf',
            self.pecan_conf_mock
        )
        self.pecan_conf_patcher.start()

        #engine.get_session mocking
        self.request_mock.session = self.session
Exemple #6
0
 def discovery(self):
     """Discover dummy tests used for testsing."""
     mixins.TEST_REPOSITORY = []
     nose_discovery.discovery(path=TEST_PATH, session=self.session)
     mixins.cache_test_repository(self.session)
     self.session.flush()
Exemple #7
0
 def discovery(self):
     """Discover dummy tests used for testsing."""
     mixins.TEST_REPOSITORY = []
     nose_discovery.discovery(path=TEST_PATH, session=self.session)
     mixins.cache_test_repository(self.session)
     self.session.flush()