コード例 #1
0
    def test_run_error(self, mock_timer, mock_connect, mock_human_api,
                       mock_deployment_get):
        mock_deployment_get.return_value = {"config": {}}
        injector_inst = mock_connect.return_value
        mock_human_api.side_effect = error.OSFException("foo error")
        hook = fault_injection.FaultInjectionHook(self.task, {
            "action": "foo",
            "verify": True
        }, {"iteration": 1})

        hook.run_sync()

        self.assertEqual(
            {
                "finished_at": fakes.FakeTimer().finish_timestamp(),
                "started_at": fakes.FakeTimer().timestamp(),
                "status": consts.HookStatus.FAILED,
                "error": {
                    "details": mock.ANY,
                    "etype": "OSFException",
                    "msg": "foo error"
                },
                "triggered_by": {
                    "iteration": 1
                }
            }, hook.result())

        mock_connect.assert_called_once_with(None)
        injector_inst.verify.assert_called_once_with()
        mock_human_api.assert_called_once_with(injector_inst, "foo")
コード例 #2
0
ファイル: human.py プロジェクト: weezer/os-faults
def execute(destructor, command):
    command = command.lower()
    rec = None
    for pattern in PATTERNS:
        rec = re.search(pattern, command)
        if rec:
            break

    if not rec:
        raise error.OSFException('Could not parse command: %s' % command)

    groups = rec.groupdict()

    action = groups.get('action').replace(' ', '_')
    service_name = groups.get('service')
    node_name = groups.get('node')
    network_name = groups.get('network')
    duration = groups.get('duration')

    if service_name:
        service = destructor.get_service(name=service_name)

        if action in SERVICE_ACTIONS:

            kwargs = {}
            if node_name in RANDOMNESS:
                kwargs['nodes'] = service.get_nodes().pick()
            elif node_name:
                kwargs['nodes'] = destructor.get_nodes(fqdns=[node_name])

            if duration:
                kwargs['sec'] = int(duration)

            fn = getattr(service, action)
            fn(**kwargs)

        else:  # node actions
            nodes = service.get_nodes()

            if node_name in RANDOMNESS:
                nodes = nodes.pick()

            kwargs = {}
            if network_name:
                kwargs['network_name'] = network_name

            fn = getattr(nodes, action)
            fn(**kwargs)
    else:  # nodes operation
        nodes = destructor.get_nodes(fqdns=[node_name])

        kwargs = {}
        if network_name:
            kwargs['network_name'] = network_name

        fn = getattr(nodes, action)
        fn(**kwargs)
コード例 #3
0
ファイル: human.py プロジェクト: MaxBab/os-faults
def execute(destructor, command):
    command = command.lower()
    rec = None
    for pattern in PATTERNS:
        rec = re.search(pattern, command)
        if rec:
            break

    if not rec:
        raise error.OSFException('Could not parse command: %s' % command)

    groups = rec.groupdict()

    action = groups.get('action').replace(' ', '_')
    service_name = groups.get('service')
    container_name = groups.get('container')
    node_name = groups.get('node')
    network_name = groups.get('network')
    target = groups.get('target')
    duration = groups.get('duration')

    if service_name:
        service = destructor.get_service(name=service_name)

        if action in SERVICE_ACTIONS:

            kwargs = {}
            if node_name in RANDOMNESS:
                kwargs['nodes'] = service.get_nodes().pick()
            elif node_name and node_name not in ANYTHING:
                kwargs['nodes'] = destructor.get_nodes(fqdns=[node_name])

            if duration:
                kwargs['sec'] = int(duration)

            fn = getattr(service, action)
            fn(**kwargs)

        else:  # node actions
            nodes = service.get_nodes()

            if node_name in RANDOMNESS:
                nodes = nodes.pick()

            kwargs = {}
            if network_name:
                kwargs['network_name'] = network_name
            if target:
                kwargs['target'] = target
                kwargs['duration'] = int(duration)

            fn = getattr(nodes, action)
            fn(**kwargs)
    elif container_name:
        container = destructor.get_container(name=container_name)

        if action in CONTAINER_ACTIONS:

            kwargs = {}
            if node_name in RANDOMNESS:
                kwargs['nodes'] = container.get_nodes().pick()
            elif node_name and node_name not in ANYTHING:
                kwargs['nodes'] = destructor.get_nodes(fqdns=[node_name])

            if duration:
                kwargs['sec'] = int(duration)

            fn = getattr(container, action)
            fn(**kwargs)

        else:  # node actions
            nodes = container.get_nodes()

            if node_name in RANDOMNESS:
                nodes = nodes.pick()

            kwargs = {}
            if network_name:
                kwargs['network_name'] = network_name
            if target:
                kwargs['target'] = target
                kwargs['duration'] = int(duration)

            fn = getattr(nodes, action)
            fn(**kwargs)
    else:  # nodes operation
        if node_name and node_name not in ANYTHING:
            nodes = destructor.get_nodes(fqdns=[node_name])
        else:
            nodes = destructor.get_nodes()

        kwargs = {}
        if network_name:
            kwargs['network_name'] = network_name
        if target:
            kwargs['target'] = target
            kwargs['duration'] = int(duration)

        fn = getattr(nodes, action)
        fn(**kwargs)

    LOG.info('Command `%s` is executed successfully', command)