tahoe-lafs/integration/test_grid_manager.py

181 lines
6.1 KiB
Python
Raw Normal View History

2018-11-28 01:06:53 -07:00
import sys
import time
import json
import shutil
from os import mkdir, unlink, listdir, utime
from os.path import join, exists, getmtime
2020-05-07 20:57:06 -06:00
from allmydata.crypto import ed25519
2018-11-28 01:06:53 -07:00
from allmydata.util import base32
from allmydata.util import configutil
2018-11-28 01:06:53 -07:00
import util
2020-05-12 16:57:37 -06:00
from grid import (
create_grid,
)
2018-11-28 01:06:53 -07:00
2019-04-08 19:42:39 -06:00
import pytest_twisted
2018-11-28 01:06:53 -07:00
2019-04-08 19:42:39 -06:00
@pytest_twisted.inlineCallbacks
2020-05-07 22:29:04 -06:00
def test_create_certificate(reactor, request):
"""
The Grid Manager produces a valid, correctly-signed certificate.
"""
2018-11-28 01:06:53 -07:00
gm_config = yield util.run_tahoe(
2020-05-07 22:29:04 -06:00
reactor, request, "grid-manager", "--config", "-", "create",
2018-11-28 01:06:53 -07:00
)
privkey_bytes = json.loads(gm_config)['private_key'].encode('ascii')
2020-05-07 20:57:06 -06:00
privkey, pubkey = ed25519.signing_keypair_from_string(privkey_bytes)
2018-11-28 01:06:53 -07:00
# Note that zara + her key here are arbitrary and don't match any
# "actual" clients in the test-grid; we're just checking that the
# Grid Manager signs this properly.
2018-11-28 01:06:53 -07:00
gm_config = yield util.run_tahoe(
2020-05-07 22:29:04 -06:00
reactor, request, "grid-manager", "--config", "-", "add",
"zara", "pub-v0-kzug3ut2m7ziihf3ndpqlquuxeie4foyl36wn54myqc4wmiwe4ga",
2018-11-28 01:06:53 -07:00
stdin=gm_config,
)
zara_cert_bytes = yield util.run_tahoe(
2020-05-07 22:29:04 -06:00
reactor, request, "grid-manager", "--config", "-", "sign", "zara",
2018-11-28 01:06:53 -07:00
stdin=gm_config,
)
zara_cert = json.loads(zara_cert_bytes)
2018-11-28 01:06:53 -07:00
# confirm that zara's certificate is made by the Grid Manager
2018-11-28 01:22:49 -07:00
# (.verify returns None on success, raises exception on error)
pubkey.verify(
base32.a2b(zara_cert['signature'].encode('ascii')),
zara_cert['certificate'].encode('ascii'),
2018-11-28 01:06:53 -07:00
)
2019-04-08 19:42:39 -06:00
@pytest_twisted.inlineCallbacks
2020-05-07 22:29:04 -06:00
def test_remove_client(reactor, request):
"""
A Grid Manager can add and successfully remove a client
"""
2018-11-28 01:06:53 -07:00
gm_config = yield util.run_tahoe(
2020-05-07 22:29:04 -06:00
reactor, request, "grid-manager", "--config", "-", "create",
2018-11-28 01:06:53 -07:00
)
2018-11-28 01:20:51 -07:00
gm_config = yield util.run_tahoe(
2020-05-07 22:29:04 -06:00
reactor, request, "grid-manager", "--config", "-", "add",
"zara", "pub-v0-kzug3ut2m7ziihf3ndpqlquuxeie4foyl36wn54myqc4wmiwe4ga",
2018-11-28 01:20:51 -07:00
stdin=gm_config,
)
gm_config = yield util.run_tahoe(
2020-05-07 22:29:04 -06:00
reactor, request, "grid-manager", "--config", "-", "add",
"yakov", "pub-v0-kvxhb3nexybmipkrar2ztfrwp4uxxsmrjzkpzafit3ket4u5yldq",
2018-11-28 01:20:51 -07:00
stdin=gm_config,
)
2020-05-07 14:40:10 -06:00
assert "zara" in json.loads(gm_config)['storage_servers']
assert "yakov" in json.loads(gm_config)['storage_servers']
2018-11-28 01:20:51 -07:00
gm_config = yield util.run_tahoe(
2020-05-07 22:29:04 -06:00
reactor, request, "grid-manager", "--config", "-", "remove",
"zara",
2018-11-28 01:20:51 -07:00
stdin=gm_config,
)
2020-05-07 14:40:10 -06:00
assert "zara" not in json.loads(gm_config)['storage_servers']
assert "yakov" in json.loads(gm_config)['storage_servers']
2018-11-28 01:20:51 -07:00
2019-04-08 19:42:39 -06:00
@pytest_twisted.inlineCallbacks
2020-05-07 22:29:04 -06:00
def test_remove_last_client(reactor, request):
2020-05-07 14:50:10 -06:00
"""
A Grid Manager can remove all clients
"""
2018-11-28 01:20:51 -07:00
gm_config = yield util.run_tahoe(
2020-05-07 22:29:04 -06:00
reactor, request, "grid-manager", "--config", "-", "create",
2018-11-28 01:20:51 -07:00
)
2018-11-28 01:06:53 -07:00
gm_config = yield util.run_tahoe(
2020-05-07 22:29:04 -06:00
reactor, request, "grid-manager", "--config", "-", "add",
"zara", "pub-v0-kzug3ut2m7ziihf3ndpqlquuxeie4foyl36wn54myqc4wmiwe4ga",
2018-11-28 01:06:53 -07:00
stdin=gm_config,
)
2020-05-07 14:40:10 -06:00
assert "zara" in json.loads(gm_config)['storage_servers']
2018-11-28 01:06:53 -07:00
gm_config = yield util.run_tahoe(
2020-05-07 22:29:04 -06:00
reactor, request, "grid-manager", "--config", "-", "remove",
"zara",
2018-11-28 01:06:53 -07:00
stdin=gm_config,
)
# there are no storage servers left at all now
2020-05-07 14:40:10 -06:00
assert "storage_servers" not in json.loads(gm_config)
2019-04-08 19:42:39 -06:00
@pytest_twisted.inlineCallbacks
2020-05-12 12:22:35 -06:00
def test_reject_storage_server(reactor, request, temp_dir, flog_gatherer, port_allocator):
2020-05-07 14:50:10 -06:00
"""
A client with happines=2 fails to upload to a Grid when it is
using Grid Manager and there is only 1 storage server with a valid
certificate.
2020-05-07 14:50:10 -06:00
"""
2020-05-12 12:22:35 -06:00
grid = yield create_grid(reactor, request, temp_dir, flog_gatherer, port_allocator)
storage0 = yield grid.add_storage_node()
storage1 = yield grid.add_storage_node()
gm_config = yield util.run_tahoe(
2020-05-07 22:29:04 -06:00
reactor, request, "grid-manager", "--config", "-", "create",
)
gm_privkey_bytes = json.loads(gm_config)['private_key'].encode('ascii')
gm_privkey, gm_pubkey = ed25519.signing_keypair_from_string(gm_privkey_bytes)
# create certificate for the first storage-server
pubkey_fname = join(storage0.process.node_dir, "node.pubkey")
with open(pubkey_fname, 'r') as f:
pubkey_str = f.read().strip()
gm_config = yield util.run_tahoe(
reactor, request, "grid-manager", "--config", "-", "add",
"storage0", pubkey_str,
stdin=gm_config,
)
assert json.loads(gm_config)['storage_servers'].keys() == ['storage0']
print("inserting certificate")
cert = yield util.run_tahoe(
reactor, request, "grid-manager", "--config", "-", "sign", "storage0",
stdin=gm_config,
)
yield util.run_tahoe(
reactor, request, "--node-directory", storage0.process.node_dir,
"admin", "add-grid-manager-cert",
"--name", "default",
2020-10-04 18:02:46 -06:00
"--filename", "-",
stdin=cert,
)
# re-start this storage server
yield storage0.restart(reactor, request)
# now only one storage-server has the certificate .. configure
# diana to have the grid-manager certificate
diana = yield grid.add_client("diana", needed=2, happy=2, total=2)
2020-05-12 12:22:35 -06:00
config = configutil.get_config(join(diana.process.node_dir, "tahoe.cfg"))
config.add_section("grid_managers")
config.set("grid_managers", "test", ed25519.string_from_verifying_key(gm_pubkey))
2020-05-12 12:22:35 -06:00
with open(join(diana.process.node_dir, "tahoe.cfg"), "w") as f:
config.write(f)
2020-05-07 14:54:50 -06:00
2020-05-12 16:57:37 -06:00
yield diana.restart(reactor, request, servers=2)
# try to put something into the grid, which should fail (because
# diana has happy=2 but should only find storage0 to be acceptable
# to upload to)
try:
yield util.run_tahoe(
2020-05-12 12:22:35 -06:00
reactor, request, "--node-directory", diana.process.node_dir,
"put", "-",
2020-05-07 22:29:04 -06:00
stdin="some content\n" * 200,
)
assert False, "Should get a failure"
except util.ProcessFailed as e:
assert 'UploadUnhappinessError' in e.output.getvalue()