Beispiel #1
0
def test_incorrect_auth_schema():
    f = tempfile.NamedTemporaryFile(mode="w")
    data = yaml.safe_load(open("clouds.yaml"))
    del data["clouds"]["devstack"]["auth"]["password"]
    yaml.dump(data, f)
    with pytest.raises(osl.exceptions.CannotConnectToCloud,
                       match="Authentication failed"):
        osl.get_client("devstack", 0, 0, config={"config_files": [f.name]})
Beispiel #2
0
def test_request_not_match_schema():
    compute = osl.get_client("devstack", "compute", osl.schema("compute.yaml"))
    with pytest.raises(osl.exceptions.ValidationError,
                       match="required parameter"):
        compute.flavors.create_flavor()
    with pytest.raises(osl.exceptions.ValidationError,
                       match="required property"):
        compute.flavors.create_flavor(flavor={"flavor": {"name": "test"}})
Beispiel #3
0
def test_response_not_match_schema():
    compute = osl.get_client("devstack", "compute", osl.schema("compute.yaml"))
    with mock.patch(
            "bravado.http_future.HttpFuture._get_incoming_response") as r:
        resp = mock.MagicMock()
        resp.status_code = 200
        resp.json.return_value = {}
        r.return_value = resp
        with pytest.raises(osl.exceptions.ValidationError,
                           match="required property"):
            compute.flavors.get_flavor(flavor_id="fake")
Beispiel #4
0
def test_not_defined_response():
    compute = osl.get_client("devstack", "compute", osl.schema("compute.yaml"))
    with mock.patch(
            "bravado.requests_client.RequestsResponseAdapter") as resp_class:
        resp = mock.MagicMock()
        resp.status_code = 404
        resp.json.return_value = {}
        resp_class.return_value = resp
        try:
            compute.flavors.get_flavor(flavor_id="fake")
            pytest.fail("Exception must be thrown")
        except osl.exceptions.UnexpectedResponse as e:
            assert resp.status_code == e.status_code
Beispiel #5
0
import pytest
import uuid
import os_sdk_light as osl
from bravado_core import exception

CLOUD = "devstack"
c = osl.get_client(cloud=CLOUD,
                   service="image",
                   schema=osl.schema("image.yaml"))


def test_image():
    image = c.images.create_image(image={'name': 'myubuntu'})
    image = c.images.get_image(image_id=image['id'])
    # update = [{"op": "replace", "path": "/name", "value": image["id"]}]
    # image = c.images.update_image(image_id=image['id'], image=update)
    c.images.delete_image(image_id=image['id'])
Beispiel #6
0
import pytest
import uuid
import os_sdk_light as osl
from bravado_core import exception

TEST_RP = "test resource provider %s" % uuid.uuid4()
CLOUD = "devstack"
c = osl.get_client(CLOUD, "placement", osl.schema("placement.yaml"))


@pytest.fixture
def rp():
    orig_rp = {"name": TEST_RP}
    c.resource_providers.create_resource_provider(body=orig_rp)
    rp = c.resource_providers.list_resource_providers(
        name=orig_rp["name"])["resource_providers"][0]
    yield rp
    c.resource_providers.delete_resource_provider(uuid=rp["uuid"])


def test_rps(rp):
    rp1 = c.resource_providers.get_resource_provider(uuid=rp["uuid"])
    assert rp["name"] == rp1["name"]


def test_inventories(rp):
    c.resource_providers.put_inventories(
        uuid=rp["uuid"],
        body={
            "resource_provider_generation": rp["generation"],
            "inventories": {
Beispiel #7
0
import time
import pytest
import uuid
import os_sdk_light as osl
from bravado_core import exception

TEST_FLAVOR = "test flavor %s" % uuid.uuid4()
TEST_SERVER = "test server %s" % uuid.uuid4()
CLOUD = "devstack"
compute_client = osl.get_client(CLOUD, "compute", osl.schema("compute.yaml"))
image_client = osl.get_client(CLOUD, "image", osl.schema("image.yaml"))
network_client = osl.get_client(CLOUD, "network", osl.schema("network.yaml"))


@pytest.fixture
def server():
    flavors = compute_client.flavors.list_flavors()["flavors"]
    flavors.sort(key=lambda x: x["ram"])
    flavor = flavors[0]
    images = image_client.images.list()["images"]
    image = [i for i in images if "cirros" in i["name"]][0]
    networks = network_client.networks.list()["networks"]
    network = [i for i in networks if "private" in i["name"]][0]
    server = compute_client.servers.create_server(
        server={
            "server": {
                "name": TEST_SERVER,
                "imageRef": image["id"],
                "flavorRef": flavor["id"],
                "networks": [{
                    "uuid": network["id"]
Beispiel #8
0
import pytest
import uuid
import os_sdk_light as osl
from bravado_core import exception

CLOUD = "devstack"
c = osl.get_client(cloud=CLOUD,
                   service="network",
                   schema=osl.schema("network.yaml"))


def test_port():
    networks = c.networks.list()["networks"]
    network = [i for i in networks if "private" in i["name"]][0]
    port_id = str(uuid.uuid4())
    port = c.ports.create_port(port={"port": {
        "network_id": network["id"]
    }})["port"]
    port = c.ports.get_port(port_id=port["id"])["port"]
    c.ports.list_ports(id=port["id"])
    port = c.ports.update_port(port_id=port["id"],
                               port={"port": {
                                   "name": port_id
                               }})["port"]
    c.ports.delete_port(port_id=port["id"])


def test_floatingip(server):
    networks = c.networks.list()["networks"]
    network = [i for i in networks if "public" in i["name"]][0]
    port = c.ports.list_ports(device_id=server["id"])['ports'][0]
Beispiel #9
0
def test_incorrect_schema():
    f = tempfile.NamedTemporaryFile()
    with pytest.raises(osl.exceptions.SchemaError,
                       match="cannot be read or invalid"):
        osl.get_client("devstack", "compute", f.name)
Beispiel #10
0
def test_get_endpoint_failed():
    with pytest.raises(osl.exceptions.CannotConnectToCloud,
                       match="Failed to find service endpoint"):
        osl.get_client("devstack", 0, 0)
Beispiel #11
0
def test_no_cloud_config(change_dir):
    with pytest.raises(osl.exceptions.CannotConnectToCloud,
                       match="Not enough params"):
        osl.get_client(0, 0, 0)
Beispiel #12
0
def test_microversion_in_header():
    p = osl.get_client("devstack", "placement", osl.schema("placement.yaml"))
    p.traits.get_traits()
Beispiel #13
0
#!/usr/bin/env python
from __future__ import print_function
import sys
import yaml

import os_sdk_light as osl


placement_client = osl.get_client(
    'devstack', 'placement', osl.schema('placement.yaml'))


def main(limit):
    output = {}
    rps = placement_client.resource_providers.list_resource_providers()[
        'resource_providers']
    for rp in rps[0:limit]:
        output[rp['uuid']] = {}
        usages = placement_client.resource_providers.get_usages(
            uuid=rp['uuid'])['usages']
        traits = placement_client.resource_providers.get_rp_traits(
            uuid=rp['uuid'])['traits']
        aggregates = placement_client.resource_providers.get_aggregates(
            uuid=rp['uuid'])['aggregates']
        for name, props in placement_client.resource_providers.get_inventories(
                uuid=rp['uuid'])['inventories'].items():
            output[rp['uuid']][name] = {'total': props['total'],
                                        'used': usages.get(name, 0)}
        output[rp['uuid']]['traits'] = traits
        output[rp['uuid']]['aggregates'] = aggregates