Example #1
0
def test_volume_throttle_positive(client, kw, result):

    with mock.patch("pyscaleio.models.Volume.__scheme__", {}):
        volume = Volume(instance={"id": "test", "links": []})

    with mock.patch("pyscaleio.ScaleIOClient.perform_action_on") as m:
        volume.throttle(**kw)
        m.assert_called_once_with("Volume", "test", "setMappedSdcLimits", result)
Example #2
0
def test_volume_unexport(client, kw, result):

    with mock.patch("pyscaleio.models.Volume.__scheme__", {}):
        volume = Volume(instance={"id": "test", "links": []})

    with mock.patch("pyscaleio.ScaleIOClient.perform_action_on") as m:
        volume.unexport(**kw)
        m.assert_called_once_with("Volume", "test", "removeMappedSdc", result)
Example #3
0
def test_volume_unexport(client, kw, result):

    with mock.patch("pyscaleio.models.Volume.__scheme__", {}):
        volume = Volume(instance={"id": "test", "links": []})

    with mock.patch("pyscaleio.ScaleIOClient.perform_action_on") as m:
        volume.unexport(**kw)
        m.assert_called_once_with("Volume", "test", "removeMappedSdc", result)
Example #4
0
def test_volume_throttle_positive(client, kw, result):

    with mock.patch("pyscaleio.models.Volume.__scheme__", {}):
        volume = Volume(instance={"id": "test", "links": []})

    with mock.patch("pyscaleio.ScaleIOClient.perform_action_on") as m:
        volume.throttle(**kw)
        m.assert_called_once_with("Volume", "test", "setMappedSdcLimits",
                                  result)
Example #5
0
def test_volume_throttle_negative(client, kw, exception):

    with mock.patch("pyscaleio.models.Volume.__scheme__", {}):
        volume = Volume(instance={"id": "test", "links": []})

    with mock.patch("pyscaleio.ScaleIOClient.perform_action_on") as m:
        with pytest.raises(exception):
            volume.throttle(**kw)
        m.assert_not_called()
Example #6
0
def test_volume_throttle_negative(client, kw, exception):

    with mock.patch("pyscaleio.models.Volume.__scheme__", {}):
        volume = Volume(instance={"id": "test", "links": []})

    with mock.patch("pyscaleio.ScaleIOClient.perform_action_on") as m:
        with pytest.raises(exception):
            volume.throttle(**kw)
        m.assert_not_called()
Example #7
0
def test_volume_create(client, kw, result):

    args = (1, "test_pool")
    full_result = {
        "volumeSizeInKb": str(1048576),
        "storagePoolId": "test_pool",
        "volumeType": constants.VOLUME_TYPE_THIN,
    }
    full_result.update(result)

    with mock.patch("pyscaleio.models.MutableResource.create") as m:
        Volume.create(*args, **kw)
        m.assert_called_once_with(full_result)
Example #8
0
def test_volume_create(client, kw, result):

    args = (1, "test_pool")
    full_result = {
        "volumeSizeInKb": str(1048576),
        "storagePoolId": "test_pool",
        "volumeType": constants.VOLUME_TYPE_THIN,
    }
    full_result.update(result)

    with mock.patch("pyscaleio.models.MutableResource.create") as m:
        Volume.create(*args, **kw)
        m.assert_called_once_with(full_result)
Example #9
0
def test_volume_model_exports(client):

    volume_exports = [{
        "sdcId": "sdc01",
        "sdcIp": "127.0.0.1",
        "limitIops": 0,
        "limitBwInMbps": 0
    }]
    volume_payload = mock_resource_get(Volume._get_name(), "test",
        mock_volume({
            "id": "test",
            "mappedSdcInfo": volume_exports
        })
    )
    sdc_payloads = [mock_resource_get(Sdc._get_name(), sdc_id, {
        "id": sdc_id,
        "sdcIp": sdc_id,
        "sdcGuid": str(uuid.uuid4()),
        "sdcApproved": True,
        "mdmConnectionState": constants.SDC_MDM_STATE_CONNECTED,
    }) for sdc_id in ("sdc0{0}".format(i) for i in range(1, 3))]

    with httmock.HTTMock(login_payload, volume_payload):
        volume = Volume("test")

        assert volume.exports
        assert isinstance(volume.exports, (Sequence, ExportsInfo))

    with httmock.HTTMock(*sdc_payloads):
        sdc1 = Sdc("sdc01")
        sdc2 = Sdc("sdc02")

        assert sdc1 in volume.exports
        assert sdc2 not in volume.exports
        assert "some_string" not in volume.exports
Example #10
0
def test_volume_model(client):

    volume_payload = mock_resource_get(Volume._get_name(), "test",
                                       mock_volume({"id": "test"}))
    system_payload = mock_resources_get(System._get_name(), [{"id": "system"}])
    with httmock.HTTMock(login_payload, volume_payload, system_payload):
        volume = Volume("test")

        assert volume.name is None
        assert volume.size == 8 * constants.GIGABYTE
        assert volume.type == constants.VOLUME_TYPE_THICK
        assert isinstance(volume.exports, Sequence)
        assert not volume.exports

        with mock.patch("pyscaleio.models.System.__scheme__", {}):
            assert volume.path == "/dev/disk/by-id/emc-vol-system-test"
Example #11
0
def test_volume_unexport_negative(client, method):

    with mock.patch("pyscaleio.models.Volume.__scheme__", {}):
        volume = Volume(instance={"id": "test", "links": []})

    with mock.patch("pyscaleio.ScaleIOClient.perform_action_on") as m:
        with pytest.raises(exceptions.ScaleIONotBothParameters):
            getattr(volume, method)(**{"sdc_id": "test", "sdc_guid": "test"})
        m.assert_not_called()
Example #12
0
def test_volume_one_by_name(client):

    volume_id = "test_id"
    volume_name = "test_name"

    volume_payload = mock_resource_get(Volume._get_name(), volume_id, {
        "id": volume_id,
        "name": volume_name
    })

    call_args = (Volume._get_name(), "queryIdByKey", {"name": volume_name})
    with mock.patch("pyscaleio.models.Volume.__scheme__", {}):
        with mock.patch("pyscaleio.ScaleIOClient.perform_action_on_type",
                        side_effect=[volume_id]) as m:
            with httmock.HTTMock(login_payload, volume_payload):
                volume = Volume.one_by_name(volume_name)
            m.assert_called_once_with(*call_args)

            assert isinstance(volume, Volume)
            assert volume.name == volume_name
            assert volume["id"] == volume_id
Example #13
0
def test_volume_snapshot(client, kw, result):
    volume_data = {
        "id": "base_volume",
        "links": [],
        "volumeType": constants.VOLUME_TYPE_THIN,
        "useRmcache": False,
        "sizeInKb": 1048576,
        "storagePoolId": "pool_id"
    }
    volume = Volume(instance=volume_data)

    snapshot_data = volume_data.copy()
    snapshot_data.update({
        "id": "volume_snapshot",
        "volumeType": constants.VOLUME_TYPE_SNAPSHOT,
        "ancestorVolume": "base_volume",
    })
    snapshot_payload = mock_resource_get(Volume._get_name(), "volume_snapshot",
                                         snapshot_data)

    system_payload = mock_resources_get(System._get_name(),
                                        [{
                                            "id": "test",
                                            "restrictedSdcModeEnabled": True
                                        }])
    method_data = {
        "snapshotDefs": [dict({"volumeId": "base_volume"}, **result)]
    }
    with httmock.HTTMock(login_payload, system_payload, snapshot_payload):
        with mock.patch("pyscaleio.ScaleIOClient.perform_action_on",
                        side_effect=[{
                            "volumeIdList": ["volume_snapshot"]
                        }]) as m:
            snapshot = volume.snapshot(**kw)
            m.assert_called_once_with("System", "test", "snapshotVolumes",
                                      method_data)

        assert isinstance(snapshot, Volume)
        assert snapshot.type == constants.VOLUME_TYPE_SNAPSHOT
        assert snapshot.get("ancestorVolume") == "base_volume"
Example #14
0
def test_volume_model_exports(client):

    volume_exports = [{
        "sdcId": "sdc01",
        "sdcIp": "127.0.0.1",
        "limitIops": 0,
        "limitBwInMbps": 0
    }]
    volume_payload = mock_resource_get(
        Volume._get_name(), "test",
        mock_volume({
            "id": "test",
            "mappedSdcInfo": volume_exports
        }))
    sdc_payloads = [
        mock_resource_get(
            Sdc._get_name(), sdc_id, {
                "id": sdc_id,
                "sdcIp": sdc_id,
                "sdcGuid": str(uuid.uuid4()),
                "sdcApproved": True,
                "mdmConnectionState": constants.SDC_MDM_STATE_CONNECTED,
            }) for sdc_id in ("sdc0{0}".format(i) for i in range(1, 3))
    ]

    with httmock.HTTMock(login_payload, volume_payload):
        volume = Volume("test")

        assert volume.exports
        assert isinstance(volume.exports, (Sequence, ExportsInfo))

    with httmock.HTTMock(*sdc_payloads):
        sdc1 = Sdc("sdc01")
        sdc2 = Sdc("sdc02")

        assert sdc1 in volume.exports
        assert sdc2 not in volume.exports
        assert "some_string" not in volume.exports
Example #15
0
def test_volume_one_by_name(client):

    volume_id = "test_id"
    volume_name = "test_name"

    volume_payload = mock_resource_get(Volume._get_name(), volume_id, {
        "id": volume_id,
        "name": volume_name
    })

    call_args = (Volume._get_name(), "queryIdByKey", {"name": volume_name})
    with mock.patch("pyscaleio.models.Volume.__scheme__", {}):
        with mock.patch(
            "pyscaleio.ScaleIOClient.perform_action_on_type",
            side_effect=[volume_id]
        ) as m:
            with httmock.HTTMock(login_payload, volume_payload):
                volume = Volume.one_by_name(volume_name)
            m.assert_called_once_with(*call_args)

            assert isinstance(volume, Volume)
            assert volume.name == volume_name
            assert volume["id"] == volume_id
Example #16
0
def test_volume_snapshot(client, kw, result):
    volume_data = {
        "id": "base_volume",
        "links": [],
        "volumeType": constants.VOLUME_TYPE_THIN,
        "useRmcache": False,
        "sizeInKb": 1048576,
        "storagePoolId": "pool_id"
    }
    volume = Volume(instance=volume_data)

    snapshot_data = volume_data.copy()
    snapshot_data.update({
        "id": "volume_snapshot",
        "volumeType": constants.VOLUME_TYPE_SNAPSHOT,
        "ancestorVolume": "base_volume",
    })
    snapshot_payload = mock_resource_get(Volume._get_name(),
        "volume_snapshot", snapshot_data)

    system_payload = mock_resources_get(System._get_name(), [{
        "id": "test", "restrictedSdcModeEnabled": True
    }])
    method_data = {
        "snapshotDefs": [dict({"volumeId": "base_volume"}, **result)]
    }
    with httmock.HTTMock(login_payload, system_payload, snapshot_payload):
        with mock.patch(
            "pyscaleio.ScaleIOClient.perform_action_on",
            side_effect=[{"volumeIdList": ["volume_snapshot"]}]
        ) as m:
            snapshot = volume.snapshot(**kw)
            m.assert_called_once_with("System", "test", "snapshotVolumes", method_data)

        assert isinstance(snapshot, Volume)
        assert snapshot.type == constants.VOLUME_TYPE_SNAPSHOT
        assert snapshot.get("ancestorVolume") == "base_volume"
Example #17
0
def test_volume_model(client):

    volume_payload = mock_resource_get(Volume._get_name(), "test",
        mock_volume({"id": "test"})
    )
    system_payload = mock_resources_get(System._get_name(), [{
        "id": "system"
    }])
    with httmock.HTTMock(login_payload, volume_payload, system_payload):
        volume = Volume("test")

        assert volume.name is None
        assert volume.size == 8 * constants.GIGABYTE
        assert volume.type == constants.VOLUME_TYPE_THICK
        assert isinstance(volume.exports, Sequence)
        assert not volume.exports

        with mock.patch("pyscaleio.models.System.__scheme__", {}):
            assert volume.path == "/dev/disk/by-id/emc-vol-system-test"