Esempio n. 1
0
def test_path():
    res = resource.Resource(name="bill")
    res.path = NODE_DATA_0
    assert res._path == "/dev/drbd1000"

    res = resource.Resource(name="bill2000")
    res.path = NODE_DATA_0
    assert res._path == "/dev/drbd1003"

    res = resource.Resource(name="OpenNebula-Image-210-vm58-disk1")
    with pytest.raises(IndexError):
        res.path = NODE_DATA_1
Esempio n. 2
0
def test_snapshots():
    snap_list = json.loads(SNAP_DATA_0)[0]["snapshot_dfns"]

    res = resource.Resource(name="OpenNebula-Image-229")
    assert set(res._snapshots(snap_list)) == set(["potato"])

    res = resource.Resource(name="OpenNebula-Image-224")
    assert set(res._snapshots(snap_list)) == set([
        "OpenNebula-Snap-1", "OpenNebula-Snap-3", "OpenNebula-Snap-4", "potato"
    ])

    res = resource.Resource(name="no-snapshots")
    assert set(res._snapshots(snap_list)) == set([])
Esempio n. 3
0
def test_space_reporting():
    res = resource.Resource(name="test-resource-please-ignore",
                            storage_pool="thin")
    res._update_storage_info(STORAGE_POOL_DATA_0)
    assert res._storage_pool_free_MiB == 36435
    assert res._storage_pool_used_MiB == 6525
    assert res._storage_pool_total_MiB == 42960

    # More redundancy means less usable space.
    res = resource.Resource(name="test-resource-please-ignore",
                            storage_pool="thin",
                            auto_place="4")
    res._update_storage_info(STORAGE_POOL_DATA_0)
    assert res._storage_pool_free_MiB == 9108
    assert res._storage_pool_used_MiB == 1632
    assert res._storage_pool_total_MiB == 10740

    # Node-based deployments can only use the space from those nodes.
    res = resource.Resource(name="test-resource-please-ignore",
                            storage_pool="thin",
                            nodes=["attila"])
    res._update_storage_info(STORAGE_POOL_DATA_0)
    assert res._storage_pool_free_MiB == 11065
    assert res._storage_pool_used_MiB == 3255
    assert res._storage_pool_total_MiB == 14320

    # Node-based deployments can only use the space from those nodes
    # and must place them on every node, so only count the most
    # space-restricted node.
    res = resource.Resource(
        name="test-resource-please-ignore",
        storage_pool="thin",
        nodes=["attila", "boudicca"],
    )
    res._update_storage_info(STORAGE_POOL_DATA_0)
    assert res._storage_pool_free_MiB == 11065
    assert res._storage_pool_used_MiB == 3255
    assert res._storage_pool_total_MiB == 14320

    with pytest.raises(KeyError):
        res = resource.Resource(
            name="test-resource-please-ignore",
            storage_pool="thin",
            nodes=["attila", "boudicca", "bogus.node"],
        )
        res._update_storage_info(STORAGE_POOL_DATA_0)
Esempio n. 4
0
def test_is_client():
    res = resource.Resource(name="bill2000")
    assert res._is_client(NODE_DATA_0, "boudicca") is True

    res = resource.Resource(name="bill2000")
    assert res._is_client(NODE_DATA_0, "attila") is False

    res = resource.Resource(name="bill")
    assert res._is_client(NODE_DATA_0, "boudicca") is False

    res = resource.Resource(name="fake-resource")
    with pytest.raises(IndexError):
        assert res._is_client(NODE_DATA_0, "boudicca") is False

    res = resource.Resource(name="bill2000")
    with pytest.raises(IndexError):
        assert res._is_client(NODE_DATA_0, "fake-node") is False

    res = resource.Resource(name="fake-resource")
    with pytest.raises(IndexError):
        assert res._is_client(NODE_DATA_0, "fake-node") is False
Esempio n. 5
0
def test_get_node_interface():
    res = resource.Resource(name="bill")
    assert res._get_node_interface(INTERFACE_DATA,
                                   "vercingetorix") == "192.168.6.190"
Esempio n. 6
0
def test_deployment_nodes():
    res = resource.Resource(name="bill")
    assert set(res._deployed_nodes(
        json.loads(NODE_DATA_0)[0]["resources"])) == set(
            ["charlemagne", "boudicca", "attila"])