Exemple #1
0
def test_corrupt_recover():
    daruma = Daruma.provision(providers, 3, 3)
    daruma.put("test", "data")
    providers[0].wipe()
    providers[2].wipe()

    Daruma.load(providers)
    assert daruma.get("test") == "data"
Exemple #2
0
def test_extra_providers():
    Daruma.provision(providers, 4, 4)
    daruma, extra_providers = Daruma.load(providers)
    assert extra_providers == []
    Daruma.provision(providers[:3], 2, 2)
    daruma, extra_providers = Daruma.load(providers)
    assert daruma.file_manager.providers == providers[:3]
    assert sorted(extra_providers) == sorted(providers[3:])
Exemple #3
0
def test_corrupt_fail():
    daruma = Daruma.provision(providers, 3, 3)
    daruma.put("test", "data")
    providers[0].wipe()
    providers[1].wipe()
    providers[2].wipe()

    with pytest.raises(exceptions.FatalOperationFailure):
        Daruma.load(providers)
Exemple #4
0
def test_permanently_offline_load():
    daruma = Daruma.provision(providers, 3, 3)
    daruma.put("test", "data")
    providers[0].set_state(TestProviderState.OFFLINE)
    daruma, _ = Daruma.load(providers)
    assert providers[0].status == ProviderStatus.RED
    assert daruma.get("test") == "data"
Exemple #5
0
def test_multiple_sessions():
    daruma = Daruma.provision(providers, 3, 3)
    daruma.put("test", "data")
    daruma.put("test2", "moredata")
    assert sorted(daruma.ls("")) == [{
        "name": "test",
        "is_directory": False,
        "size": 4
    }, {
        "name": "test2",
        "is_directory": False,
        "size": 8
    }]

    daruma, _ = Daruma.load(providers)
    assert sorted(daruma.ls("")) == [{
        "name": "test",
        "is_directory": False,
        "size": 4
    }, {
        "name": "test2",
        "is_directory": False,
        "size": 8
    }]
    assert daruma.get("test") == "data"
    assert daruma.get("test2") == "moredata"
Exemple #6
0
def test_temporary_offline_load():
    daruma = Daruma.provision(providers, 3, 3)
    daruma.put("test", "data")
    providers[0].set_state(TestProviderState.FAILING, 4)
    daruma, _ = Daruma.load(providers)
    assert daruma.get("test") == "data"
    assert providers[0].status == ProviderStatus.YELLOW
Exemple #7
0
def test_read_only_mode_fix_by_adding():
    daruma = Daruma.provision(providers, 3, 3)
    daruma.put("file", "data")

    daruma, _ = Daruma.load(providers[:3])

    with pytest.raises(exceptions.ReadOnlyMode):
        daruma.put("test", "file")

    missing_providers = providers[3:]
    assert sorted(daruma.get_missing_providers()) == sorted(
        map(lambda provider: provider.uuid, missing_providers))

    # try an invalid add_missing_provider call
    assert daruma.add_missing_provider(providers[0]) is False

    # add one missing provider
    assert daruma.add_missing_provider(missing_providers.pop())
    assert daruma.get_missing_providers() == map(
        lambda provider: provider.uuid, missing_providers)

    # make sure we can still get
    assert daruma.get("file") == "data"

    # but that we can't read
    with pytest.raises(exceptions.ReadOnlyMode):
        daruma.put("test", "file")

    # add the other missing provider
    assert daruma.add_missing_provider(missing_providers.pop())
    assert daruma.get_missing_providers() == []

    # check that we are out of read only mode
    daruma.put("test", "file")
    assert daruma.get("test") == "file"
Exemple #8
0
def test_attempt_repair_in_read_only():
    daruma = Daruma.provision(providers, 3, 3)
    daruma.put("test", "data")

    # load with only 4 providers, one of which is bad
    providers[0].set_state(TestProviderState.OFFLINE)
    daruma, _ = Daruma.load(providers[:4])

    assert daruma.get("test") == "data"
Exemple #9
0
def test_read_only_mode():
    daruma = Daruma.provision(providers, 3, 3)
    daruma.put("test", "file")

    daruma, _ = Daruma.load(providers[0:3])
    with pytest.raises(exceptions.ReadOnlyMode):
        daruma.put("test", "something else")

    assert sorted(daruma.get_missing_providers()) == sorted(
        map(lambda provider: provider.uuid, providers[3:]))

    # check that we can still read
    assert daruma.get("test") == "file"
Exemple #10
0
def try_load_instance():
    """
    Attempts to load Daruma instance from active providers
    Redirects to either status or confirmation page
    """
    # TODO make this asynchronous
    # TODO spinning daruma?
    if len(global_app_state.providers) < 3:
        return redirect("setup.html")
    try:
        # TODO handle extra providers
        global_app_state.daruma, extra_providers = Daruma.load(global_app_state.providers)
        return redirect("dashboard.html")
    except exceptions.FatalOperationFailure:
        return redirect("modal/show/confirm_provision")
Exemple #11
0
def test_read_only_mode_fix_by_removing():
    Daruma.provision(providers, 3, 3)

    provider_subset = providers[0:3]

    daruma, _ = Daruma.load(provider_subset)

    with pytest.raises(exceptions.ReadOnlyMode):
        daruma.put("test", "file")

    daruma.reprovision(provider_subset, 2, 2)

    # check that we are out of read only mode
    daruma.put("test", "file")
    assert daruma.get("test") == "file"
Exemple #12
0
def test_add_provider():
    daruma = Daruma.provision(providers[0:4], 3, 3)
    daruma.put("test", "data")
    daruma.reprovision(providers, 4, 4)

    assert daruma.get("test") == "data"
    # check that we can bootstrap
    daruma, _ = Daruma.load(providers)

    # check that k has been changed
    providers[0].wipe()
    providers[1].wipe()

    with pytest.raises(exceptions.FatalOperationFailure):
        daruma.get("test")
Exemple #13
0
def test_different_ks():
    bootstrap_reconstruction_threshold = 3
    file_reconstruction_threshold = 2
    daruma = Daruma.provision(providers, bootstrap_reconstruction_threshold,
                              file_reconstruction_threshold)

    daruma.put("test", "data")
    providers[0].wipe()
    providers[1].wipe()

    # should be able to recover the key
    daruma, _ = Daruma.load(providers)

    providers[0].wipe()
    providers[1].wipe()
    providers[2].wipe()

    # but now can't recover the key
    with pytest.raises(Exception):
        Daruma.load(providers, 3, 2)

    # should still be able to recover the files
    # even though 3rd provider went down after initializing
    assert daruma.get("test") == "data"
Exemple #14
0
def test_remove_provider():
    daruma = Daruma.provision(providers, 4, 4)
    daruma.put("test", "data")

    daruma.reprovision(providers[0:4], 3, 3)

    assert daruma.get("test") == "data"

    # check that we can bootstrap
    daruma, _ = Daruma.load(providers[0:4])
    assert daruma.get("test") == "data"

    # check that k has been changed
    providers[0].wipe()

    assert daruma.get("test") == "data"
Exemple #15
0
def test_reprovision_remove_bad():
    daruma = Daruma.provision(providers, 4, 4)
    daruma.put("test", "data")

    providers[-1].set_state(TestProviderState.OFFLINE)

    daruma.reprovision(providers[:-1], 3, 3)

    assert daruma.get("test") == "data"

    # check that we can bootstrap
    daruma, _ = Daruma.load(providers[0:-1])
    assert daruma.get("test") == "data"

    # check that k has been changed
    providers[0].wipe()

    assert daruma.get("test") == "data"
Exemple #16
0
 def do_load(self, line=None):
     """
     Attempt to load Daruma from the added providers
     """
     global daruma
     # if we were able to load at least 2 providers, attempt to load an existing instance
     # 2 because we may be trying to load a 3-provider instance in read only mode
     try:
         assert len(providers) >= 2
         daruma, extra_providers = Daruma.load(providers)
         print "Loaded an existing installation"
         if len(extra_providers) > 0:
             print "Some providers were not part of the loaded installation:", map(
                 lambda provider: provider.uuid, extra_providers)
             print "Type 'reprovision' at the 'Daruma>' prompt if you would like to configure Daruma to use these providers"
         return True
     except AssertionError:
         print "Looks like you need to add more providers! Type 'add' to get started."
     except exceptions.FatalOperationFailure:
         print "Looks like there's no existing installation with these providers."
         print "If this is correct, type 'provision' to start a new instance. If not, type 'add' to add more providers."
     return False
Exemple #17
0
        name="filesytem_watcher_thread")
    filesystem_watcher_thread.daemon = True
    filesystem_watcher_thread.start()

    # Start native UI
    app_menu.MainLoop()
    app_state.filesystem_watcher.stop()


if __name__ == "__main__":
    logging.basicConfig(filename='daruma_run.log',
                        filemode='w',
                        level=logging.ERROR)
    logging.getLogger("daruma").setLevel(logging.DEBUG)

    platform_specific_setup()

    app_state = ApplicationState()
    providers, errors = app_state.provider_manager.load_all_providers_from_credentials(
    )
    logger.error("loading errors:" + str(errors))
    try:
        assert len(providers) >= 2
        app_state.daruma, extra_providers = Daruma.load(providers)
        app_state.providers = providers
        app_state.needs_reprovision = len(extra_providers) > 0 or len(
            app_state.daruma.get_missing_providers()) > 0
    except (AssertionError, exceptions.FatalOperationFailure):
        app_state.providers = providers
    launch_gui(app_state)