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]
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:])
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"
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"
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"
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
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"
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)
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"
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
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)
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"
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"
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)
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"
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"
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")
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) })
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"
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)
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"
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
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"
def test_update(): daruma = Daruma.provision(providers, 3, 3) daruma.put("test", "data") daruma.put("test", "newdata") assert daruma.get("test") == "newdata"
def test_get_nonexistent(): daruma = Daruma.provision(providers, 3, 3) with pytest.raises(exceptions.FileNotFound): daruma.get("blah")
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
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
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
def test_delete(): daruma = Daruma.provision(providers, 3, 3) daruma.put("test", "data") daruma.delete("test") with pytest.raises(exceptions.FileNotFound): daruma.get("test")
def test_init(): daruma = Daruma.provision(providers, 3, 3) assert len(daruma.ls("")) == 0