예제 #1
0
static int
test_vdi_list_parser(const void *opaque)
{
    const struct testVDIListParserData *data = opaque;
    collie_test test = data->data;
    VIR_AUTOFREE(char *) output = NULL;
    VIR_AUTOPTR(virStoragePoolDef) pool = NULL;
    VIR_AUTOPTR(virStorageVolDef) vol = NULL;

    if (!(pool = virStoragePoolDefParseFile(data->poolxml)))
        return -1;

    if (!(vol = virStorageVolDefParseFile(pool, data->volxml, 0)))
        return -1;

    if (VIR_STRDUP(output, test.output) < 0)
        return -1;

    if (virStorageBackendSheepdogParseVdiList(vol, output) !=
        test.expected_return)
        return -1;

    if (test.expected_return)
        return 0;

    if (vol->target.capacity == test.expected_capacity &&
        vol->target.allocation == test.expected_allocation)
        return 0;

    return -1;
}
예제 #2
0
static int
test_node_info_parser(const void *opaque)
{
    const struct testNodeInfoParserData *data = opaque;
    collie_test test = data->data;
    VIR_AUTOFREE(char *) output = NULL;
    VIR_AUTOPTR(virStoragePoolDef) pool = NULL;

    if (!(pool = virStoragePoolDefParseFile(data->poolxml)))
        return -1;

    if (VIR_STRDUP(output, test.output) < 0)
        return -1;

    if (virStorageBackendSheepdogParseNodeInfo(pool, output) !=
        test.expected_return)
        return -1;

    if (test.expected_return)
        return 0;

    if (pool->capacity == test.expected_capacity &&
        pool->allocation == test.expected_allocation)
        return 0;

    return -1;
}
예제 #3
0
static int
testCompareXMLToXMLFiles(const char *poolxml, const char *inxml,
                         const char *outxml, unsigned int flags)
{
    char *actual = NULL;
    int ret = -1;
    virStoragePoolDefPtr pool = NULL;
    virStorageVolDefPtr dev = NULL;

    if (!(pool = virStoragePoolDefParseFile(poolxml)))
        goto fail;

    if (!(dev = virStorageVolDefParseFile(pool, inxml, flags)))
        goto fail;

    if (!(actual = virStorageVolDefFormat(pool, dev)))
        goto fail;

    if (virTestCompareToFile(actual, outxml) < 0)
        goto fail;

    ret = 0;

 fail:
    VIR_FREE(actual);
    virStoragePoolDefFree(pool);
    virStorageVolDefFree(dev);
    return ret;
}
static int
testCompareXMLToXMLFiles(const char *inxml, const char *outxml)
{
    char *actual = NULL;
    int ret = -1;
    virStoragePoolDefPtr dev = NULL;

    if (!(dev = virStoragePoolDefParseFile(inxml)))
        goto fail;

    if (!(actual = virStoragePoolDefFormat(dev)))
        goto fail;

    if (virtTestCompareToFile(actual, outxml) < 0)
        goto fail;

    ret = 0;

 fail:
    VIR_FREE(actual);
    virStoragePoolDefFree(dev);
    return ret;
}
예제 #5
0
static int
testCompareXMLToArgvFiles(bool shouldFail,
                          const char *poolxml,
                          const char *volxml,
                          const char *inputpoolxml,
                          const char *inputvolxml,
                          const char *cmdline,
                          unsigned int flags,
                          unsigned long parse_flags)
{
    char *actualCmdline = NULL;
    virStorageVolEncryptConvertStep convertStep = VIR_STORAGE_VOL_ENCRYPT_NONE;
    int ret = -1;

    virCommandPtr cmd = NULL;

    virStorageVolDefPtr vol = NULL, inputvol = NULL;
    virStoragePoolDefPtr def = NULL;
    virStoragePoolDefPtr inputpool = NULL;
    virStoragePoolObjPtr obj = NULL;

    if (!(def = virStoragePoolDefParseFile(poolxml)))
        goto cleanup;

    if (!(obj = virStoragePoolObjNew())) {
        virStoragePoolDefFree(def);
        goto cleanup;
    }
    virStoragePoolObjSetDef(obj, def);

    if (inputpoolxml) {
        if (!(inputpool = virStoragePoolDefParseFile(inputpoolxml)))
            goto cleanup;
    }

    if (inputvolxml)
        parse_flags |= VIR_VOL_XML_PARSE_NO_CAPACITY;

    if (!(vol = virStorageVolDefParseFile(def, volxml, parse_flags)))
        goto cleanup;

    if (inputvolxml &&
        !(inputvol = virStorageVolDefParseFile(inputpool, inputvolxml, 0)))
        goto cleanup;

    testSetVolumeType(vol, def);
    testSetVolumeType(inputvol, inputpool);

    /* Using an input file for encryption requires a multi-step process
     * to create an image of the same size as the inputvol and then to
     * convert the inputvol afterwards. Since we only care about the
     * command line we have to copy code from storageBackendCreateQemuImg
     * and adjust it for the test needs. */
    if (inputvol && (vol->target.encryption || inputvol->target.encryption))
        convertStep = VIR_STORAGE_VOL_ENCRYPT_CREATE;

    do {
        cmd = virStorageBackendCreateQemuImgCmdFromVol(obj, vol,
                                                       inputvol, flags,
                                                       create_tool,
                                                       "/path/to/secretFile",
                                                       "/path/to/inputSecretFile",
                                                       convertStep);
        if (!cmd) {
            if (shouldFail) {
                virResetLastError();
                ret = 0;
            }
            goto cleanup;
        }

        if (convertStep != VIR_STORAGE_VOL_ENCRYPT_CONVERT) {
            if (!(actualCmdline = virCommandToString(cmd)))
                goto cleanup;
        } else {
            char *createCmdline = actualCmdline;
            char *cvtCmdline;
            int rc;

            if (!(cvtCmdline = virCommandToString(cmd)))
                goto cleanup;

            rc = virAsprintf(&actualCmdline, "%s\n%s",
                             createCmdline, cvtCmdline);

            VIR_FREE(createCmdline);
            VIR_FREE(cvtCmdline);
            if (rc < 0)
                goto cleanup;
        }

        if (convertStep == VIR_STORAGE_VOL_ENCRYPT_NONE)
            convertStep = VIR_STORAGE_VOL_ENCRYPT_DONE;
        else if (convertStep == VIR_STORAGE_VOL_ENCRYPT_CREATE)
            convertStep = VIR_STORAGE_VOL_ENCRYPT_CONVERT;
        else if (convertStep == VIR_STORAGE_VOL_ENCRYPT_CONVERT)
            convertStep = VIR_STORAGE_VOL_ENCRYPT_DONE;

    } while (convertStep != VIR_STORAGE_VOL_ENCRYPT_DONE);

    if (virTestCompareToFile(actualCmdline, cmdline) < 0)
        goto cleanup;

    ret = 0;

 cleanup:
    virStoragePoolDefFree(inputpool);
    virStorageVolDefFree(vol);
    virStorageVolDefFree(inputvol);
    virCommandFree(cmd);
    VIR_FREE(actualCmdline);
    virStoragePoolObjEndAPI(&obj);
    return ret;
}
예제 #6
0
static int
testCompareXMLToArgvFiles(bool shouldFail,
                          const char *poolxml,
                          const char *volxml,
                          const char *inputpoolxml,
                          const char *inputvolxml,
                          const char *cmdline,
                          unsigned int flags,
                          int imgformat,
                          unsigned long parse_flags)
{
    char *actualCmdline = NULL;
    int ret = -1;

    virCommandPtr cmd = NULL;
    virConnectPtr conn;

    virStorageVolDefPtr vol = NULL, inputvol = NULL;
    virStoragePoolDefPtr pool = NULL;
    virStoragePoolDefPtr inputpool = NULL;
    virStoragePoolObj poolobj = {.def = NULL };


    if (!(conn = virGetConnect()))
        goto cleanup;

    if (!(pool = virStoragePoolDefParseFile(poolxml)))
        goto cleanup;

    poolobj.def = pool;

    if (inputpoolxml) {
        if (!(inputpool = virStoragePoolDefParseFile(inputpoolxml)))
            goto cleanup;
    }

    if (inputvolxml)
        parse_flags |= VIR_VOL_XML_PARSE_NO_CAPACITY;

    if (!(vol = virStorageVolDefParseFile(pool, volxml, parse_flags)))
        goto cleanup;

    if (inputvolxml &&
            !(inputvol = virStorageVolDefParseFile(inputpool, inputvolxml, 0)))
        goto cleanup;

    testSetVolumeType(vol, pool);
    testSetVolumeType(inputvol, inputpool);

    cmd = virStorageBackendCreateQemuImgCmdFromVol(conn, &poolobj, vol,
            inputvol, flags,
            create_tool, imgformat);
    if (!cmd) {
        if (shouldFail) {
            virResetLastError();
            ret = 0;
        }
        goto cleanup;
    }

    if (!(actualCmdline = virCommandToString(cmd)))
        goto cleanup;

    if (virTestCompareToFile(actualCmdline, cmdline) < 0)
        goto cleanup;

    ret = 0;

cleanup:
    virStoragePoolDefFree(pool);
    virStoragePoolDefFree(inputpool);
    virStorageVolDefFree(vol);
    virStorageVolDefFree(inputvol);
    virCommandFree(cmd);
    VIR_FREE(actualCmdline);
    virObjectUnref(conn);
    return ret;
}