Ejemplo n.º 1
0
def make_unreachable(ctx, **kwargs):
    with update_storage(ctx) as data:
        data['unreachable_call_order'] = data.get('unreachable_call_order', [])
        data['unreachable_call_order'].append({
            'id': ctx.instance.id,
            'time': time.time()
        })
Ejemplo n.º 2
0
def stop(**kwargs):
    with update_storage(ctx) as data:
        ctx.logger.info('stopping machine: {0}'.format(ctx.node_id))
        if ctx.node_id not in data['machines']:
            raise RuntimeError('machine with id [{0}] does not exist'.format(
                ctx.node_id))
        data['machines'][ctx.node_id] = NOT_RUNNING
Ejemplo n.º 3
0
def stop(**kwargs):
    with update_storage(ctx) as data:
        ctx.logger.info('stopping machine: {0}'.format(ctx.node_id))
        if ctx.node_id not in data['machines']:
            raise RuntimeError('machine with id [{0}] does not exist'
                               .format(ctx.node_id))
        data['machines'][ctx.node_id] = NOT_RUNNING
Ejemplo n.º 4
0
def saving_operation_info(ctx, op, main_node, second_node=None, **_):
    with update_storage(ctx) as data:
        invocations = data['mock_operation_invocation'] = data.get(
            'mock_operation_invocation', []
        )
        num = data.get('num', 0) + 1
        data['num'] = num

        op_info = {'operation': op, 'num': num}
        if second_node is None:
            op_info.update({
                'node': main_node.node.name,
                'id': main_node.instance.id,
                'target_ids': [r.target.instance.id
                               for r in main_node.instance.relationships]
            })
        else:
            op_info.update({
                'id': main_node.instance.id,
                'source': main_node.node.name,
                'target': second_node.node.name
            })
        invocations.append(op_info)

    client = get_rest_client()
    fail_input = client.deployments.get(ctx.deployment.id).inputs.get(
        'fail', [])
    fail_input = [i for i in fail_input if
                  i.get('workflow') == ctx.workflow_id and
                  i.get('node') == main_node.node.id and
                  i.get('operation') == ctx.operation.name]
    if fail_input:
        raise RuntimeError('TEST_EXPECTED_FAIL')
Ejemplo n.º 5
0
def get_resource_operation(ctx, **kwargs):
    resource_path = get_prop('resource_path', ctx, kwargs)
    # trying to retrieve a resource
    res1 = ctx.download_resource(resource_path)
    if not res1:
        raise RuntimeError('Failed to get resource {0}'.format(resource_path))
    with open(res1, 'r') as f:
        res1_data = f.read()
    os.remove(res1)

    # trying to retrieve a resource to a specific location
    tempdir = tempfile.mkdtemp()
    try:
        filepath = os.path.join(tempdir, 'temp-resource-file')
        res2 = ctx.download_resource(resource_path, filepath)
        if not res2:
            raise RuntimeError('Failed to get resource {0} into {1}'.format(
                resource_path, filepath))
        with open(res2, 'r') as f:
            res2_data = f.read()
    finally:
        shutil.rmtree(tempdir)

    with update_storage(ctx) as data:
        data['get_resource_operation_invocation'] = data.get(
            'get_resource_operation_invocation', [])
        data['get_resource_operation_invocation'].append({
            'res1_data': res1_data,
            'res2_data': res2_data,
            'custom_filepath': filepath,
            'res2_path': res2
        })
Ejemplo n.º 6
0
def terminate(**kwargs):
    with update_storage(ctx) as data:
        ctx.logger.info('terminating machine: {0}'.format(ctx.node_id))
        if ctx.node_id not in data['machines']:
            raise RuntimeError('machine with id [{0}] does not exist'.format(
                ctx.node_id))
        del data['machines'][ctx.node_id]
Ejemplo n.º 7
0
def terminate(**kwargs):
    with update_storage(ctx) as data:
        ctx.logger.info('terminating machine: {0}'.format(ctx.node_id))
        if ctx.node_id not in data['machines']:
            raise RuntimeError('machine with id [{0}] does not exist'
                               .format(ctx.node_id))
        del data['machines'][ctx.node_id]
Ejemplo n.º 8
0
def mock_operation_get_instance_ip_from_context(ctx, **_):
    with update_storage(ctx) as data:
        data['mock_operation_invocation'] = data.get(
            'mock_operation_invocation', [])
        data['mock_operation_invocation'].append((ctx.node_name, ctx.host_ip))

    return True
Ejemplo n.º 9
0
def make_unreachable(ctx, **kwargs):
    with update_storage(ctx) as data:
        data['unreachable_call_order'] = data.get('unreachable_call_order', [])
        data['unreachable_call_order'].append({
            'id': ctx.instance.id,
            'time': time.time()
        })
Ejemplo n.º 10
0
def get_resource_operation(ctx, **kwargs):
    resource_path = get_prop('resource_path', ctx, kwargs)
    # trying to retrieve a resource
    res1 = ctx.download_resource(resource_path)
    if not res1:
        raise RuntimeError('Failed to get resource {0}'.format(resource_path))
    with open(res1, 'r') as f:
        res1_data = f.read()
    os.remove(res1)

    # trying to retrieve a resource to a specific location
    tempdir = tempfile.mkdtemp()
    try:
        filepath = os.path.join(tempdir, 'temp-resource-file')
        res2 = ctx.download_resource(resource_path, filepath)
        if not res2:
            raise RuntimeError('Failed to get resource {0} into {1}'.format(
                resource_path, filepath))
        with open(res2, 'r') as f:
            res2_data = f.read()
    finally:
        shutil.rmtree(tempdir)

    with update_storage(ctx) as data:
        data['get_resource_operation_invocation'] = data.get(
            'get_resource_operation_invocation', []
        )
        data['get_resource_operation_invocation'].append({
            'res1_data': res1_data,
            'res2_data': res2_data,
            'custom_filepath': filepath,
            'res2_path': res2
        })
Ejemplo n.º 11
0
def mock_operation_get_instance_ip(ctx, **kwargs):
    with update_storage(ctx) as data:
        data['mock_operation_invocation'] = data.get(
            'mock_operation_invocation', [])
        data['mock_operation_invocation'].append(
            (ctx.node.name, get_node_instance_ip(ctx.instance.id)))

    return True
Ejemplo n.º 12
0
def mock_operation_get_instance_ip_of_related_from_context(ctx, **_):
    with update_storage(ctx) as data:
        data['mock_operation_invocation'] = data.get(
            'mock_operation_invocation', [])
        data['mock_operation_invocation'].append(
            ('{}_rel'.format(ctx.node_name), ctx.related.host_ip))

    return True
Ejemplo n.º 13
0
def mock_operation_from_custom_workflow(ctx, key, value, **kwargs):
    with update_storage(ctx) as data:
        data['mock_operation_invocation'] = data.get(
            'mock_operation_invocation', []
        )
        data['mock_operation_invocation'].append({
            key: value
        })
Ejemplo n.º 14
0
def configure(cloudify_agent=None, **_):
    installer = get_backend(cloudify_agent)
    installer.create()
    worker_name = installer.agent_name
    with update_storage(ctx) as data:
        data[worker_name] = data.get(worker_name, {})
        data[worker_name]['states'] = data[worker_name].get('states', [])
        data[worker_name]['states'].append('configured')
Ejemplo n.º 15
0
def restart(cloudify_agent=None, **_):
    installer = get_backend(cloudify_agent)
    worker_name = installer.agent_name
    installer.restart()
    with update_storage(ctx) as data:
        data[worker_name] = data.get(worker_name, {})
        data[worker_name]['states'] = data[worker_name].get('states', [])
        data[worker_name]['states'].append('restarted')
Ejemplo n.º 16
0
def uninstall(ctx, **kwargs):
    agent_config = _fix_worker(ctx, **kwargs)
    worker_name = agent_config['name']
    ctx.logger.info('Uninstalling worker {0}'.format(worker_name))
    with update_storage(ctx) as data:
        data[worker_name] = data.get(worker_name, {})
        data[worker_name]['states'] = data[worker_name].get('states', [])
        data[worker_name]['states'].append('uninstalled')
        data[worker_name]['pids'] = []
Ejemplo n.º 17
0
def put_workflow_node_instance(ctx, modification, relationships):
    with update_storage(ctx) as data:
        state = data.get('state', {})
        data['state'] = state
        state[ctx.instance.id] = {
            'node_id': ctx.node.id,
            'modification': modification,
            'relationships': relationships
        }
Ejemplo n.º 18
0
def uninstall(cloudify_agent=None, **kwargs):
    installer = get_backend(cloudify_agent)
    installer.uninstall()
    worker_name = installer.agent_name
    with update_storage(ctx) as data:
        data[worker_name] = data.get(worker_name, {})
        data[worker_name]['states'] = data[worker_name].get('states', [])
        data[worker_name]['states'].append('uninstalled')
        data[worker_name]['pids'] = []
Ejemplo n.º 19
0
def stop_monitor(ctx, **kwargs):
    with update_storage(ctx) as data:
        data['monitoring_operations_invocation'] = data.get(
            'monitoring_operations_invocation', []
        )
        data['monitoring_operations_invocation'].append({
            'id': ctx.instance.id,
            'operation': 'stop_monitor'
        })
Ejemplo n.º 20
0
def uninstall(ctx, **kwargs):
    agent_config = _fix_worker(ctx, **kwargs)
    worker_name = agent_config['name']
    ctx.logger.info('Uninstalling worker {0}'.format(worker_name))
    with update_storage(ctx) as data:
        data[worker_name] = data.get(worker_name, {})
        data[worker_name]['states'] = data[worker_name].get('states', [])
        data[worker_name]['states'].append('uninstalled')
        data[worker_name]['pids'] = []
Ejemplo n.º 21
0
def provision(**kwargs):
    with update_storage(ctx) as data:
        machines = data.get('machines', {})
        if ctx.node_id in machines:
            raise NonRecoverableError(
                'machine with id [{0}] already exists'.format(ctx.node_id))
        if ctx.properties.get('test_ip'):
            ctx.runtime_properties['ip'] = ctx.properties['test_ip']
        machines[ctx.node_id] = NOT_RUNNING
        data['machines'] = machines
Ejemplo n.º 22
0
def install(ctx, plugins, **kwargs):

    for plugin in plugins:
        plugin_name = plugin['name']
        ctx.logger.info('Installing plugin {0}'.format(plugin_name))
        with update_storage(ctx) as data:
            data[ctx.task_target] = data.get(ctx.task_target, {})
            data[ctx.task_target][plugin_name] = \
                data[ctx.task_target].get(plugin_name, [])
            data[ctx.task_target][plugin_name].append('installed')
Ejemplo n.º 23
0
def mock_operation_get_instance_ip_of_related_from_context(ctx, **_):
    with update_storage(ctx) as data:
        data['mock_operation_invocation'] = data.get(
            'mock_operation_invocation', []
        )
        data['mock_operation_invocation'].append((
            '{}_rel'.format(ctx.node_name), ctx.related.host_ip
        ))

    return True
Ejemplo n.º 24
0
def provision(**kwargs):
    with update_storage(ctx) as data:
        machines = data.get('machines', {})
        if ctx.node_id in machines:
            raise NonRecoverableError('machine with id [{0}] already exists'
                                      .format(ctx.node_id))
        if ctx.properties.get('test_ip'):
            ctx.runtime_properties['ip'] = ctx.properties['test_ip']
        machines[ctx.node_id] = NOT_RUNNING
        data['machines'] = machines
Ejemplo n.º 25
0
def stop_monitor(ctx, **kwargs):
    with update_storage(ctx) as data:
        data['monitoring_operations_invocation'] = data.get(
            'monitoring_operations_invocation', [])
        data['monitoring_operations_invocation'].append({
            'id':
            ctx.instance.id,
            'operation':
            'stop_monitor'
        })
Ejemplo n.º 26
0
def retrieve_template(ctx, rendering_tests_demo_conf, mode, **_):
    if mode == 'get':
        resource = \
            ctx.get_resource_and_render(rendering_tests_demo_conf)
    else:
        resource = \
            ctx.download_resource_and_render(rendering_tests_demo_conf)

    with update_storage(ctx) as data:
        data['rendered_resource'] = resource
Ejemplo n.º 27
0
def mock_operation_get_instance_ip_from_context(ctx, **_):
    with update_storage(ctx) as data:
        data['mock_operation_invocation'] = data.get(
            'mock_operation_invocation', []
        )
        data['mock_operation_invocation'].append((
            ctx.node.name, ctx.instance.host_ip
        ))

    return True
Ejemplo n.º 28
0
def host_get_state(ctx, **kwargs):
    with update_storage(ctx) as data:
        data['host_get_state_invocation'] = data.get(
            'host_get_state_invocation', [])
        data['host_get_state_invocation'].append(time.time())

    if len(data['host_get_state_invocation']) <= get_prop(
            'false_count', ctx, kwargs):
        return False
    return True
Ejemplo n.º 29
0
def retrieve_template(ctx, rendering_tests_demo_conf, mode, **_):
    if mode == 'get':
        resource = \
            ctx.get_resource_and_render(rendering_tests_demo_conf)
    else:
        resource = \
            ctx.download_resource_and_render(rendering_tests_demo_conf)

    with update_storage(ctx) as data:
        data['rendered_resource'] = resource
Ejemplo n.º 30
0
def mock_operation_get_instance_ip(ctx, **kwargs):
    with update_storage(ctx) as data:
        data['mock_operation_invocation'] = data.get(
            'mock_operation_invocation', []
        )
        data['mock_operation_invocation'].append((
            ctx.node.name, get_node_instance_ip(ctx.instance.id)
        ))

    return True
Ejemplo n.º 31
0
def make_reachable(ctx, **kwargs):
    state_info = {
        'id': ctx.instance.id,
        'time': time.time(),
        'capabilities': ctx.capabilities.get_all()
    }
    ctx.logger.info('Appending to state [node_id={0}, state={1}]'
                    .format(ctx.instance.id, state_info))
    with update_storage(ctx) as data:
        data['state'] = data.get('state', [])
        data['state'].append(state_info)
Ejemplo n.º 32
0
def delete(cloudify_agent=None, **_):
    installer = get_backend(cloudify_agent)
    installer.delete()
    worker_name = installer.agent_name
    with update_storage(ctx) as data:
        data[worker_name] = data.get(worker_name, {})
        data[worker_name]['states'] = data[worker_name].get('states', [])
        data[worker_name]['states'].append('deleted')

    if ctx.type == context.NODE_INSTANCE:
        del ctx.instance.runtime_properties['cloudify_agent']
Ejemplo n.º 33
0
def retry(ctx, retry_count=1, retry_after=1, **kwargs):
    with update_storage(ctx) as data:
        invocations = data.get('retry_invocations', 0)
        if invocations != ctx.operation.retry_number:
            raise NonRecoverableError(
                'invocations({0}) != ctx.operation.retry_number'
                '({1})'.format(invocations, ctx.operation.retry_number))
        data['retry_invocations'] = invocations + 1
    if ctx.operation.retry_number < retry_count:
        return ctx.operation.retry(message='Retrying operation',
                                   retry_after=retry_after)
Ejemplo n.º 34
0
def start(**kwargs):
    with update_storage(ctx) as data:
        machines = data.get('machines', {})
        ctx.send_event('starting machine event')
        ctx.logger.info('cloudmock start: [node_id={0}, machines={1}]'
                        .format(ctx.node_id, machines))
        if ctx.node_id not in machines:
            raise NonRecoverableError('machine with id [{0}] does not exist'
                                      .format(ctx.node_id))
        machines[ctx.node_id] = RUNNING
        ctx.runtime_properties['id'] = ctx.node_id
Ejemplo n.º 35
0
def retry(ctx, retry_count=1, retry_after=1, **kwargs):
    with update_storage(ctx) as data:
        invocations = data.get('retry_invocations', 0)
        if invocations != ctx.operation.retry_number:
            raise NonRecoverableError(
                'invocations({0}) != ctx.operation.retry_number'
                '({1})'.format(invocations, ctx.operation.retry_number))
        data['retry_invocations'] = invocations + 1
    if ctx.operation.retry_number < retry_count:
        return ctx.operation.retry(message='Retrying operation',
                                   retry_after=retry_after)
Ejemplo n.º 36
0
def make_reachable(ctx, **kwargs):
    state_info = {
        'id': ctx.instance.id,
        'time': time.time(),
        'capabilities': ctx.capabilities.get_all()
    }
    ctx.logger.info('Appending to state [node_id={0}, state={1}]'.format(
        ctx.instance.id, state_info))
    with update_storage(ctx) as data:
        data['state'] = data.get('state', [])
        data['state'].append(state_info)
Ejemplo n.º 37
0
def get_instance_ip_of_source_and_target(ctx, **_):
    with update_storage(ctx) as data:
        data['mock_operation_invocation'] = data.get(
            'mock_operation_invocation', [])
        data['mock_operation_invocation'].append(
            ('{}_source'.format(ctx.source.node.name),
             ctx.source.instance.host_ip))
        data['mock_operation_invocation'].append(
            ('{}_target'.format(ctx.target.node.name),
             ctx.target.instance.host_ip))
    return True
Ejemplo n.º 38
0
def start(**kwargs):
    with update_storage(ctx) as data:
        machines = data.get('machines', {})
        ctx.send_event('starting machine event')
        ctx.logger.info('cloudmock start: [node_id={0}, machines={1}]'.format(
            ctx.node_id, machines))
        if ctx.node_id not in machines:
            raise NonRecoverableError(
                'machine with id [{0}] does not exist'.format(ctx.node_id))
        machines[ctx.node_id] = RUNNING
        ctx.runtime_properties['id'] = ctx.node_id
Ejemplo n.º 39
0
def stop(ctx, **kwargs):
    agent_config = _fix_worker(ctx, **kwargs)
    worker_name = agent_config['name']
    ctx.logger.info('Stopping worker {0}'.format(worker_name))
    celery.control.cancel_consumer(queue=worker_name,
                                   destination=['celery.cloudify.management'])
    with update_storage(ctx) as data:
        data[worker_name] = data.get(worker_name, {})
        data[worker_name]['states'] = data[worker_name].get('states', [])
        data[worker_name]['states'].append('stopped')
        data[worker_name]['pids'] = []
Ejemplo n.º 40
0
def put_workflow_node_instance(ctx,
                               modification,
                               relationships):
    with update_storage(ctx) as data:
        state = data.get('state', {})
        data['state'] = state
        state[ctx.instance.id] = {
            'node_id': ctx.node.id,
            'modification': modification,
            'relationships': relationships
        }
Ejemplo n.º 41
0
def install(plugins, **kwargs):

    plugin_installer = get_backend()

    for plugin in plugins:
        with update_storage(ctx) as data:
            plugin_installer.install(plugin)
            plugin_name = plugin['name']
            data[ctx.task_target] = data.get(ctx.task_target, {})
            data[ctx.task_target][plugin_name] = \
                data[ctx.task_target].get(plugin_name, [])
            data[ctx.task_target][plugin_name].append('installed')
Ejemplo n.º 42
0
def mock_operation(ctx, **kwargs):
    mockprop = get_prop('mockprop', ctx, kwargs)
    with update_storage(ctx) as data:
        data['mock_operation_invocation'] = data.get(
            'mock_operation_invocation', [])
        data['mock_operation_invocation'].append({
            'id': ctx.instance.id,
            'mockprop': mockprop,
            'properties':
            {key: value
             for (key, value) in ctx.node.properties.items()}
        })
Ejemplo n.º 43
0
def host_get_state(ctx, **kwargs):
    with update_storage(ctx) as data:
        data['host_get_state_invocation'] = data.get(
            'host_get_state_invocation', []
        )
        data['host_get_state_invocation'].append(time.time())

    if len(data['host_get_state_invocation']) <= get_prop('false_count',
                                                          ctx,
                                                          kwargs):
        return False
    return True
Ejemplo n.º 44
0
def install_plugins(plugins, **_):

    plugin_installer = get_backend()

    for plugin in plugins:
        with update_storage(ctx) as data:
            plugin_installer.install(plugin)
            plugin_name = plugin['name']
            data[ctx.task_target] = data.get(ctx.task_target, {})
            data[ctx.task_target][plugin_name] = \
                data[ctx.task_target].get(plugin_name, [])
            data[ctx.task_target][plugin_name].append('installed')
Ejemplo n.º 45
0
def fail_user_exception(ctx, exception_type, **kwargs):
    with update_storage(ctx) as data:
        data['failure_invocation'] = data.get('failure_invocation', [])
        data['failure_invocation'].append(time.time())

    if exception_type == 'user_exception':
        raise UserException('Failing task on user defined exception')
    if exception_type == 'user_exception_recoverable':
        raise RecoverableUserException(
            'Failing task on user defined exception')
    if exception_type == 'user_exception_non_recoverable':
        raise NonRecoverableUserException(
            'Failing task on user defined exception')
Ejemplo n.º 46
0
def mock_operation(ctx, **kwargs):
    mockprop = get_prop('mockprop', ctx, kwargs)
    with update_storage(ctx) as data:
        data['mock_operation_invocation'] = data.get(
            'mock_operation_invocation', []
        )
        data['mock_operation_invocation'].append({
            'id': ctx.instance.id,
            'mockprop': mockprop,
            'properties': {
                key: value for (key, value) in ctx.node.properties.items()
            }
        })
Ejemplo n.º 47
0
def append_to_state(ctx):
    with update_storage(ctx) as data:
        data['state'] = data.get('state', [])
        data['state'].append({
            'id': ctx.node_id,
            'related_id': ctx.related.node_id,
            'time': time(),
            'properties': dict(ctx.properties),
            'runtime_properties': dict(ctx.runtime_properties),
            'related_properties': ctx.related.properties,
            'related_runtime_properties': ctx.related.runtime_properties,
            'capabilities': ctx.capabilities.get_all()
        })
Ejemplo n.º 48
0
def stop(ctx, **kwargs):
    agent_config = _fix_worker(ctx, **kwargs)
    worker_name = agent_config['name']
    ctx.logger.info('Stopping worker {0}'.format(worker_name))
    celery.control.cancel_consumer(
        queue=worker_name,
        destination=['celery.cloudify.management']
    )
    with update_storage(ctx) as data:
        data[worker_name] = data.get(worker_name, {})
        data[worker_name]['states'] = data[worker_name].get('states', [])
        data[worker_name]['states'].append('stopped')
        data[worker_name]['pids'] = []
Ejemplo n.º 49
0
def append_to_state(ctx):
    with update_storage(ctx) as data:
        data['state'] = data.get('state', [])
        data['state'].append({
            'id': ctx.node_id,
            'related_id': ctx.related.node_id,
            'time': time(),
            'properties': dict(ctx.properties),
            'runtime_properties': dict(ctx.runtime_properties),
            'related_properties': ctx.related.properties,
            'related_runtime_properties': ctx.related.runtime_properties,
            'capabilities': ctx.capabilities.get_all()
        })
Ejemplo n.º 50
0
def get_instance_ip_of_source_and_target(ctx, **_):
    with update_storage(ctx) as data:
        data['mock_operation_invocation'] = data.get(
            'mock_operation_invocation', []
        )
        data['mock_operation_invocation'].append((
            '{}_source'.format(ctx.source.node.name),
            ctx.source.instance.host_ip
        ))
        data['mock_operation_invocation'].append((
            '{}_target'.format(ctx.target.node.name),
            ctx.target.instance.host_ip
        ))
    return True
Ejemplo n.º 51
0
def append_to_state(ctx):
    with update_storage(ctx) as data:
        data['state'] = data.get('state', [])
        data['state'].append({
            'source_id': ctx.source.instance.id,
            'target_id': ctx.target.instance.id,
            'time': time(),
            'source_properties': dict(ctx.source.node.properties),
            'source_runtime_properties': dict(
                ctx.source.instance.runtime_properties),
            'target_properties': ctx.target.node.properties,
            'target_runtime_properties':
            ctx.target.instance.runtime_properties,
        })
Ejemplo n.º 52
0
def _operate_on_plugins(plugins, new_state):
    plugin_installer = get_backend()
    func = plugin_installer.install if 'installed' \
        else plugin_installer.uninstall
    for plugin in plugins:
        with update_storage(ctx) as data:
            func(plugin)
            plugin_name = plugin['name']
            task_target = ctx.task_target or 'local'
            data[task_target] = data.get(task_target, {})
            data[task_target][plugin_name] = \
                data[task_target].get(plugin_name, [])
            data[task_target][plugin_name].append(new_state)
        ctx.logger.info('Plugin {0} {1}'.format(plugin['name'], new_state))
Ejemplo n.º 53
0
def assertion(a=None, b=None, c=None, d=None, **_):
    if ctx.type == context.NODE_INSTANCE:
        assertEqual(a, 'a_value')
        assertEqual(b, 'b_value')
        assertEqual(c, None)
        assertEqual(d, None)
    else:
        assertEqual(a, None)
        assertEqual(b, None)
        assertEqual(c, 'c_value')
        assertEqual(d, 'd_value')
    with update_storage(ctx) as data:
        invocations = data.get('invocations', [])
        data['invocations'] = invocations
        invocations.append(ctx.type)
Ejemplo n.º 54
0
def assertion(a=None, b=None, c=None, d=None, **_):
    if ctx.type == context.NODE_INSTANCE:
        assertEqual(a, 'a_value')
        assertEqual(b, 'b_value')
        assertEqual(c, None)
        assertEqual(d, None)
    else:
        assertEqual(a, None)
        assertEqual(b, None)
        assertEqual(c, 'c_value')
        assertEqual(d, 'd_value')
    with update_storage(ctx) as data:
        invocations = data.get('invocations', [])
        data['invocations'] = invocations
        invocations.append(ctx.type)
Ejemplo n.º 55
0
def fail(ctx, **kwargs):
    fail_count = get_prop('fail_count', ctx, kwargs, 1000000)

    with update_storage(ctx) as data:
        data['failure_invocation'] = data.get('failure_invocation', [])
        data['failure_invocation'].append(time.time())

    if len(data['failure_invocation']) > fail_count:
        return

    message = 'TEST_EXPECTED_FAIL'
    non_recoverable = get_prop('non_recoverable', ctx, kwargs, False)
    recoverable = get_prop('recoverable', ctx, kwargs, False)
    retry_after = get_prop('retry_after', ctx, kwargs)

    if non_recoverable:
        exception = NonRecoverableError(message)
    elif recoverable:
        exception = RecoverableError(message, retry_after=retry_after)
    else:
        exception = RuntimeError(message)

    raise exception