Commit 6c8639d2 authored by juga's avatar juga
Browse files

stem: log stem's exceptions setting runtime torrc

The log message might not correspond to the reason.
Only the first one that fails will be logged, but not refactoring
here.
Add an integration test to check a runtime option fails.
parent 1d836ec5
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -173,10 +173,10 @@ def set_torrc_runtime_options(controller):
    """Set torrc options at runtime."""
    try:
        controller.set_options(TORRC_RUNTIME_OPTIONS)
    except (ControllerError, InvalidArguments, InvalidRequest) as e:
        log.exception("Error trying to launch tor: %s. "
                      "Maybe the tor directory is being used by other "
                      "sbws instance?", e)
    # Only the first option that fails will be logged here.
    # Just log stem's exceptions.
    except (ControllerError, InvalidRequest, InvalidArguments) as e:
        log.exception(e)
        exit(1)

def launch_tor(conf):
+8 −0
Original line number Diff line number Diff line
@@ -10,3 +10,11 @@ def test_set_torrc_runtime_option_succesful(persistent_launch_tor):
    controller = persistent_launch_tor
    runtime_options = controller.get_conf_map(['__LeaveStreamsUnattached'])
    assert runtime_options == {'__LeaveStreamsUnattached': ['1']}


def test_set_torrc_runtime_invalidrequest_option_fail(persistent_launch_tor):
    controller = persistent_launch_tor
    try:
        controller.set_conf('ControlSocket', '/tmp/dummy')
    except stem_utils.InvalidRequest as e:
        assert "Unable to set option" in e.message