Пример #1
0
def test_init(gstate: GlobalState, fs: fake_filesystem.FakeFilesystem) -> None:

    nodemgr = NodeMgr(gstate)
    nodemgr.init()
    assert fs.exists("/etc/aquarium/node.json")

    # clean up
    for f in fs.listdir("/etc/aquarium"):
        fs.remove(f"/etc/aquarium/{f}")
Пример #2
0
def test_fail_init(gstate: GlobalState,
                   fs: fake_filesystem.FakeFilesystem) -> None:

    from gravel.controllers.nodes.mgr import NodeError

    if fs.exists("/etc/aquarium/node.json"):
        fs.remove("/etc/aquarium/node.json")
    fs.create_dir("/etc/aquarium/node.json")
    throws = False
    nodemgr = NodeMgr(gstate)
    try:
        nodemgr.init()
    except NodeError:
        throws = True
    except Exception:
        assert False
    assert throws
    # clean up
    fs.rmdir("/etc/aquarium/node.json")
Пример #3
0
async def aquarium_main_task(
    app: FastAPI,
    config: Config,
    kvstore: KV,
    gstate: GlobalState,
    nodemgr: NodeMgr,
    deployment: DeploymentMgr,
) -> None:
    logger.debug("Starting main Aquarium task.")

    app.state.deployment = deployment
    app.state.nodemgr = nodemgr

    while not _shutting_down and not deployment.installed:
        logger.debug("Waiting for node to be installed.")
        await asyncio.sleep(1.0)

    if _shutting_down:
        return

    assert deployment.installed

    try:
        await deployment.init()
    except InitError as e:
        logger.error(f"Unable to init node: {e.message}")
        sys.exit(1)

    logger.info("Init Node Manager.")
    config.init()
    kvstore.init()
    gstate_init(gstate, nodemgr)
    nodemgr.init()

    logger.info("Starting Node Manager.")
    await nodemgr.start()
    await gstate.start()

    logger.info("Post-Init Deployment.")
    deployment.postinit(gstate, nodemgr)

    app.state.gstate = gstate