示例#1
0
    def test_celery_functions_bogus_cw(self):
        """Test that celery continues to function when
        provided bogus AWS credentials for Cloud Watch logging.
        """
        test_celery = Celery(__name__, broker=Config.CELERY_BROKER_URL)
        test_app = create_app({
            'TESTING': True,
            'SQLALCHEMY_TRACK_MODIFICATIONS': False,
            'SQLALCHEMY_DATABASE_URI': 'sqlite:///test.db',
            'SCHEDULE_REPORT_CHECKS': True,
            'REMOVE_EXPIRED_REPORT_DATA_ON_DAY': '1',
            'REMOVE_EXPIRED_REPORT_UTC_TIME': '00:00',
            'CW_AWS_ACCESS_KEY_ID': 'bogusAWSkey',
            'CW_AWS_SECRET_ACCESS_KEY': 'bogusAWSsecret',
        })

        self.assertIsNone(test_celery.conf.task_routes)
        self.assertEqual(test_celery.conf.imports, ())
        self.assertEqual(test_celery.conf.beat_schedule, {})
        self.assertEqual(repr(test_celery.Task), repr(Task))

        update_celery_config(test_celery, test_app)

        self.assertIsNotNone(test_celery.conf.task_routes)
        self.assertNotEqual(test_celery.conf.imports, ())
        self.assertNotEqual(test_celery.conf.beat_schedule, {})
        self.assertNotEqual(repr(test_celery.Task), repr(Task))
        logger = get_task_logger('test')
        setup_cloudwatch_logging(logger)
        logger.info('log running')
示例#2
0
    def test_update_celery_config(self):
        """Test that the app config updates our celery instance."""
        test_celery = Celery(__name__, broker=Config.CELERY_BROKER_URL)
        test_app = create_app(
            {
                'TESTING': True,
                'SQLALCHEMY_TRACK_MODIFICATIONS': False,
                'SQLALCHEMY_DATABASE_URI': 'sqlite:///test.db',
                'SCHEDULE_REPORT_CHECKS': True,
                'REMOVE_EXPIRED_REPORT_DATA_ON_DAY': '1',
                'REMOVE_EXPIRED_REPORT_UTC_TIME': '00:00'
            }
        )

        self.assertIsNone(test_celery.conf.task_routes)
        self.assertEqual(test_celery.conf.imports, ())
        self.assertEqual(test_celery.conf.beat_schedule, {})
        self.assertEqual(repr(test_celery.Task), repr(Task))

        update_celery_config(test_celery, test_app)

        self.assertIsNotNone(test_celery.conf.task_routes)
        self.assertNotEqual(test_celery.conf.imports, ())
        self.assertNotEqual(test_celery.conf.beat_schedule, {})
        self.assertNotEqual(repr(test_celery.Task), repr(Task))
示例#3
0
文件: __init__.py 项目: werwty/masu
def create_app(test_config=None):
    """
    App factory for Flask application.

    Args:
        test_config (dict): A mapping of configurations used for testing

    Returns:
        flask.app.Flask: The configured Flask application

    """
    app = Flask(__name__, instance_relative_config=True)

    # Load configs
    if test_config:
        app.config.from_mapping(test_config)

        # disable log messages less than CRITICAL when running unit tests.
        logging.disable(logging.CRITICAL)
    else:
        app.config.from_object('masu.config.Config')

    # Logging
    setup_cloudwatch_logging(logger)
    logger.setLevel(app.config.get('LOG_LEVEL', 'WARNING'))

    if not test_config and (sys.argv and 'celery' not in sys.argv[0]):
        ApplicationStatus().startup()

    try:
        os.makedirs(app.instance_path)
        if not test_config:
            metrics.init_app(app)
    # pylint: disable=invalid-name
    except OSError as e:
        # ignore "File exists"
        if e.errno != errno.EEXIST:
            logger.warning(e)

    # Add application config to Celery
    update_celery_config(celery_app, app)

    # Blueprints
    app.register_blueprint(api_v1)

    return app
示例#4
0
文件: worker.py 项目: LaVLaS/masu
#
# Copyright 2018 Red Hat, Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.
#
"""Celery worker entry-point."""
from masu import create_app
from masu.celery import celery, update_celery_config

MASU = create_app()
MASU.app_context().push()
update_celery_config(celery, MASU)