示例#1
0
def before_activity_control(context: Activity,
                            configuration: Configuration = None,
                            settings: Settings = None,
                            secrets: Secrets = None,
                            **kwargs):
    """
    before-control of the activity's execution

    Called by the Chaos Toolkit before the activity is applied.
    """
    if no_upload(settings):
        return
    send_experiment_event(event='before-activity',
                          context=context,
                          state=None,
                          settings=settings)
示例#2
0
def before_rollback_control(context: Experiment,
                            configuration: Configuration = None,
                            settings: Settings = None,
                            secrets: Secrets = None,
                            **kwargs):
    """
    before-control of the rollback's execution

    Called by the Chaos Toolkit before the actions of the rollback are
    applied.
    """
    if no_upload(settings):
        return
    send_experiment_event(event='before-rollback',
                          context=context,
                          state=None,
                          settings=settings)
示例#3
0
def before_hypothesis_control(context: Hypothesis,
                              configuration: Configuration = None,
                              settings: Settings = None,
                              secrets: Secrets = None,
                              **kwargs):
    """
    before-control of the hypothesis's execution

    Called by the Chaos Toolkit before the steady-state hypothesis is
    applied.
    """
    if no_upload(settings):
        return
    send_experiment_event(event='before-hypothesis',
                          context=context,
                          state=None,
                          settings=settings)
示例#4
0
def cleanup_control():
    """
    Cleanup the control's global state

    Called once only during the experiment's execution.
    """

    settings = get_loaded_settings()

    if no_upload(settings):
        return

    exc_type, exc_value, exc_traceback = sys.exc_info()
    if exc_value:
        state = {'error': str(exc_value)}

        send_experiment_event(event='abort-experiment',
                              context=None,
                              settings=settings,
                              state=state)
示例#5
0
def after_activity_control(context: Activity,
                           state: Run,
                           configuration: Configuration = None,
                           settings: Settings = None,
                           secrets: Secrets = None,
                           **kwargs):
    """
    after-control of the activity's execution

    Called by the Chaos Toolkit before the activity is applied. The result of
    the execution is passed as `state`. See
    https://docs.chaostoolkit.org/reference/api/journal/#run for more
    information.
    """
    if no_upload(settings):
        return
    send_experiment_event(event='after-activity',
                          context=context,
                          state=state,
                          settings=settings)
示例#6
0
def after_rollback_control(context: Experiment,
                           state: List[Run],
                           configuration: Configuration = None,
                           settings: Settings = None,
                           secrets: Secrets = None,
                           **kwargs):
    """
    after-control of the rollback's execution

    Called by the Chaos Toolkit after the actions of the rollback have been
    applied. The `state` is the list of actions results. See
    https://docs.chaostoolkit.org/reference/api/journal/#run for more
    information.
    """
    if no_upload(settings):
        return
    send_experiment_event(event='after-rollback',
                          context=context,
                          state=state,
                          settings=settings)
示例#7
0
def after_hypothesis_control(context: Hypothesis,
                             state: Dict[str, Any],
                             configuration: Configuration = None,
                             settings: Settings = None,
                             secrets: Secrets = None,
                             **kwargs):
    """
    after-control of the hypothesis's execution

    Called by the Chaos Toolkit after the steady-state hypothesis is
    complete. The `state` contains the result of the hypothesis. Refer to
    https://docs.chaostoolkit.org/reference/api/journal/#steady-state-outcomes
    for the description of that state.
    """
    if no_upload(settings):
        return
    send_experiment_event(event='after-hypothesis',
                          context=context,
                          state=state,
                          settings=settings)
示例#8
0
def after_experiment_control(context: Experiment,
                             state: Journal,
                             configuration: Configuration = None,
                             secrets: Secrets = None,
                             settings: Settings = None,
                             **kwargs):
    """
    after-control of the experiment's execution

    Called by the Chaos Toolkit after the experiment's completed. It passes the
    journal of the execution. At that stage, the after control has no influence
    over the execution however. Please see
    https://docs.chaostoolkit.org/reference/api/journal/#journal-elements
    for more information about the journal.
    """

    if no_upload(settings):
        return
    send_experiment_event(event='after-experiment',
                          context=None,
                          state=state,
                          settings=settings)
示例#9
0
def before_experiment_control(context: Experiment,
                              configuration: Configuration = None,
                              secrets: Secrets = None,
                              settings: Settings = None,
                              **kwargs):
    """
    before-control of the experiment's execution

    Called by the Chaos Toolkit before the experiment's begin but after the
    configuration and secrets have been loaded.
    """

    if no_upload(settings):
        return

    try:
        logger.info('Creating experiment run in Proofdock...')
        with client_session(verify_tls=False, settings=settings) as session:
            execution = push_execution(settings, session)
        execution_ctx = {
            'id': execution.get('id'),
            'creation_time': execution.get('creation_time')
        }
        add_to_run_context(settings, 'execution', execution_ctx)
        logger.info("New experiment run with id: '{}' created.".format(
            execution.get('id')))
    except Exception as ex:
        logger.error('Could not create experiment run in Proofdock cloud. %s',
                     str(ex))
        logger.debug(ex)
        raise InterruptExecution()

    send_experiment_event(event='before-experiment',
                          context=context,
                          state=None,
                          settings=settings)
示例#10
0
def test_no_upload_disabled():
    # arrange
    settings = {'run_context': {}}

    # act & assert
    assert no_upload(settings) is False
示例#11
0
def test_no_upload_enabled():
    # arrange
    settings = {'run_context': {'no_upload': True}}

    # act & assert
    assert no_upload(settings) is True