Beispiel #1
0
def nodemgr(gstate: GlobalState) -> NodeMgr:

    from gravel.controllers.nodes.mgr import NodeStateModel

    nodemgr = NodeMgr(gstate)
    nodemgr._state = NodeStateModel(
        uuid="bba35d93-d4a5-48b3-804b-99c406555c89",
        address="1.2.3.4",
        hostname="foobar",
    )
    yield nodemgr
Beispiel #2
0
async def test_mgr_start(
    gstate: GlobalState,
    fs: fake_filesystem.FakeFilesystem,
    mocker: MockerFixture,
) -> None:

    from gravel.controllers.nodes.deployment import NodeStageEnum
    from gravel.controllers.nodes.mgr import NodeError, NodeStateModel

    nodemgr = NodeMgr(gstate)
    assert nodemgr._state
    assert nodemgr.deployment_state.can_start()

    orig = nodemgr.deployment_state.can_start
    nodemgr.deployment_state.can_start = mocker.MagicMock(return_value=False)
    throws = False
    try:
        await nodemgr.start()
    except NodeError as e:
        assert "unstartable" in e.message
        throws = True
    assert throws
    nodemgr.deployment_state.can_start = orig

    nodemgr._deployment._state._stage = NodeStageEnum.NONE
    nodemgr._node_prepare = mocker.AsyncMock()
    await nodemgr.start()
    nodemgr._node_prepare.assert_called_once()  # type: ignore

    nodemgr._deployment._state._stage = NodeStageEnum.READY
    nodemgr._state = NodeStateModel(
        uuid="bba35d93-d4a5-48b3-804b-99c406555c89",
        address="1.2.3.4",
        hostname="foobar",
    )

    nodemgr._start_ceph = mocker.AsyncMock()
    nodemgr._node_start = mocker.AsyncMock()

    await nodemgr.start()
    nodemgr._start_ceph.assert_called_once()  # type: ignore
    nodemgr._node_start.assert_called_once()  # type: ignore