From 4b6ee784def360bb6e65b90514218394fbf5946e Mon Sep 17 00:00:00 2001 From: John Ferlan Date: Tue, 24 Jan 2017 10:49:23 -0500 Subject: [PATCH] tests: Add new fchosttest tests for management of a vHBA Add a test that will mimic creation and destruction of a vHBA by using node device XML. The design will allow for testing the multiple mechanisms. The first test uses just in the node device XML. This is somewhat similar to the existing objecteventtest, except that this test will not provide input wwnn/wwpn's (similar to how the process is described for the the libvirt wiki). This requires mocking the virRandomGenerateWWN since parsing the input XML (virNodeDevCapSCSIHostParseXML) requires either a provided wwnn/wwpn in the XML or the ability to randomly generate the wwnn/wwpn. --- tests/fchosttest.c | 62 ++++++++++++++++++++++++++++++++++++++++++- tests/virrandommock.c | 9 +++++++ 2 files changed, 70 insertions(+), 1 deletion(-) 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