Esempio n. 1
0
def test_virtual_machine_with_device_enable_storage_pool(
        super_client, client, context):
    sp = add_storage_pool(context, [context.host.uuid],
                          block_device_path="/dev/test")
    sp_name = sp.name
    vm = _create_virtual_machine(client,
                                 context,
                                 name=random_str(),
                                 volumeDriver=sp_name,
                                 userdata='hi',
                                 vcpu=2,
                                 memoryMb=42,
                                 disks=test_disks)
    vm = client.wait_success(vm)
    assert vm.state == 'running'

    c = super_client.reload(vm)
    prefix = c.name + '-' + c.uuid[0:7]
    assert c.devices == [
        '/dev/kvm:/dev/kvm', '/dev/net/tun:/dev/net/tun',
        '/dev/test/{}-00:/dev/vm/disk00'.format(prefix),
        '/dev/test/{}-foo:/dev/vm/root'.format(prefix),
        '/dev/test/{}-01:/dev/vm/disk01'.format(prefix)
    ]

    volume1 = find_one(client.list_volume, name=prefix + '-foo')
    assert volume1.driver == sp_name
    assert volume1.driverOpts == {
        'vm': 'true',
        'base-image': context.image_uuid,
        'dont-format': 'true'
    }
Esempio n. 2
0
def test_allocation_with_shared_storage_pool(super_client, new_context):
    count = 3

    client = new_context.client
    host2 = register_simulated_host(client)
    register_simulated_host(client)

    hosts = [new_context.host, host2]
    hosts = wait_all_success(super_client, hosts)
    sp = add_storage_pool(new_context, [new_context.host.uuid, host2.uuid])
    sp_name = sp.name
    for h in hosts:
        assert h.state == 'active'
        assert h.agent().state == 'active'
        assert len(h.storagePools()) == 2
        assert h.storagePools()[0].state == 'active'
        assert h.storagePools()[1].state == 'active'

    # Create a volume with a driver that points to a storage pool
    v1 = client.create_volume(name=random_str(), driver=sp_name)
    v1 = client.wait_success(v1)
    assert v1.state == 'requested'

    data_volume_mounts = {'/con/path': v1.id}

    containers = []
    for _ in range(len(hosts) * count):
        c = client.create_container(imageUuid=new_context.image_uuid,
                                    dataVolumeMounts=data_volume_mounts)
        containers.append(c)
        time.sleep(1)  # Sleep makes the test faster as it reduces contention

    wait_all_success(super_client, containers, timeout=60)
    for c in containers:
        new_context.wait_for_state(c, 'running')
Esempio n. 3
0
def test_virtual_machine_with_device_enable_storage_pool(super_client, client,
                                                         context):
    sp = add_storage_pool(context, [context.host.uuid],
                          block_device_path="/dev/test")
    sp_name = sp.name
    vm = _create_virtual_machine(client, context, name=random_str(),
                                 volumeDriver=sp_name,
                                 userdata='hi', vcpu=2, memoryMb=42,
                                 disks=test_disks)
    vm = client.wait_success(vm)
    assert vm.state == 'running'

    c = super_client.reload(vm)
    prefix = c.name + '-' + c.uuid[0:7]
    assert c.devices == ['/dev/kvm:/dev/kvm',
                         '/dev/net/tun:/dev/net/tun',
                         '/dev/test/{}-00:/dev/vm/disk00'.format(prefix),
                         '/dev/test/{}-foo:/dev/vm/root'.format(prefix),
                         '/dev/test/{}-01:/dev/vm/disk01'.format(prefix)]

    volume1 = find_one(client.list_volume, name=prefix + '-foo')
    assert volume1.driver == sp_name
    assert volume1.driverOpts == {'vm': 'true',
                                  'base-image': context.image_uuid,
                                  'dont-format': 'true'}
Esempio n. 4
0
def test_allocate_to_host_with_pool(new_context, super_client):
    # If a volumeDriver is specified that maps to an existing pool, restrict
    # allocation to hosts in that pool
    client = new_context.client
    host = new_context.host
    host2 = register_simulated_host(client)

    sp = add_storage_pool(new_context)
    sp_name = sp.name
    assert len(host.storagePools()) == 2
    assert len(host2.storagePools()) == 1

    # Fail to schedule because requested host is not in pool
    c = new_context.create_container_no_success(
        imageUuid=new_context.image_uuid,
        volumeDriver=sp_name,
        requestedHostId=host2.id,
        dataVolume=['vol1:/con/path'])
    c = super_client.reload(c)
    assert c.state == 'removed'
    assert c.transitioning == 'error'
    assert c.transitioningMessage == 'Failed to find a placement'
Esempio n. 5
0
def test_virtual_machine_with_device_enable_storage_pool(super_client, client, context):
    sp = add_storage_pool(context, [context.host.uuid], block_device_path="/dev/test")
    sp_name = sp.name
    vm = _create_virtual_machine(
        client, context, name=random_str(), volumeDriver=sp_name, userdata="hi", vcpu=2, memoryMb=42, disks=test_disks
    )
    vm = client.wait_success(vm)
    assert vm.state == "running"

    c = super_client.reload(vm)
    prefix = c.name + "-" + c.uuid[0:7]
    assert c.devices == [
        "/dev/kvm:/dev/kvm",
        "/dev/net/tun:/dev/net/tun",
        "/dev/test/{}-00:/dev/vm/disk00".format(prefix),
        "/dev/test/{}-foo:/dev/vm/root".format(prefix),
        "/dev/test/{}-01:/dev/vm/disk01".format(prefix),
    ]

    volume1 = find_one(client.list_volume, name=prefix + "-foo")
    assert volume1.driver == sp_name
    assert volume1.driverOpts == {"vm": "true", "base-image": context.image_uuid, "dont-format": "true"}
Esempio n. 6
0
def test_allocate_to_host_with_pool(new_context, super_client):
    # If a volumeDriver is specified that maps to an existing pool, restrict
    # allocation to hosts in that pool
    client = new_context.client
    host = new_context.host
    host2 = register_simulated_host(client)

    sp = add_storage_pool(new_context)
    sp_name = sp.name
    assert len(host.storagePools()) == 2
    assert len(host2.storagePools()) == 1

    # Fail to schedule because requested host is not in pool
    c = new_context.create_container_no_success(
        imageUuid=new_context.image_uuid,
        volumeDriver=sp_name,
        requestedHostId=host2.id,
        dataVolume=['vol1:/con/path'])
    c = super_client.reload(c)
    assert c.state == 'removed'
    assert c.transitioning == 'error'
    assert c.transitioningMessage == 'Failed to find a placement'