Esempio n. 1
0
def upgradedb():
    """ Upgrades the database schema to the latest revision
    """
    app.config["SERVER_NAME"] = 'localhost'
    migrations_dir = os.path.join(os.path.abspath(os.path.dirname(__file__)),
                                  'migrations')
    with app.app_context():
        flask_migrate.upgrade(directory=migrations_dir)
Esempio n. 2
0
def get_url_for(*args, **kwargs):
    """
    flask.url_for wrapper which creates the app_context on-the-fly.
    """
    if has_app_context():
        return url_for(*args, **kwargs)

    # Localhost is right URL only when the scheduler runs on the same
    # system as the web views.
    app.config['SERVER_NAME'] = 'localhost'
    with app.app_context():
        log.warning("get_url_for() has been called without the Flask "
                    "app_context. That can lead to SQLAlchemy errors caused by "
                    "multiple session being used in the same time.")
        return url_for(*args, **kwargs)
Esempio n. 3
0
    def consume(self, message):
        messaging_rx_counter.inc()

        # Sometimes, the messages put into our queue are artificially put there
        # by other parts of our own codebase.  If they are already abstracted
        # messages, then just use them as-is.  If they are not already
        # instances of our message abstraction base class, then first transform
        # them before proceeding.
        if isinstance(message, events.BaseEvent):
            msg = message
        else:
            msg = self.get_abstracted_msg(message['body'])

        if not msg:
            # We do not log here anything, because it would create lot of
            # useless messages in the logs.
            messaging_rx_ignored_counter.inc()
            return

        # Primary work is done here.
        try:
            # There is no Flask app-context in the backend and we need some,
            # because models.Event.json() and models.ArtifactBuild.json() uses
            # flask.url_for, which needs app_context to generate the URL.
            # We also cannot generate Flask context on the fly each time in the
            # mentioned json() calls, because each generation of Flask context
            # changes db.session and unfortunately does not give it to original
            # state which might be Flask bug, so the only safe way on backend is
            # to have global app_context.
            with app.app_context():
                self.process_event(msg)
            messaging_rx_processed_ok_counter.inc()
        except Exception:
            messaging_rx_failed_counter.inc()
            log.exception('Failed while handling {0!r}'.format(msg))

        if self.stop_condition and self.stop_condition(message):
            self.shutdown()
from freshmaker.errata import Errata, ErrataAdvisory
from freshmaker.events import (
    ErrataAdvisoryStateChangedEvent, ManualRebuildWithAdvisoryEvent)
from freshmaker.handlers.koji import RebuildImagesOnRPMAdvisoryChange

fedmsg_config = fedmsg.config.load_config()
dictConfig(fedmsg_config.get('logging', {'version': 1}))

if len(sys.argv) < 2:
    print("Queries Lightblue to find out all the images Freshmaker rebuilds.")
    print("Usage: ./lightblue.py ERRATA_ID [[CONTAINER_IMAGE], ...]")
    sys.exit(1)

container_images = sys.argv[2:]

app_context = app.app_context()
app_context.__enter__()

db.drop_all()
db.create_all()
db.session.commit()

errata = Errata()
kwargs = {}
if container_images:
    EventClass = ManualRebuildWithAdvisoryEvent
    kwargs['container_images'] = container_images
else:
    EventClass = ErrataAdvisoryStateChangedEvent
event = EventClass(
    "fake_message", ErrataAdvisory.from_advisory_id(errata, sys.argv[1]),