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/>.
23 #include "virstring.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
[] =
40 " <parent>scsi_host1</parent>"
41 " <capability type='scsi_host'>"
42 " <capability type='fc_host'>"
47 /* virNodeDeviceCreateXML without "<parent>" to find the vport capable HBA */
48 static const char test8_xml
[] =
50 " <capability type='scsi_host'>"
51 " <capability type='fc_host'>"
56 /* virNodeDeviceCreateXML using "<parent wwnn='%s' wwpn='%s'/>" to find
57 * the vport capable HBA */
58 static const char test9_xml
[] =
60 " <parent wwnn='2000000012341234' wwpn='1000000012341234'/>"
61 " <capability type='scsi_host'>"
62 " <capability type='fc_host'>"
67 /* virNodeDeviceCreateXML using "<parent fabric_wwn='%s'/>" to find the
68 * vport capable HBA */
69 static const char test10_xml
[] =
71 " <parent fabric_wwn='2000000043214321'/>"
72 " <capability type='scsi_host'>"
73 " <capability type='fc_host'>"
78 /* virStoragePoolCreateXML using parent='%s' to find the vport capable HBA */
79 static const char test11_xml
[] =
81 " <name>vhba_pool</name>"
83 " <adapter type='fc_host' parent='scsi_host1' wwnn='20000000c9831b4b' wwpn='10000000c9831b4b'/>"
86 " <path>/dev/disk/by-path</path>"
91 /* Test virIsVHBACapable */
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
))
102 /* Test virVHBAIsVportCapable */
104 test2(const void *data ATTRIBUTE_UNUSED
)
106 if (virVHBAIsVportCapable(TEST_FC_HOST_PREFIX
, TEST_FC_HOST_NUM
))
112 /* Test virVHBAGetConfig */
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";
123 char *fabric_wwn
= NULL
;
124 char *max_vports
= NULL
;
128 if (!(wwnn
= virVHBAGetConfig(TEST_FC_HOST_PREFIX
, TEST_FC_HOST_NUM
,
132 if (!(wwpn
= virVHBAGetConfig(TEST_FC_HOST_PREFIX
, TEST_FC_HOST_NUM
,
136 if (!(fabric_wwn
= virVHBAGetConfig(TEST_FC_HOST_PREFIX
, TEST_FC_HOST_NUM
,
140 if (!(max_vports
= virVHBAGetConfig(TEST_FC_HOST_PREFIX
, TEST_FC_HOST_NUM
,
145 if (!(vports
= virVHBAGetConfig(TEST_FC_HOST_PREFIX
, TEST_FC_HOST_NUM
,
146 "npiv_vports_inuse")))
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
))
160 VIR_FREE(fabric_wwn
);
161 VIR_FREE(max_vports
);
166 /* Test virVHBAGetHostByWWN */
168 test4(const void *data ATTRIBUTE_UNUSED
)
170 const char *expect_hostname
= "host5";
171 char *hostname
= NULL
;
174 if (!(hostname
= virVHBAGetHostByWWN(TEST_FC_HOST_PREFIX
,
176 "2101001b32a9da4e")))
179 if (STRNEQ(hostname
, expect_hostname
))
188 /* Test virVHBAFindVportHost
190 * NB: host4 is not Online, so it should not be found
193 test5(const void *data ATTRIBUTE_UNUSED
)
195 const char *expect_hostname
= "host5";
196 char *hostname
= NULL
;
199 if (!(hostname
= virVHBAFindVportHost(TEST_FC_HOST_PREFIX
)))
202 if (STRNEQ(hostname
, expect_hostname
))
211 /* Test virVHBAGetConfig fabric name optional */
213 test6(const void *data ATTRIBUTE_UNUSED
)
215 const char *expect_wwnn
= "2002001b32a9da4e";
216 const char *expect_wwpn
= "2102001b32a9da4e";
219 char *fabric_wwn
= NULL
;
222 if (!(wwnn
= virVHBAGetConfig(TEST_FC_HOST_PREFIX
, TEST_FC_HOST_NUM_NO_FAB
,
226 if (!(wwpn
= virVHBAGetConfig(TEST_FC_HOST_PREFIX
, TEST_FC_HOST_NUM_NO_FAB
,
230 if ((fabric_wwn
= virVHBAGetConfig(TEST_FC_HOST_PREFIX
,
231 TEST_FC_HOST_NUM_NO_FAB
,
235 if (STRNEQ(expect_wwnn
, wwnn
) ||
236 STRNEQ(expect_wwpn
, wwpn
))
243 VIR_FREE(fabric_wwn
);
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.
256 manageVHBAByNodeDevice(const void *data
)
258 const char *expect_hostname
= "scsi_host12";
259 virConnectPtr conn
= NULL
;
260 virNodeDevicePtr dev
= NULL
;
262 const char *vhba
= data
;
264 if (!(conn
= virConnectOpen("test:///default")))
267 if (!(dev
= virNodeDeviceCreateXML(conn
, vhba
, 0)))
270 if (virNodeDeviceDestroy(dev
) < 0)
273 if (STRNEQ(virNodeDeviceGetName(dev
), expect_hostname
)) {
274 virReportError(VIR_ERR_INTERNAL_ERROR
,
275 "Expected hostname: '%s' got: '%s'",
276 expect_hostname
, virNodeDeviceGetName(dev
));
284 virNodeDeviceFree(dev
);
286 virConnectClose(conn
);
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.
298 manageVHBAByStoragePool(const void *data
)
300 const char *expect_hostname
= "scsi_host12";
301 virConnectPtr conn
= NULL
;
302 virStoragePoolPtr pool
= NULL
;
303 virNodeDevicePtr dev
= NULL
;
305 const char *vhba
= data
;
307 if (!(conn
= virConnectOpen("test:///default")))
310 if (!(pool
= virStoragePoolCreateXML(conn
, vhba
, 0)))
313 if (!(dev
= virNodeDeviceLookupByName(conn
, expect_hostname
))) {
314 VIR_DEBUG("Failed to find expected_hostname '%s'", expect_hostname
);
315 ignore_value(virStoragePoolDestroy(pool
));
318 virNodeDeviceFree(dev
);
320 if (virStoragePoolDestroy(pool
) < 0)
323 if ((dev
= virNodeDeviceLookupByName(conn
, expect_hostname
))) {
324 VIR_DEBUG("Found expected_hostname '%s' after destroy",
326 virNodeDeviceFree(dev
);
334 virStoragePoolFree(pool
);
336 virConnectClose(conn
);
346 if (virAsprintf(&fchost_prefix
, "%s/%s", abs_srcdir
,
347 "fchostdata/fc_host/") < 0) {
352 if (virTestRun("virVHBAPathExists", test1
, NULL
) < 0)
354 if (virTestRun("virVHBAIsVportCapable", test2
, NULL
) < 0)
356 if (virTestRun("virVHBAGetConfig", test3
, NULL
) < 0)
358 if (virTestRun("virVHBAGetHostByWWN", test4
, NULL
) < 0)
360 if (virTestRun("virVHBAFindVportHost", test5
, NULL
) < 0)
362 if (virTestRun("virVHBAGetConfig-empty-fabric_wwn", test6
, NULL
) < 0)
364 if (virTestRun("manageVHBAByNodeDevice-by-parent", manageVHBAByNodeDevice
,
367 if (virTestRun("manageVHBAByNodeDevice-no-parent", manageVHBAByNodeDevice
,
370 if (virTestRun("manageVHBAByNodeDevice-parent-wwn", manageVHBAByNodeDevice
,
373 if (virTestRun("manageVHBAByNodeDevice-parent-fabric-wwn",
374 manageVHBAByNodeDevice
, test10_xml
) < 0)
376 if (virTestRun("manageVHBAByStoragePool-by-parent", manageVHBAByStoragePool
,
381 VIR_FREE(fchost_prefix
);
385 VIR_TEST_MAIN_PRELOAD(mymain
, abs_builddir
"/.libs/virrandommock.so")