diff --git a/tests/fchosttest.c b/tests/fchosttest.c index 39a06f3595..715571e32b 100644 --- a/tests/fchosttest.c +++ b/tests/fchosttest.c @@ -19,18 +19,31 @@ #include +#include "virlog.h" #include "virstring.h" #include "virvhba.h" #include "testutils.h" #define VIR_FROM_THIS VIR_FROM_NONE +VIR_LOG_INIT("tests.fchosttest"); + static char *fchost_prefix; #define TEST_FC_HOST_PREFIX fchost_prefix #define TEST_FC_HOST_NUM 5 #define TEST_FC_HOST_NUM_NO_FAB 6 +/* virNodeDeviceCreateXML using "" to find the vport capable HBA */ +static const char test7_xml[] = +"" +" scsi_host1" +" " +" " +" " +" " +""; + /* Test virIsVHBACapable */ static int test1(const void *data ATTRIBUTE_UNUSED) @@ -187,6 +200,50 @@ test6(const void *data ATTRIBUTE_UNUSED) return ret; } + + +/* Test manageVHBAByNodeDevice + * - Test both virNodeDeviceCreateXML and virNodeDeviceDestroy + * - Create a node device vHBA allowing usage of various different + * methods based on the input data/xml argument. + * - Be sure that it's possible to destroy the node device as well. + */ +static int +manageVHBAByNodeDevice(const void *data) +{ + const char *expect_hostname = "scsi_host12"; + virConnectPtr conn = NULL; + virNodeDevicePtr dev = NULL; + int ret = -1; + const char *vhba = data; + + if (!(conn = virConnectOpen("test:///default"))) + return -1; + + if (!(dev = virNodeDeviceCreateXML(conn, vhba, 0))) + goto cleanup; + + if (virNodeDeviceDestroy(dev) < 0) + goto cleanup; + + if (STRNEQ(virNodeDeviceGetName(dev), expect_hostname)) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "Expected hostname: '%s' got: '%s'", + expect_hostname, virNodeDeviceGetName(dev)); + goto cleanup; + } + + ret = 0; + + cleanup: + if (dev) + virNodeDeviceFree(dev); + if (conn) + virConnectClose(conn); + return ret; +} + + static int mymain(void) { @@ -210,10 +267,13 @@ mymain(void) ret = -1; if (virTestRun("virVHBAGetConfig-empty-fabric_wwn", test6, NULL) < 0) ret = -1; + if (virTestRun("manageVHBAByNodeDevice-by-parent", manageVHBAByNodeDevice, + test7_xml) < 0) + ret = -1; cleanup: VIR_FREE(fchost_prefix); return ret; } -VIRT_TEST_MAIN(mymain) +VIRT_TEST_MAIN_PRELOAD(mymain, abs_builddir "/.libs/virrandommock.so") diff --git a/tests/virrandommock.c b/tests/virrandommock.c index a69712a2cb..fd1a61f673 100644 --- a/tests/virrandommock.c +++ b/tests/virrandommock.c @@ -23,6 +23,7 @@ #ifndef WIN32 # include "internal.h" +# include "virstring.h" # include "virrandom.h" # include "virmock.h" @@ -41,6 +42,14 @@ virRandomBytes(unsigned char *buf, } +int virRandomGenerateWWN(char **wwn, + const char *virt_type ATTRIBUTE_UNUSED) +{ + return virAsprintf(wwn, "5100000%09llx", + (unsigned long long)virRandomBits(36)); +} + + # ifdef WITH_GNUTLS # include # include