Exemple #1
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 #2
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 #3
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 #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_offline_provision():
    providers[0].set_state(TestProviderState.FAILING, 4)
    with pytest.raises(exceptions.FatalOperationFailure) as excinfo:
        Daruma.provision(providers, 3, 3)
    failures = excinfo.value.failures
    assert len(failures) == 1
    assert failures[0].provider == providers[0]
Exemple #6
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 #7
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 #8
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 #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 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 #11
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 #12
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 #13
0
def test_reprovision_add_bad():
    daruma = Daruma.provision(providers[:-1], 3, 3)
    daruma.put("test", "data")

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

    with pytest.raises(exceptions.FatalOperationFailure):
        daruma.reprovision(providers, 4, 4)
Exemple #14
0
def test_temporary_offline_put():
    daruma = Daruma.provision(providers, 3, 3)
    # failing for 2 turns
    providers[0].set_state(TestProviderState.FAILING, 2)
    daruma.put("test", "data")

    assert daruma.get("test") == "data"
    assert providers[0].status == ProviderStatus.YELLOW
Exemple #15
0
def test_roundtrip():
    daruma = Daruma.provision(providers, 3, 3)
    daruma.put("test", "data")
    assert daruma.ls("") == [{
        "name": "test",
        "is_directory": False,
        "size": 4
    }]
    assert daruma.get("test") == "data"
Exemple #16
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 #17
0
def test_list_paths():
    daruma = Daruma.provision(providers, 2, 2)

    daruma.put("file1", "data1")
    daruma.put("file2", "data2")
    daruma.put("dir1/file3", "data3")
    daruma.mk_dir("dir1/dir2")

    expected_paths = ["file1", "file2", "dir1", "dir1/file3", "dir1/dir2"]

    assert sorted(daruma.list_all_paths()) == sorted(expected_paths)
Exemple #18
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 #19
0
def test_wiped_provider():
    daruma = Daruma.provision(providers, 3, 3)
    daruma.put("test", "data")

    providers[0].wipe()

    # check that repairs happen properly
    assert daruma.get("test") == "data"
    assert providers[0].status == ProviderStatus.YELLOW

    # check that the 0th provider is now fully operational
    providers[3].set_state(TestProviderState.OFFLINE)
    providers[4].set_state(TestProviderState.OFFLINE)
    assert daruma.get("test") == "data"
Exemple #20
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 #21
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 #22
0
def try_provision_instance():
    """
    Attempt to provision a Daruma object given the current list of providers.
    """
    try:
        global_app_state.daruma = Daruma.provision(global_app_state.providers,
                                                   len(global_app_state.providers) - 1,
                                                   len(global_app_state.providers) - 1)
        global_native_app.mark_setup_complete()
        global_app_state.filesystem_watcher.bulk_update_filesystem()
        return jsonify({"success": True})
    except exceptions.FatalOperationFailure as e:
        return jsonify({
            "success": False,
            "errors": map(lambda failure: (failure.provider.provider_name(), failure.provider.uid), e.failures)
        })
Exemple #23
0
 def do_provision(self, line=None):
     """
     Attempt to start a new Daruma on the added providers
     """
     global daruma
     # if we were able to load at least 3 providers, attempt to load an existing instance
     try:
         assert len(providers) >= 3
         threshold = len(providers) - 1
         daruma = Daruma.provision(providers, threshold, threshold)
         print "Created a new installation"
     except AssertionError:
         print "Looks like you need to add more providers! Type 'add' to get started."
     except exceptions.FatalOperationFailure as e:
         print "We were unable to create an instance because of errors with", map(
             lambda failure: failure.provider.uuid, e.failures)
Exemple #24
0
def test_return_to_yellow():
    daruma = Daruma.provision(providers, 3, 3)
    daruma.put("test", "data")

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

    daruma.get("test")

    assert providers[0].status == ProviderStatus.RED
    assert providers[1].status == ProviderStatus.RED

    providers[0].set_state(TestProviderState.ACTIVE)
    providers[1].set_state(TestProviderState.ACTIVE)

    daruma.get("test")

    assert providers[0].status == ProviderStatus.YELLOW
    assert providers[1].status == ProviderStatus.YELLOW
Exemple #25
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 #26
0
def test_delete():
    daruma = Daruma.provision(providers, 3, 3)
    daruma.put("test", "data")
    daruma.delete("test")
    with pytest.raises(exceptions.FileNotFound):
        daruma.get("test")
Exemple #27
0
def test_update():
    daruma = Daruma.provision(providers, 3, 3)
    daruma.put("test", "data")
    daruma.put("test", "newdata")
    assert daruma.get("test") == "newdata"
Exemple #28
0
def test_corrupting():
    daruma = Daruma.provision(providers, 3, 3)
    daruma.put("test", "data")
    providers[0].set_state(TestProviderState.CORRUPTING)
    assert daruma.get("test") == "data"
    assert providers[0].status == ProviderStatus.YELLOW
Exemple #29
0
def test_permanently_authfail_get():
    daruma = Daruma.provision(providers, 3, 3)
    daruma.put("test", "data")
    providers[0].set_state(TestProviderState.UNAUTHENTICATED)
    assert daruma.get("test") == "data"
    assert providers[0].status == ProviderStatus.AUTH_FAIL
Exemple #30
0
def test_permanently_offline_put():
    daruma = Daruma.provision(providers, 3, 3)
    providers[0].set_state(TestProviderState.OFFLINE)
    with pytest.raises(exceptions.FatalOperationFailure):
        daruma.put("test", "data")
    assert providers[0].status == ProviderStatus.RED