Ejemplo n.º 1
0
def random_volume(pool_dir, random_qcow2):
    volume = fake_volume(image_file=random_qcow2)
    image = volume.image
    pool = fake_pool(pool_dir)

    driver = DirectoryPoolDriver()
    driver.image_activate(image, pool, LogProgress())
    driver.volume_activate(volume, pool, LogProgress())

    return volume, driver.get_volume(volume, pool), driver, pool
Ejemplo n.º 2
0
def test_volume_activate(pool_dir, random_qcow2):
    volume = fake_volume(image_file=random_qcow2)
    image = volume.image
    pool = fake_pool(pool_dir)

    driver = DirectoryPoolDriver()
    driver.image_activate(image, pool, LogProgress())
    driver.volume_activate(volume, pool, LogProgress())

    found = driver.get_volume(volume, pool)
    found_image = driver.get_image(image, pool)

    assert found is not None
    assert found.info['backing-filename'] == os.path.basename(found_image.file)
    assert found.info['virtual-size'] == found_image.info['virtual-size']
    assert os.path.dirname(found.file) == pool_dir
Ejemplo n.º 3
0
def test_volume_activate(random_qcow2, pool_dir, agent, responses):
    volume = fake_volume(image_file=random_qcow2)
    image = volume.image
    pool = fake_pool(pool_dir)

    driver = DirectoryPoolDriver()
    driver.image_activate(image, pool, LogProgress())

    def pre(req):
        req['data']['volumeStoragePoolMap']['volume'] = volume
        req['data']['volumeStoragePoolMap']['storagePool'] = pool

    def post(req, resp):
        assert resp['data']['+data']['libvirt']['filename'].endswith('.qcow2')
        assert resp['data']['+data']['libvirt']['backing-filename']\
            .endswith('.qcow2')
        assert resp['data']['+data']['libvirt']['full-backing-filename']\
            .endswith('.qcow2')

        assert int(resp['data']['+data']['libvirt']['actual-size']) > 200000
        del resp['data']['+data']['libvirt']['actual-size']

        del resp['data']['+data']['libvirt']['filename']
        del resp['data']['+data']['libvirt']['backing-filename']
        del resp['data']['+data']['libvirt']['full-backing-filename']

    event_test(agent, 'libvirt/volume_activate', pre_func=pre, post_func=post)
Ejemplo n.º 4
0
def test_download(pool_dir, random_qcow2):
    image = fake_image(file=random_qcow2)
    pool = fake_pool(pool_dir)

    driver = DirectoryPoolDriver()
    driver.image_activate(image, pool, LogProgress())

    dest_file = os.path.join(pool_dir, '{0}.qcow2'.format(image.uuid))
    assert os.path.exists(dest_file)

    return image.uuid
Ejemplo n.º 5
0
def test_volume_remove(random_volume, pool_dir, random_qcow2):
    volume, volume_obj, driver, pool = random_volume
    image_obj = driver.get_image(volume.image, pool)

    assert os.path.exists(volume_obj.file)
    assert os.path.exists(image_obj.file)
    assert not driver.is_volume_removed(volume, pool)

    driver.volume_remove(volume, pool, LogProgress())

    assert not os.path.exists(volume_obj.file)
    assert os.path.exists(image_obj.file)
    assert driver.is_volume_removed(volume, pool)
Ejemplo n.º 6
0
def test_get_image(pool_dir, random_qcow2):
    image = fake_image(file=random_qcow2)
    pool = fake_pool(pool_dir)

    driver = DirectoryPoolDriver()
    driver.image_activate(image, pool, LogProgress())

    found = driver.get_image(image, pool)

    assert found is not None
    assert found.file == os.path.join(pool_dir, '{0}.qcow2'.format(image.uuid))
    assert found.get_format() == 'qcow2'

    _check_file_mode(found.file, '400')
Ejemplo n.º 7
0
def test_instance_activate(random_qcow2, pool_dir, agent, responses):
    _delete_instance('c861f990-4472-4fa1-960f-65171b544c28')

    volume = fake_volume(image_file=random_qcow2)
    image = volume.image
    pool = fake_pool(pool_dir)
    volume['storagePools'] = [pool]

    driver = DirectoryPoolDriver()
    driver.image_activate(image, pool, LogProgress())
    driver.volume_activate(volume, pool, LogProgress())

    def pre(req):
        req.data.instanceHostMap.instance.image = image
        req.data.instanceHostMap.instance.volumes.append(volume)

    def post(_, resp):
        assert resp['data']['instance']['+data']['+libvirt']['xml'] is not None
        resp['data']['instance']['+data']['+libvirt']['xml'] = '<xml/>'

    event_test(agent, 'libvirt/instance_activate', pre_func=pre,
               post_func=post)

    _delete_instance('c861f990-4472-4fa1-960f-65171b544c28')