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; }
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 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; }
static virStorageVolDefPtr parallelsStorageVolDefineXML(virStoragePoolObjPtr pool, const char *xmldesc, const char *xmlfile, bool is_new) { virStorageVolDefPtr privvol = NULL; virStorageVolDefPtr ret = NULL; char *xml_path = NULL; if (xmlfile) privvol = virStorageVolDefParseFile(pool->def, xmlfile); else privvol = virStorageVolDefParseString(pool->def, xmldesc); if (privvol == NULL) goto cleanup; if (virStorageVolDefFindByName(pool, privvol->name)) { virReportError(VIR_ERR_OPERATION_FAILED, "%s", _("storage vol already exists")); goto cleanup; } if (is_new) { /* Make sure enough space */ if ((pool->def->allocation + privvol->target.allocation) > pool->def->capacity) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Not enough free space in pool for volume '%s'"), privvol->name); goto cleanup; } } if (virAsprintf(&privvol->target.path, "%s/%s", pool->def->target.path, privvol->name) < 0) goto cleanup; if (VIR_STRDUP(privvol->key, privvol->target.path) < 0) goto cleanup; if (is_new) { xml_path = parallelsAddFileExt(privvol->target.path, ".xml"); if (!xml_path) goto cleanup; if (virXMLSaveFile(xml_path, NULL, "volume-create", xmldesc)) { virReportError(VIR_ERR_OPERATION_FAILED, "%s", _("Can't create file with volume description")); goto cleanup; } pool->def->allocation += privvol->target.allocation; pool->def->available = (pool->def->capacity - pool->def->allocation); } if (VIR_APPEND_ELEMENT_COPY(pool->volumes.objs, pool->volumes.count, privvol) < 0) goto cleanup; ret = privvol; privvol = NULL; cleanup: virStorageVolDefFree(privvol); VIR_FREE(xml_path); return ret; }
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; }