Re: [PATCHv1.5 02/27] test: Implement fake storage pool driver in qemuxml2argv test

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 11/27/13 08:47, Osier Yang wrote:
> On 27/11/13 00:48, Peter Krempa wrote:
>> To support testing of "volume" disk backing, we need to implement a few
>> disk driver backend functions.
>>
>> The fake storage driver uses files in storagepoolxml2xmlout/POOLNAME.xml
>> as XML files for pool definitions and volume names are in format
>> "VOL_TYPE+VOL_PATH". By default type "block" is assumed (for iSCSI test
>> compatibility).
>>
>> The choice of this approach along with implemented functions was made so
>> that <disk type='volume'> can be tested in the xml2argv test.
>> ---
>>   tests/qemuxml2argvtest.c | 162
>> +++++++++++++++++++++++++++++++++++++++++++++++
>>   1 file changed, 162 insertions(+)
>>
>> diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
>> index a290062..a4cef84 100644
>> --- a/tests/qemuxml2argvtest.c
>> +++ b/tests/qemuxml2argvtest.c
>> @@ -18,6 +18,7 @@
>>   # include "qemu/qemu_command.h"
>>   # include "qemu/qemu_domain.h"
>>   # include "datatypes.h"
>> +# include "conf/storage_conf.h"
>>   # include "cpu/cpu_map.h"
>>   # include "virstring.h"
>>
>> @@ -75,6 +76,161 @@ static virSecretDriver fakeSecretDriver = {
>>       .secretUndefine = NULL,
>>   };
>>
>> +
>> +# define STORAGE_POOL_XML_PATH "storagepoolxml2xmlout/"
> 
> This will cause build failure when building with VPATH.

Hmmm, I'll look into it.

> 
>> +static const unsigned char fakeUUID[VIR_UUID_BUFLEN] = "fakeuuid";
>> +
>> +static virStoragePoolPtr
>> +fakeStoragePoolLookupByName(virConnectPtr conn,
>> +                            const char *name)
>> +{
>> +    char *xmlpath = NULL;
>> +    virStoragePoolPtr ret = NULL;
>> +
>> +    if (STRNEQ(name, "inactive")) {
>> +        if (virAsprintf(&xmlpath, "%s%s.xml",
>> +                        STORAGE_POOL_XML_PATH,
>> +                        name) < 0)
>> +            return NULL;
>> +
>> +        if (!virFileExists(xmlpath)) {
>> +            virReportError(VIR_ERR_NO_STORAGE_POOL,
>> +                           "File '%s' not found", xmlpath);
>> +            goto cleanup;
>> +        }virGetStoragePool
>> +    }
>> +
>> +    ret = virGetStoragePool(conn, name, fakeUUID, NULL, NULL);
> 
> Looks like "fakeUUID" is only used here, so generating a random UUID
> might work.

Random? Why bother? This static one is used so that virGetStoragePool()
doesn't crash and isn't used anywhere else.

> 
>> +
>> +cleanup:
>> +    VIR_FREE(xmlpath);
>> +    return ret;
>> +}
>> +
>> +
>> +static virStorageVolPtr
>> +fakeStorageVolLookupByName(virStoragePoolPtr pool,
>> +                           const char *name)
>> +{
>> +    char **volinfo = NULL;
>> +    virStorageVolPtr ret = NULL;
>> +
>> +    if (STREQ(pool->name, "inactive")) {
>> +        virReportError(VIR_ERR_OPERATION_INVALID,
>> +                       "storage pool '%s' is not active", pool->name);
>> +        return NULL;
>> +    }
>> +
>> +    if (STREQ(name, "nonexistent")) {
> 
> It will be better if it has document what these magic strings mean.

Yeah, I forgot this one ...

> 
>> +        virReportError(VIR_ERR_NO_STORAGE_VOL,
>> +                       "no storage vol with matching name '%s'", name);
>> +        return NULL;
>> +    }
>> +
>> +    if (!strchr(name, '+'))
>> +        goto fallback;
>> +
>> +    if (!(volinfo = virStringSplit(name, "+", 2)))
>> +        return NULL;
>> +
>> +    if (!volinfo[1])
>> +        goto fallback;
>> +
>> +    ret = virGetStorageVol(pool->conn, pool->name, volinfo[1],
>> volinfo[0],
>> +                           NULL, NULL);
>> +
>> +cleanup:
>> +    virStringFreeList(volinfo);
>> +    return ret;
>> +
>> +fallback:
>> +    ret = virGetStorageVol(pool->conn, pool->name, name, "block",
>> NULL, NULL);
>> +    goto cleanup;
>> +}
>> +
>> +static int
>> +fakeStorageVolGetInfo(virStorageVolPtr vol,
>> +                      virStorageVolInfoPtr info)
>> +{
>> +    memset(info, 0, sizeof(*info));
>> +
>> +    info->type = virStorageVolTypeFromString(vol->key);
>> +
>> +    if (info->type < 0) {
>> +        virReportError(VIR_ERR_INTERNAL_ERROR,
>> +                       "Invalid volume type '%s'", vol->key);
>> +        return -1;
>> +    }
>> +
>> +    return 0;
>> +}
>> +
>> +
>> +static char *
>> +fakeStorageVolGetPath(virStorageVolPtr vol)
>> +{
>> +    char *ret = NULL;
>> +
>> +    ignore_value(virAsprintf(&ret, "/some/%s/device/%s", vol->key,
>> vol->name));
>> +
>> +    return ret;
>> +}
>> +
>> +
>> +static char *
>> +fakeStoragePoolDumpXML(virStoragePoolPtr pool,
> 
> Better to rename it as fakeStoragePoolGetXMLDesc to keep consistent.
> "DumpXML" is used in virsh.

Right.

> 
> Osier

Peter

Attachment: signature.asc
Description: OpenPGP digital signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]