Esempio n. 1
0
async def test_bootstrap_finisher_cb(gstate: GlobalState,
                                     mocker: MockerFixture,
                                     nodemgr: NodeMgr) -> None:

    from gravel.controllers.nodes.mgr import NodeInitStage

    nodemgr._init_stage = NodeInitStage.NONE
    assert await expect_assertion(nodemgr._post_bootstrap_finisher(True, None))
    nodemgr._init_stage = NodeInitStage.PREPARE
    assert await expect_assertion(nodemgr._post_bootstrap_finisher(True, None))
    nodemgr._init_stage = NodeInitStage.STARTED
    assert await expect_assertion(nodemgr._post_bootstrap_finisher(True, None))

    nodemgr._init_stage = NodeInitStage.AVAILABLE
    nodemgr._save_state = mocker.AsyncMock()
    nodemgr._post_bootstrap_config = mocker.AsyncMock()

    await nodemgr._post_bootstrap_finisher(True, None)

    nodemgr._save_state.assert_called_once()  # type: ignore
    nodemgr._post_bootstrap_config.assert_called_once()  # type: ignore
Esempio n. 2
0
async def test_join(gstate: GlobalState, mocker: MockerFixture,
                    nodemgr: NodeMgr) -> None:

    from uuid import UUID

    from gravel.controllers.inventory.disks import DiskDevice
    from gravel.controllers.nodes.deployment import DeploymentDisksConfig
    from gravel.controllers.nodes.disks import DiskSolution
    from gravel.controllers.nodes.mgr import JoinParamsModel, NodeInitStage

    def mock_solution(gstate: GlobalState) -> DiskSolution:
        return DiskSolution(
            systemdisk=DiskDevice(
                id="foo01",
                name="foo",
                path="/dev/foo",
                product="Foo",
                vendor="Foo Inc",
                size=1000,
                rotational=False,
                available=True,
                rejected_reasons=[],
            ),
            storage=[
                DiskDevice(
                    id="bar01",
                    name="bar",
                    path="/dev/bar",
                    product="Bar",
                    vendor="Bar LLC",
                    size=2000,
                    rotational=False,
                    available=True,
                    rejected_reasons=[],
                ),
                DiskDevice(
                    id="baz01",
                    name="baz",
                    path="/dev/baz",
                    product="Baz",
                    vendor="Baz Ltd",
                    size=2000,
                    rotational=False,
                    available=True,
                    rejected_reasons=[],
                ),
            ],
            storage_size=4000,
            possible=True,
        )

    async def mock_join(
        leader_address: str,
        token: str,
        uuid: UUID,
        hostname: str,
        address: str,
        disks: DeploymentDisksConfig,
    ) -> bool:
        assert leader_address == "10.1.2.3"
        assert token == "751b-51fd-10d7-f7b4"
        assert str(uuid) == "bba35d93-d4a5-48b3-804b-99c406555c89"
        assert hostname == "foobar"
        assert address == "1.2.3.4"
        assert disks.system == "/dev/foo"
        assert len(disks.storage) == 2
        assert "/dev/bar" in disks.storage
        assert "/dev/baz" in disks.storage
        return True

    mocker.patch("gravel.controllers.nodes.disks.Disks.gen_solution",
                 new=mock_solution)

    nodemgr._init_stage = NodeInitStage.AVAILABLE

    nodemgr._deployment.join = mocker.AsyncMock(side_effects=Exception())
    throws = False
    try:
        await nodemgr.join(
            "10.1.2.3",
            "751b-51fd-10d7-f7b4",
            JoinParamsModel(hostname="foobar"),
        )
    except Exception:
        throws = True
    assert throws
    nodemgr._deployment.join.assert_called_once()  # type: ignore

    nodemgr._deployment.join = mocker.AsyncMock(return_value=False)
    res = await nodemgr.join("10.1.2.3", "751b-51fd-10d7-f7b4",
                             JoinParamsModel(hostname="foobar"))
    assert not res
    nodemgr._deployment.join.assert_called_once()  # type: ignore

    nodemgr._save_state = mocker.AsyncMock()
    nodemgr._node_start = mocker.AsyncMock()
    nodemgr._deployment.join = mock_join
    res = await nodemgr.join("10.1.2.3", "751b-51fd-10d7-f7b4",
                             JoinParamsModel(hostname="foobar"))
    assert res
    assert nodemgr._token == "751b-51fd-10d7-f7b4"
    nodemgr._save_state.assert_called_once()  # type: ignore
    nodemgr._node_start.assert_called_once()  # type: ignore