backup: Wire up qemu full pull backup commands over QMP
[libvirt/ericb.git] / tests / fchosttest.c
blob3ee19129260936485905df8a25e425d90771afba
1 /*
2 * Copyright (C) 2013 Red Hat, Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see
16 * <http://www.gnu.org/licenses/>.
20 #include <config.h>
22 #include "virlog.h"
23 #include "virstring.h"
24 #include "virvhba.h"
25 #include "testutils.h"
27 #define VIR_FROM_THIS VIR_FROM_NONE
29 VIR_LOG_INIT("tests.fchosttest");
31 static char *fchost_prefix;
33 #define TEST_FC_HOST_PREFIX fchost_prefix
34 #define TEST_FC_HOST_NUM 5
35 #define TEST_FC_HOST_NUM_NO_FAB 6
37 /* virNodeDeviceCreateXML using "<parent>" to find the vport capable HBA */
38 static const char test7_xml[] =
39 "<device>"
40 " <parent>scsi_host1</parent>"
41 " <capability type='scsi_host'>"
42 " <capability type='fc_host'>"
43 " </capability>"
44 " </capability>"
45 "</device>";
47 /* virNodeDeviceCreateXML without "<parent>" to find the vport capable HBA */
48 static const char test8_xml[] =
49 "<device>"
50 " <capability type='scsi_host'>"
51 " <capability type='fc_host'>"
52 " </capability>"
53 " </capability>"
54 "</device>";
56 /* virNodeDeviceCreateXML using "<parent wwnn='%s' wwpn='%s'/>" to find
57 * the vport capable HBA */
58 static const char test9_xml[] =
59 "<device>"
60 " <parent wwnn='2000000012341234' wwpn='1000000012341234'/>"
61 " <capability type='scsi_host'>"
62 " <capability type='fc_host'>"
63 " </capability>"
64 " </capability>"
65 "</device>";
67 /* virNodeDeviceCreateXML using "<parent fabric_wwn='%s'/>" to find the
68 * vport capable HBA */
69 static const char test10_xml[] =
70 "<device>"
71 " <parent fabric_wwn='2000000043214321'/>"
72 " <capability type='scsi_host'>"
73 " <capability type='fc_host'>"
74 " </capability>"
75 " </capability>"
76 "</device>";
78 /* virStoragePoolCreateXML using parent='%s' to find the vport capable HBA */
79 static const char test11_xml[] =
80 "<pool type='scsi'>"
81 " <name>vhba_pool</name>"
82 " <source>"
83 " <adapter type='fc_host' parent='scsi_host1' wwnn='20000000c9831b4b' wwpn='10000000c9831b4b'/>"
84 " </source>"
85 " <target>"
86 " <path>/dev/disk/by-path</path>"
87 " </target>"
88 "</pool>";
91 /* Test virIsVHBACapable */
92 static int
93 test1(const void *data ATTRIBUTE_UNUSED)
95 if (virVHBAPathExists(TEST_FC_HOST_PREFIX, TEST_FC_HOST_NUM) &&
96 virVHBAPathExists(TEST_FC_HOST_PREFIX, TEST_FC_HOST_NUM_NO_FAB))
97 return 0;
99 return -1;
102 /* Test virVHBAIsVportCapable */
103 static int
104 test2(const void *data ATTRIBUTE_UNUSED)
106 if (virVHBAIsVportCapable(TEST_FC_HOST_PREFIX, TEST_FC_HOST_NUM))
107 return 0;
109 return -1;
112 /* Test virVHBAGetConfig */
113 static int
114 test3(const void *data ATTRIBUTE_UNUSED)
116 const char *expect_wwnn = "2001001b32a9da4e";
117 const char *expect_wwpn = "2101001b32a9da4e";
118 const char *expect_fabric_wwn = "2001000dec9877c1";
119 const char *expect_max_vports = "127";
120 const char *expect_vports = "0";
121 char *wwnn = NULL;
122 char *wwpn = NULL;
123 char *fabric_wwn = NULL;
124 char *max_vports = NULL;
125 char *vports = NULL;
126 int ret = -1;
128 if (!(wwnn = virVHBAGetConfig(TEST_FC_HOST_PREFIX, TEST_FC_HOST_NUM,
129 "node_name")))
130 return -1;
132 if (!(wwpn = virVHBAGetConfig(TEST_FC_HOST_PREFIX, TEST_FC_HOST_NUM,
133 "port_name")))
134 goto cleanup;
136 if (!(fabric_wwn = virVHBAGetConfig(TEST_FC_HOST_PREFIX, TEST_FC_HOST_NUM,
137 "fabric_name")))
138 goto cleanup;
140 if (!(max_vports = virVHBAGetConfig(TEST_FC_HOST_PREFIX, TEST_FC_HOST_NUM,
141 "max_npiv_vports")))
142 goto cleanup;
145 if (!(vports = virVHBAGetConfig(TEST_FC_HOST_PREFIX, TEST_FC_HOST_NUM,
146 "npiv_vports_inuse")))
147 goto cleanup;
149 if (STRNEQ(expect_wwnn, wwnn) ||
150 STRNEQ(expect_wwpn, wwpn) ||
151 STRNEQ(expect_fabric_wwn, fabric_wwn) ||
152 STRNEQ(expect_max_vports, max_vports) ||
153 STRNEQ(expect_vports, vports))
154 goto cleanup;
156 ret = 0;
157 cleanup:
158 VIR_FREE(wwnn);
159 VIR_FREE(wwpn);
160 VIR_FREE(fabric_wwn);
161 VIR_FREE(max_vports);
162 VIR_FREE(vports);
163 return ret;
166 /* Test virVHBAGetHostByWWN */
167 static int
168 test4(const void *data ATTRIBUTE_UNUSED)
170 const char *expect_hostname = "host5";
171 char *hostname = NULL;
172 int ret = -1;
174 if (!(hostname = virVHBAGetHostByWWN(TEST_FC_HOST_PREFIX,
175 "2001001b32a9da4e",
176 "2101001b32a9da4e")))
177 return -1;
179 if (STRNEQ(hostname, expect_hostname))
180 goto cleanup;
182 ret = 0;
183 cleanup:
184 VIR_FREE(hostname);
185 return ret;
188 /* Test virVHBAFindVportHost
190 * NB: host4 is not Online, so it should not be found
192 static int
193 test5(const void *data ATTRIBUTE_UNUSED)
195 const char *expect_hostname = "host5";
196 char *hostname = NULL;
197 int ret = -1;
199 if (!(hostname = virVHBAFindVportHost(TEST_FC_HOST_PREFIX)))
200 return -1;
202 if (STRNEQ(hostname, expect_hostname))
203 goto cleanup;
205 ret = 0;
206 cleanup:
207 VIR_FREE(hostname);
208 return ret;
211 /* Test virVHBAGetConfig fabric name optional */
212 static int
213 test6(const void *data ATTRIBUTE_UNUSED)
215 const char *expect_wwnn = "2002001b32a9da4e";
216 const char *expect_wwpn = "2102001b32a9da4e";
217 char *wwnn = NULL;
218 char *wwpn = NULL;
219 char *fabric_wwn = NULL;
220 int ret = -1;
222 if (!(wwnn = virVHBAGetConfig(TEST_FC_HOST_PREFIX, TEST_FC_HOST_NUM_NO_FAB,
223 "node_name")))
224 return -1;
226 if (!(wwpn = virVHBAGetConfig(TEST_FC_HOST_PREFIX, TEST_FC_HOST_NUM_NO_FAB,
227 "port_name")))
228 goto cleanup;
230 if ((fabric_wwn = virVHBAGetConfig(TEST_FC_HOST_PREFIX,
231 TEST_FC_HOST_NUM_NO_FAB,
232 "fabric_name")))
233 goto cleanup;
235 if (STRNEQ(expect_wwnn, wwnn) ||
236 STRNEQ(expect_wwpn, wwpn))
237 goto cleanup;
239 ret = 0;
240 cleanup:
241 VIR_FREE(wwnn);
242 VIR_FREE(wwpn);
243 VIR_FREE(fabric_wwn);
244 return ret;
249 /* Test manageVHBAByNodeDevice
250 * - Test both virNodeDeviceCreateXML and virNodeDeviceDestroy
251 * - Create a node device vHBA allowing usage of various different
252 * methods based on the input data/xml argument.
253 * - Be sure that it's possible to destroy the node device as well.
255 static int
256 manageVHBAByNodeDevice(const void *data)
258 const char *expect_hostname = "scsi_host12";
259 virConnectPtr conn = NULL;
260 virNodeDevicePtr dev = NULL;
261 int ret = -1;
262 const char *vhba = data;
264 if (!(conn = virConnectOpen("test:///default")))
265 return -1;
267 if (!(dev = virNodeDeviceCreateXML(conn, vhba, 0)))
268 goto cleanup;
270 if (virNodeDeviceDestroy(dev) < 0)
271 goto cleanup;
273 if (STRNEQ(virNodeDeviceGetName(dev), expect_hostname)) {
274 virReportError(VIR_ERR_INTERNAL_ERROR,
275 "Expected hostname: '%s' got: '%s'",
276 expect_hostname, virNodeDeviceGetName(dev));
277 goto cleanup;
280 ret = 0;
282 cleanup:
283 if (dev)
284 virNodeDeviceFree(dev);
285 if (conn)
286 virConnectClose(conn);
287 return ret;
291 /* Test manageVHBAByStoragePool
292 * - Test both virStoragePoolCreateXML and virStoragePoolDestroy
293 * - Create a storage pool vHBA allowing usage of various different
294 * methods based on the input data/xml argument.
295 * - Be sure that it's possible to destroy the storage pool as well.
297 static int
298 manageVHBAByStoragePool(const void *data)
300 const char *expect_hostname = "scsi_host12";
301 virConnectPtr conn = NULL;
302 virStoragePoolPtr pool = NULL;
303 virNodeDevicePtr dev = NULL;
304 int ret = -1;
305 const char *vhba = data;
307 if (!(conn = virConnectOpen("test:///default")))
308 return -1;
310 if (!(pool = virStoragePoolCreateXML(conn, vhba, 0)))
311 goto cleanup;
313 if (!(dev = virNodeDeviceLookupByName(conn, expect_hostname))) {
314 VIR_DEBUG("Failed to find expected_hostname '%s'", expect_hostname);
315 ignore_value(virStoragePoolDestroy(pool));
316 goto cleanup;
318 virNodeDeviceFree(dev);
320 if (virStoragePoolDestroy(pool) < 0)
321 goto cleanup;
323 if ((dev = virNodeDeviceLookupByName(conn, expect_hostname))) {
324 VIR_DEBUG("Found expected_hostname '%s' after destroy",
325 expect_hostname);
326 virNodeDeviceFree(dev);
327 goto cleanup;
330 ret = 0;
332 cleanup:
333 if (pool)
334 virStoragePoolFree(pool);
335 if (conn)
336 virConnectClose(conn);
337 return ret;
341 static int
342 mymain(void)
344 int ret = 0;
346 if (virAsprintf(&fchost_prefix, "%s/%s", abs_srcdir,
347 "fchostdata/fc_host/") < 0) {
348 ret = -1;
349 goto cleanup;
352 if (virTestRun("virVHBAPathExists", test1, NULL) < 0)
353 ret = -1;
354 if (virTestRun("virVHBAIsVportCapable", test2, NULL) < 0)
355 ret = -1;
356 if (virTestRun("virVHBAGetConfig", test3, NULL) < 0)
357 ret = -1;
358 if (virTestRun("virVHBAGetHostByWWN", test4, NULL) < 0)
359 ret = -1;
360 if (virTestRun("virVHBAFindVportHost", test5, NULL) < 0)
361 ret = -1;
362 if (virTestRun("virVHBAGetConfig-empty-fabric_wwn", test6, NULL) < 0)
363 ret = -1;
364 if (virTestRun("manageVHBAByNodeDevice-by-parent", manageVHBAByNodeDevice,
365 test7_xml) < 0)
366 ret = -1;
367 if (virTestRun("manageVHBAByNodeDevice-no-parent", manageVHBAByNodeDevice,
368 test8_xml) < 0)
369 ret = -1;
370 if (virTestRun("manageVHBAByNodeDevice-parent-wwn", manageVHBAByNodeDevice,
371 test9_xml) < 0)
372 ret = -1;
373 if (virTestRun("manageVHBAByNodeDevice-parent-fabric-wwn",
374 manageVHBAByNodeDevice, test10_xml) < 0)
375 ret = -1;
376 if (virTestRun("manageVHBAByStoragePool-by-parent", manageVHBAByStoragePool,
377 test11_xml) < 0)
378 ret = -1;
380 cleanup:
381 VIR_FREE(fchost_prefix);
382 return ret;
385 VIR_TEST_MAIN_PRELOAD(mymain, abs_builddir "/.libs/virrandommock.so")