Exemple #1
0
    def setUpClass(cls):
        initialize_test_config()
        execution_db_help.setup_dbs()

        cls.app = create_app()
        cls.app.testing = True
        cls.context = cls.app.test_request_context()
        cls.context.push()

        cls.test_client = cls.app.test_client(cls)

        db.create_all()
        cls.role_rd = Role('message_guest')
        cls.role_rd.set_resources([{'name': 'messages', 'permissions': ['read', 'delete', 'update']}])

        cls.role_r = Role('read_only')
        cls.role_r.set_resources([{'name': 'messages', 'permissions': ['read', 'update']}])
        db.session.add(cls.role_rd)
        db.session.add(cls.role_r)
        try:
            db.session.commit()
        except IntegrityError:
            db.session.rollback()
        cls.user1 = UserWrapper('username', 'password', roles=[cls.role_rd.id])
        cls.user2 = UserWrapper('username2', 'password2', roles=[cls.role_r.id])
        cls.user3 = UserWrapper('username3', 'password3')
        cls.all_users = (cls.user1, cls.user2, cls.user3)
        db.session.add(cls.user1.user)
        db.session.add(cls.user2.user)
        db.session.add(cls.user3.user)
        try:
            db.session.commit()
        except IntegrityError:
            db.session.rollback()
Exemple #2
0
def run(ctx, host, port, config):
    """Main entry point to run Walkoff locally.

    This command starts a Walkoff server locally. If run from the directory of a locally-installed Walkoff instance it
    will use the configuration file located in ./data/walkoff.config, otherwise you can specify the path to the
    configuration using the --config option.

    This local install is intended for testing purposes only, and it is recommended that you use the kubernetes version.
    """
    exit_code = 0
    walkoff.config.initialize(config)
    compose_api(walkoff.config.Config)
    app = create_app(walkoff.config.Config)
    import_workflows(app)
    try:
        _run_server(app, *convert_host_port(host, port))
    except KeyboardInterrupt:
        logger.info('Caught KeyboardInterrupt! Please wait a few seconds for WALKOFF to shutdown.')
    except Exception as e:
        traceback.print_exc()
        exit_code = 1
    finally:
        app.running_context.executor.shutdown_pool()
        logger.info('Shutting down server')
        os._exit(exit_code)
Exemple #3
0
def run(ctx, host, port, config):
    """Main entry point to run Walkoff locally.

    This command starts a Walkoff server locally. If run from the directory of a locally-installed Walkoff instance it
    will use the configuration file located in ./data/walkoff.config, otherwise you can specify the path to the
    configuration using the --config option.

    This local install is intended for testing purposes only, and it is recommended that you use the kubernetes version.
    """
    exit_code = 0
    walkoff.config.initialize(config)
    compose_api(walkoff.config.Config)
    app = create_app(walkoff.config.Config)
    import_workflows(app)
    try:
        _run_server(app, *convert_host_port(host, port))
    except KeyboardInterrupt:
        logger.info(
            'Caught KeyboardInterrupt! Please wait a few seconds for WALKOFF to shutdown.'
        )
    except Exception as e:
        traceback.print_exc()
        exit_code = 1
    finally:
        app.running_context.executor.shutdown_pool()
        logger.info('Shutting down server')
        os._exit(exit_code)
    def setUpClass(cls):
        initialize_test_config()
        execution_db_help.setup_dbs()

        app = create_app()
        cls.context = app.test_request_context()
        cls.context.push()
        create_user()
    def setUpClass(cls):
        initialize_test_config()

        app = create_app()
        cls.context = app.test_request_context()
        cls.context.push()

        execution_db_help.setup_dbs()

        create_user()
Exemple #6
0
    def setUpClass(cls):
        initialize_test_config()
        walkoff.config.Config.write_values_to_file()

        cls.app = create_app(walkoff.config.Config)
        cls.context = cls.app.test_request_context()
        cls.context.push()

        pids = spawn_worker_processes()
        cls.app.running_context.executor.initialize_threading(cls.app, pids)
    def setUpClass(cls):
        initialize_test_config()
        execution_db_help.setup_dbs()

        app = create_app(walkoff.config.Config)
        cls.context = app.test_request_context()
        cls.context.push()

        multiprocessedexecutor.MultiprocessedExecutor.initialize_threading = mock_initialize_threading
        multiprocessedexecutor.MultiprocessedExecutor.wait_and_reset = mock_wait_and_reset
        multiprocessedexecutor.MultiprocessedExecutor.shutdown_pool = mock_shutdown_pool
        cls.executor = multiprocessedexecutor.MultiprocessedExecutor(
            MockRedisCacheAdapter(), create_autospec(CaseLogger))
        cls.executor.initialize_threading(app)
Exemple #8
0
    def setUpClass(cls):
        initialize_test_config()
        execution_db_help.setup_dbs()

        app = create_app()
        cls.context = app.test_request_context()
        cls.context.push()

        multiprocessedexecutor.MultiprocessedExecutor.initialize_threading = mock_initialize_threading
        multiprocessedexecutor.MultiprocessedExecutor.wait_and_reset = mock_wait_and_reset
        multiprocessedexecutor.MultiprocessedExecutor.shutdown_pool = mock_shutdown_pool
        cls.executor = multiprocessedexecutor.MultiprocessedExecutor(
            MockRedisCacheAdapter(), LocalActionExecutionStrategy())
        cls.executor.initialize_threading(app)
Exemple #9
0
    def setUpClass(cls):
        initialize_test_config()

        cls.app = create_app()
        cls.context = cls.app.test_request_context()
        cls.context.push()

        db.create_all()
        for user in [user for user in User.query.all() if user.username != 'admin']:
            db.session.delete(user)
        for role in [role for role in Role.query.all() if role.name != 'admin']:
            db.session.delete(role)
        for message in Message.query.all():
            db.session.delete(message)
        db.session.commit()
    def setUpClass(cls):
        initialize_test_config()
        execution_db_help.setup_dbs()

        app = create_app()
        cls.context = app.test_request_context()
        cls.context.push()

        multiprocessedexecutor.MultiprocessedExecutor.initialize_threading = mock_initialize_threading
        multiprocessedexecutor.MultiprocessedExecutor.wait_and_reset = mock_wait_and_reset
        multiprocessedexecutor.MultiprocessedExecutor.shutdown_pool = mock_shutdown_pool
        cls.executor = multiprocessedexecutor.MultiprocessedExecutor(
            MockRedisCacheAdapter(),
            LocalActionExecutionStrategy()
        )
        cls.executor.initialize_threading(app)
    def setUpClass(cls):
        initialize_test_config()
        cls.conf = walkoff.config.Config

        if cls != ServerTestCase and cls.setUp != ServerTestCase.setUp:
            original_setup = cls.setUp

            def setup_override(self, *args, **kwargs):
                ServerTestCase.setUp(self)
                return original_setup(self, *args, **kwargs)

            cls.setUp = setup_override

        if cls != ServerTestCase and cls.tearDown != ServerTestCase.tearDown:
            original_teardown = cls.tearDown

            def teardown_override(self, *args, **kwargs):
                cls.preTearDown(self)
                ServerTestCase.tearDown(self)
                return original_teardown(self, *args, **kwargs)

            cls.tearDown = teardown_override

        if (cls.conf.DATA_DIR_NAME not in os.listdir(cls.conf.TEST_PATH)
                or os.path.isfile(cls.conf.DATA_PATH)):
            if os.path.isfile(cls.conf.DATA_PATH):
                os.remove(cls.conf.DATA_PATH)
            os.makedirs(cls.conf.DATA_PATH)

        cls.app = create_app()
        cls.app.testing = True
        cls.context = cls.app.test_request_context()
        cls.context.push()

        create_user()

        if cls.patch:
            MultiprocessedExecutor.initialize_threading = mock_initialize_threading
            MultiprocessedExecutor.shutdown_pool = mock_shutdown_pool
            MultiprocessedExecutor.wait_and_reset = mock_wait_and_reset
            cls.app.running_context.executor.initialize_threading(cls.app)
        else:
            walkoff.config.Config.write_values_to_file()
            pids = spawn_worker_processes()
            cls.app.running_context.executor.initialize_threading(
                cls.app, pids)
Exemple #12
0
    def setUpClass(cls):
        initialize_test_config()
        cls.conf = walkoff.config.Config

        if cls != ServerTestCase and cls.setUp != ServerTestCase.setUp:
            original_setup = cls.setUp

            def setup_override(self, *args, **kwargs):
                ServerTestCase.setUp(self)
                return original_setup(self, *args, **kwargs)

            cls.setUp = setup_override

        if cls != ServerTestCase and cls.tearDown != ServerTestCase.tearDown:
            original_teardown = cls.tearDown

            def teardown_override(self, *args, **kwargs):
                cls.preTearDown(self)
                ServerTestCase.tearDown(self)
                return original_teardown(self, *args, **kwargs)

            cls.tearDown = teardown_override

        if (cls.conf.DATA_DIR_NAME not in os.listdir(cls.conf.TEST_PATH)
                or os.path.isfile(cls.conf.DATA_PATH)):
            if os.path.isfile(cls.conf.DATA_PATH):
                os.remove(cls.conf.DATA_PATH)
            os.makedirs(cls.conf.DATA_PATH)

        cls.app = create_app()
        cls.app.testing = True
        cls.context = cls.app.test_request_context()
        cls.context.push()

        create_user()

        if cls.patch:
            MultiprocessedExecutor.initialize_threading = mock_initialize_threading
            MultiprocessedExecutor.shutdown_pool = mock_shutdown_pool
            MultiprocessedExecutor.wait_and_reset = mock_wait_and_reset
            cls.app.running_context.executor.initialize_threading(cls.app)
        else:
            walkoff.config.Config.write_values_to_file()
            pids = spawn_worker_processes()
            cls.app.running_context.executor.initialize_threading(cls.app, pids)
Exemple #13
0
    def setUpClass(cls):
        initialize_test_config()
        cls.app = create_app(walkoff.config.Config)
        cls.context = current_app.test_request_context()
        cls.context.push()

        db.create_all()
        for user in [
                user for user in User.query.all() if user.username != 'admin'
        ]:
            db.session.delete(user)
        for role in [
                role for role in Role.query.all() if role.name != 'admin'
        ]:
            db.session.delete(role)
        for message in Message.query.all():
            db.session.delete(message)
        db.session.commit()
    def setUpClass(cls):
        cls.uid1 = str(uuid4())
        cls.uid2 = str(uuid4())
        cls.uid3 = str(uuid4())
        cls.uids = {cls.uid1, cls.uid2, cls.uid3}

        initialize_test_config()
        cls.app = create_app()
        cls.context = cls.app.test_request_context()
        cls.context.push()

        db.create_all()
        for user in [user for user in User.query.all() if user.username != 'admin']:
            db.session.delete(user)
        for role in [role for role in Role.query.all() if role.name != 'admin']:
            db.session.delete(role)
        for message in Message.query.all():
            db.session.delete(message)
        db.session.commit()
    def setUpClass(cls):
        initialize_test_config()
        execution_db_help.setup_dbs()

        cls.app = create_app()
        cls.context = cls.app.test_request_context()
        cls.context.push()

        db.create_all()
        for user in [user for user in User.query.all() if user.username != 'admin']:
            db.session.delete(user)
        for message in MessageHistory.query.all():
            db.session.delete(message)
        db.session.commit()
        cls.user1 = User('username', 'password')
        cls.user2 = User('username2', 'pwwww3')
        db.session.add(cls.user1)
        db.session.add(cls.user2)
        db.session.commit()
Exemple #16
0
    def setUpClass(cls):
        initialize_test_config()
        execution_db_help.setup_dbs()

        cls.app = create_app()
        cls.context = cls.app.test_request_context()
        cls.context.push()

        db.create_all()
        for user in [
                user for user in User.query.all() if user.username != 'admin'
        ]:
            db.session.delete(user)
        for message in MessageHistory.query.all():
            db.session.delete(message)
        db.session.commit()
        cls.user1 = User('username', 'password')
        cls.user2 = User('username2', 'pwwww3')
        db.session.add(cls.user1)
        db.session.add(cls.user2)
        db.session.commit()
Exemple #17
0
        logger.info('Importing any workflows not currently in database')
        for p in os.listdir(walkoff.config.Config.WORKFLOWS_PATH):
            full_path = os.path.join(walkoff.config.Config.WORKFLOWS_PATH, p)
            if os.path.isfile(full_path):
                playbook = JsonPlaybookLoader.load_playbook(full_path)
                if playbook.name not in playbook_name:
                    app.running_context.execution_db.session.add(playbook)
        app.running_context.execution_db.session.commit()


if __name__ == "__main__":
    args = parse_args()
    exit_code = 0
    walkoff.config.initialize(args.config)
    compose_api(walkoff.config.Config)
    app = create_app()

    if not walkoff.config.Config.SEPARATE_PROMETHEUS:
        metrics = PrometheusMetrics(app, path='/prometheus_metrics')

    import_workflows(app)
    try:
        run(args, app, *convert_host_port(args))
    except KeyboardInterrupt:
        logger.info(
            'Caught KeyboardInterrupt! Please wait a few seconds for WALKOFF to shutdown.'
        )
    except Exception as e:
        exc_type, exc_value, exc_traceback = sys.exc_info()
        traceback.print_exc()
        exit_code = 1
 def setUpClass(cls):
     initialize_test_config()
     cls.app = create_app()
     cls.app.testing = True
     cls.context = cls.app.test_request_context()
     cls.context.push()
Exemple #19
0
        logger.info('Importing any workflows not currently in database')
        for p in os.listdir(walkoff.config.Config.WORKFLOWS_PATH):
            full_path = os.path.join(walkoff.config.Config.WORKFLOWS_PATH, p)
            if os.path.isfile(full_path):
                playbook = JsonPlaybookLoader.load_playbook(full_path)
                if playbook.name not in playbook_name:
                    app.running_context.execution_db.session.add(playbook)
        app.running_context.execution_db.session.commit()


if __name__ == "__main__":
    args = parse_args()
    exit_code = 0
    walkoff.config.initialize(args.config)
    compose_api(walkoff.config.Config)
    app = create_app()

    if not walkoff.config.Config.SEPARATE_PROMETHEUS:
        metrics = PrometheusMetrics(app, path='/prometheus_metrics')

    import_workflows(app)
    try:
        run(args, app, *convert_host_port(args))
    except KeyboardInterrupt:
        logger.info('Caught KeyboardInterrupt! Please wait a few seconds for WALKOFF to shutdown.')
    except Exception as e:
        exc_type, exc_value, exc_traceback = sys.exc_info()
        traceback.print_exc()
        exit_code = 1
    finally:
        app.running_context.executor.shutdown_pool()
Exemple #20
0
    if os.path.exists(walkoff.config.Config.WORKFLOWS_PATH):
        logger.info('Importing any workflows not currently in database')
        for p in os.listdir(walkoff.config.Config.WORKFLOWS_PATH):
            full_path = os.path.join(walkoff.config.Config.WORKFLOWS_PATH, p)
            if os.path.isfile(full_path):
                playbook = JsonPlaybookLoader.load_playbook(full_path)
                if playbook.name not in playbook_name:
                    app.running_context.execution_db.session.add(playbook)
        app.running_context.execution_db.session.commit()


if __name__ == "__main__":
    args = parse_args()
    exit_code = 0
    walkoff.config.initialize(args.config)
    app = create_app(walkoff.config.Config)
    import_workflows(app)
    try:
        run(app, *convert_host_port(args))
    except KeyboardInterrupt:
        logger.info(
            'Caught KeyboardInterrupt! Please wait a few seconds for WALKOFF to shutdown.'
        )
    except Exception as e:
        exc_type, exc_value, exc_traceback = sys.exc_info()
        traceback.print_exc()
        exit_code = 1
    finally:
        app.running_context.executor.shutdown_pool()
        logger.info('Shutting down server')
        os._exit(exit_code)
 def setUpClass(cls):
     initialize_test_config()
     cls.app = create_app()
     cls.app.testing = True
     cls.context = cls.app.test_request_context()
     cls.context.push()
Exemple #22
0
    host = walkoff.config.Config.HOST if args.host is None else args.host
    port = walkoff.config.Config.PORT if args.port is None else args.port
    try:
        port = int(port)
    except ValueError:
        print('Invalid port {}. Port must be an integer!'.format(port))
        exit(1)
    return host, port


if __name__ == '__main__':
    exit_code = 0
    args = parse_args()

    walkoff.config.initialize(args.config)
    app = create_app(interface_app=True)

    walkoff.config.Config.WORKFLOW_RESULTS_HANDLER = 'kafka'
    receiver = make_results_receiver()
    receiver_thread = threading.Thread(target=receiver.receive_results)
    receiver_thread.start()

    try:
        run(app, *convert_host_port(args))
    except KeyboardInterrupt:
        logger.info(
            'Caught KeyboardInterrupt! Please wait a few seconds for WALKOFF interface server to shutdown.'
        )
        receiver.thread_exit = True
        receiver_thread.join(timeout=1)
    except Exception as e:
Exemple #23
0
    host = walkoff.config.Config.HOST if args.host is None else args.host
    port = walkoff.config.Config.PORT if args.port is None else args.port
    try:
        port = int(port)
    except ValueError:
        print('Invalid port {}. Port must be an integer!'.format(port))
        exit(1)
    return host, port


if __name__ == '__main__':
    exit_code = 0
    args = parse_args()

    walkoff.config.initialize(args.config)
    app = create_app(interface_app=True)

    walkoff.config.Config.WORKFLOW_RESULTS_HANDLER = 'kafka'
    receiver = make_results_receiver()
    receiver_thread = threading.Thread(target=receiver.receive_results)
    receiver_thread.start()

    try:
        run(app, *convert_host_port(args))
    except KeyboardInterrupt:
        logger.info('Caught KeyboardInterrupt! Please wait a few seconds for WALKOFF interface server to shutdown.')
        receiver.thread_exit = True
        receiver_thread.join(timeout=1)
    except Exception as e:
        exc_type, exc_value, exc_traceback = sys.exc_info()
        traceback.print_exc()