6 #include "storage/storage_util.h"
7 #include "testutilsqemu.h"
10 #define VIR_FROM_THIS VIR_FROM_NONE
12 const char create_tool
[] = "qemu-img";
14 /* createVol sets this on volume creation */
16 testSetVolumeType(virStorageVolDefPtr vol
,
17 virStoragePoolDefPtr pool
)
23 case VIR_STORAGE_POOL_DIR
:
24 case VIR_STORAGE_POOL_FS
:
25 case VIR_STORAGE_POOL_NETFS
:
26 vol
->type
= VIR_STORAGE_VOL_FILE
;
29 case VIR_STORAGE_POOL_LOGICAL
:
30 vol
->type
= VIR_STORAGE_VOL_BLOCK
;
36 testCompareXMLToArgvFiles(bool shouldFail
,
39 const char *inputpoolxml
,
40 const char *inputvolxml
,
43 unsigned long parse_flags
)
45 virStorageVolEncryptConvertStep convertStep
= VIR_STORAGE_VOL_ENCRYPT_NONE
;
47 virStoragePoolDefPtr def
= NULL
;
48 virStoragePoolObjPtr obj
= NULL
;
49 VIR_AUTOFREE(char *) actualCmdline
= NULL
;
50 VIR_AUTOPTR(virStorageVolDef
) vol
= NULL
;
51 VIR_AUTOPTR(virStorageVolDef
) inputvol
= NULL
;
52 VIR_AUTOPTR(virStoragePoolDef
) inputpool
= NULL
;
53 VIR_AUTOPTR(virCommand
) cmd
= NULL
;
55 if (!(def
= virStoragePoolDefParseFile(poolxml
)))
58 if (!(obj
= virStoragePoolObjNew())) {
59 virStoragePoolDefFree(def
);
62 virStoragePoolObjSetDef(obj
, def
);
65 if (!(inputpool
= virStoragePoolDefParseFile(inputpoolxml
)))
70 parse_flags
|= VIR_VOL_XML_PARSE_NO_CAPACITY
;
72 if (!(vol
= virStorageVolDefParseFile(def
, volxml
, parse_flags
)))
76 !(inputvol
= virStorageVolDefParseFile(inputpool
, inputvolxml
, 0)))
79 testSetVolumeType(vol
, def
);
80 testSetVolumeType(inputvol
, inputpool
);
82 /* Using an input file for encryption requires a multi-step process
83 * to create an image of the same size as the inputvol and then to
84 * convert the inputvol afterwards. Since we only care about the
85 * command line we have to copy code from storageBackendCreateQemuImg
86 * and adjust it for the test needs. */
87 if (inputvol
&& (vol
->target
.encryption
|| inputvol
->target
.encryption
))
88 convertStep
= VIR_STORAGE_VOL_ENCRYPT_CREATE
;
92 cmd
= virStorageBackendCreateQemuImgCmdFromVol(obj
, vol
,
95 "/path/to/secretFile",
96 "/path/to/inputSecretFile",
106 if (convertStep
!= VIR_STORAGE_VOL_ENCRYPT_CONVERT
) {
107 if (!(actualCmdline
= virCommandToString(cmd
, false)))
110 char *createCmdline
= actualCmdline
;
111 VIR_AUTOFREE(char *) cvtCmdline
= NULL
;
114 if (!(cvtCmdline
= virCommandToString(cmd
, false)))
117 rc
= virAsprintf(&actualCmdline
, "%s\n%s",
118 createCmdline
, cvtCmdline
);
120 VIR_FREE(createCmdline
);
125 if (convertStep
== VIR_STORAGE_VOL_ENCRYPT_NONE
)
126 convertStep
= VIR_STORAGE_VOL_ENCRYPT_DONE
;
127 else if (convertStep
== VIR_STORAGE_VOL_ENCRYPT_CREATE
)
128 convertStep
= VIR_STORAGE_VOL_ENCRYPT_CONVERT
;
129 else if (convertStep
== VIR_STORAGE_VOL_ENCRYPT_CONVERT
)
130 convertStep
= VIR_STORAGE_VOL_ENCRYPT_DONE
;
132 } while (convertStep
!= VIR_STORAGE_VOL_ENCRYPT_DONE
);
134 if (virTestCompareToFile(actualCmdline
, cmdline
) < 0)
140 virStoragePoolObjEndAPI(&obj
);
148 const char *inputpool
;
149 const char *inputvol
;
152 unsigned long parseflags
;
156 testCompareXMLToArgvHelper(const void *data
)
158 const struct testInfo
*info
= data
;
159 VIR_AUTOFREE(char *) poolxml
= NULL
;
160 VIR_AUTOFREE(char *) inputpoolxml
= NULL
;
161 VIR_AUTOFREE(char *) volxml
= NULL
;
162 VIR_AUTOFREE(char *) inputvolxml
= NULL
;
163 VIR_AUTOFREE(char *) cmdline
= NULL
;
165 if (info
->inputvol
&&
166 virAsprintf(&inputvolxml
, "%s/storagevolxml2xmlin/%s.xml",
167 abs_srcdir
, info
->inputvol
) < 0)
169 if (info
->inputpool
&&
170 virAsprintf(&inputpoolxml
, "%s/storagepoolxml2xmlin/%s.xml",
171 abs_srcdir
, info
->inputpool
) < 0)
173 if (virAsprintf(&poolxml
, "%s/storagepoolxml2xmlin/%s.xml",
174 abs_srcdir
, info
->pool
) < 0 ||
175 virAsprintf(&volxml
, "%s/storagevolxml2xmlin/%s.xml",
176 abs_srcdir
, info
->vol
) < 0) {
179 if (virAsprintf(&cmdline
, "%s/storagevolxml2argvdata/%s.argv",
180 abs_srcdir
, info
->cmdline
) < 0 && !info
->shouldFail
)
183 return testCompareXMLToArgvFiles(info
->shouldFail
, poolxml
, volxml
,
184 inputpoolxml
, inputvolxml
,
185 cmdline
, info
->flags
,
194 unsigned int flags
= VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA
;
196 #define DO_TEST_FULL(shouldFail, parseflags, pool, vol, inputpool, inputvol, \
199 struct testInfo info = { shouldFail, pool, vol, inputpool, inputvol, \
200 cmdline, flags, parseflags }; \
201 if (virTestRun("Storage Vol XML-2-argv " cmdline, \
202 testCompareXMLToArgvHelper, &info) < 0) \
207 #define DO_TEST(pool, ...) \
208 DO_TEST_FULL(false, 0, pool, __VA_ARGS__)
210 #define DO_TEST_FAIL(pool, ...) \
211 DO_TEST_FULL(true, 0, pool, __VA_ARGS__)
213 DO_TEST("pool-dir", "vol-qcow2",
216 DO_TEST("pool-dir", "vol-qcow2-nobacking",
218 "qcow2-nobacking-prealloc-compat", flags
);
219 DO_TEST("pool-dir", "vol-qcow2-nobacking",
220 "pool-dir", "vol-file",
221 "qcow2-nobacking-convert-prealloc-compat", flags
);
222 DO_TEST("pool-dir", "vol-qcow2-lazy",
225 DO_TEST("pool-dir", "vol-qcow2-1.1",
228 DO_TEST_FAIL("pool-dir", "vol-qcow2-0.10-lazy",
230 "qcow2-0.10-lazy", 0);
231 DO_TEST("pool-dir", "vol-qcow2-nobacking",
232 "pool-logical", "vol-logical",
233 "qcow2-from-logical-compat", 0);
234 DO_TEST("pool-logical", "vol-logical",
235 "pool-dir", "vol-qcow2-nobacking",
236 "logical-from-qcow2", 0);
237 DO_TEST("pool-dir", "vol-qcow2-nocow",
239 "qcow2-nocow-compat", 0);
240 DO_TEST("pool-dir", "vol-qcow2-nocapacity",
241 "pool-dir", "vol-file",
242 "qcow2-nocapacity-convert-prealloc", flags
);
243 DO_TEST("pool-dir", "vol-qcow2-zerocapacity",
245 "qcow2-zerocapacity", 0);
246 DO_TEST_FULL(false, VIR_VOL_XML_PARSE_OPT_CAPACITY
,
247 "pool-dir", "vol-qcow2-nocapacity-backing", NULL
, NULL
,
248 "qcow2-nocapacity", 0);
250 DO_TEST("pool-dir", "vol-file-iso",
253 DO_TEST("pool-dir", "vol-file",
254 "pool-dir", "vol-file-iso",
257 DO_TEST_FAIL("pool-dir", "vol-qcow2-encryption",
259 "qcow2-encryption", 0);
261 DO_TEST("pool-dir", "vol-luks",
264 DO_TEST("pool-dir", "vol-luks-cipher",
268 DO_TEST("pool-dir", "vol-luks-convert",
269 "pool-dir", "vol-file",
272 DO_TEST("pool-dir", "vol-luks-convert",
273 "pool-dir", "vol-file-qcow2",
274 "luks-convert-qcow2", 0);
276 DO_TEST("pool-dir", "vol-encrypt2",
277 "pool-dir", "vol-encrypt1",
278 "luks-convert-encrypt", 0);
280 DO_TEST("pool-dir", "vol-file",
281 "pool-dir", "vol-encrypt2",
282 "luks-convert-encrypt2fileraw", 0);
284 DO_TEST("pool-dir", "vol-file-qcow2",
285 "pool-dir", "vol-encrypt2",
286 "luks-convert-encrypt2fileqcow2", 0);
288 return ret
== 0 ? EXIT_SUCCESS
: EXIT_FAILURE
;
291 VIR_TEST_MAIN(mymain
)