From nobody Sun Feb 8 14:12:28 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.24 as permitted sender) client-ip=209.132.183.24; envelope-from=libvir-list-bounces@redhat.com; helo=mx3-phx2.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.24 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx3-phx2.redhat.com (mx3-phx2.redhat.com [209.132.183.24]) by mx.zohomail.com with SMTPS id 1488642944803341.95587360129673; Sat, 4 Mar 2017 07:55:44 -0800 (PST) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx3-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v24FqHfX027256; Sat, 4 Mar 2017 10:52:17 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v24FqGmC016180 for ; Sat, 4 Mar 2017 10:52:16 -0500 Received: from localhost.localdomain.com (ovpn-116-78.phx2.redhat.com [10.3.116.78]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v24FqFi7009975 for ; Sat, 4 Mar 2017 10:52:15 -0500 From: John Ferlan To: libvir-list@redhat.com Date: Sat, 4 Mar 2017 10:52:07 -0500 Message-Id: <20170304155212.23385-2-jferlan@redhat.com> In-Reply-To: <20170304155212.23385-1-jferlan@redhat.com> References: <20170304155212.23385-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-loop: libvir-list@redhat.com Subject: [libvirt] [REPOST PATCHv2 1/6] tests: Add createVHBAByStoragePool-by-parent to fchosttest X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Add a new test to fchosttest in order to test creation of our vHBA via the Storage Pool logic. Unlike the real code, we cannot yet use the virVHBA* API's because they (currently) traverse the file system in order to get the parent vport capable scsi_host. Besides there's no "real" NPIV device here - so we have to take some liberties, at least for now. Instead, we'll follow the node device tests partially in order to create and destroy the vHBA with the test node devices. Signed-off-by: John Ferlan --- src/test/test_driver.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++= ++-- tests/fchosttest.c | 64 ++++++++++++++++++++++++++++++++++ 2 files changed, 156 insertions(+), 2 deletions(-) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 61c82b9..a9bb5a6 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -4366,6 +4366,34 @@ testConnectFindStoragePoolSources(virConnectPtr conn= ATTRIBUTE_UNUSED, } =20 =20 +static virNodeDeviceObjPtr +testNodeDeviceMockCreateVport(testDriverPtr driver, + const char *wwnn, + const char *wwpn); +static int +testCreateVport(testDriverPtr driver, + const char *wwnn, + const char *wwpn) +{ + virNodeDeviceObjPtr obj =3D NULL; + /* The storage_backend_scsi createVport() will use the input adapter + * fields parent name, parent_wwnn/parent_wwpn, or parent_fabric_wwn + * in order to determine whether the provided parent can be used to + * create a vHBA or will find "an available vport capable" to create + * a vHBA. In order to do this, it uses the virVHBA* API's which trave= rse + * the sysfs looking at various fields (rather than going via nodedev). + * + * Since the test environ doesn't have the sysfs for the storage pool + * test, at least for now use the node device test infrastructure to + * create the vHBA. In the long run the result is the same. */ + if (!(obj =3D testNodeDeviceMockCreateVport(driver, wwnn, wwpn))) + return -1; + virNodeDeviceObjUnlock(obj); + + return 0; +} + + static virStoragePoolPtr testStoragePoolCreateXML(virConnectPtr conn, const char *xml, @@ -4396,6 +4424,21 @@ testStoragePoolCreateXML(virConnectPtr conn, goto cleanup; def =3D NULL; =20 + if (pool->def->source.adapter.type =3D=3D + VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_FC_HOST) { + /* In the real code, we'd call virVHBAManageVport followed by + * find_new_device, but we cannot do that here since we're not + * mocking udev. The mock routine will copy an existing vHBA and + * rename a few fields to mock that. */ + if (testCreateVport(privconn, + pool->def->source.adapter.data.fchost.wwnn, + pool->def->source.adapter.data.fchost.wwpn) < = 0) { + virStoragePoolObjRemove(&privconn->pools, pool); + pool =3D NULL; + goto cleanup; + } + } + if (testStoragePoolObjSetDefaults(pool) =3D=3D -1) { virStoragePoolObjRemove(&privconn->pools, pool); pool =3D NULL; @@ -4406,7 +4449,6 @@ testStoragePoolCreateXML(virConnectPtr conn, event =3D virStoragePoolEventLifecycleNew(pool->def->name, pool->def->= uuid, VIR_STORAGE_POOL_EVENT_STARTED, 0); - ret =3D virGetStoragePool(conn, pool->def->name, pool->def->uuid, NULL, NULL); =20 @@ -4540,6 +4582,44 @@ testStoragePoolBuild(virStoragePoolPtr pool, =20 =20 static int +testDestroyVport(testDriverPtr privconn, + const char *wwnn ATTRIBUTE_UNUSED, + const char *wwpn ATTRIBUTE_UNUSED) +{ + int ret =3D -1; + virNodeDeviceObjPtr obj =3D NULL; + virObjectEventPtr event =3D NULL; + + /* NB: Cannot use virVHBAGetHostByWWN (yet) like the storage_backend_s= csi + * deleteVport() helper since that traverses the file system looking f= or + * the wwnn/wwpn. So our choice short term is to cheat and use the name + * (scsi_host12) we know was created. + * + * Reaching across the boundaries of space and time into the + * Node Device in order to remove */ + if (!(obj =3D virNodeDeviceObjFindByName(&privconn->devs, "scsi_host12= "))) { + virReportError(VIR_ERR_NO_NODE_DEVICE, "%s", + _("no node device with matching name 'scsi_host12'"= )); + goto cleanup; + } + + event =3D virNodeDeviceEventLifecycleNew("scsi_host12", + VIR_NODE_DEVICE_EVENT_DELETED, + 0); + + virNodeDeviceObjRemove(&privconn->devs, &obj); + + ret =3D 0; + + cleanup: + if (obj) + virNodeDeviceObjUnlock(obj); + testObjectEventQueue(privconn, event); + return ret; +} + + +static int testStoragePoolDestroy(virStoragePoolPtr pool) { testDriverPtr privconn =3D pool->conn->privateData; @@ -4563,7 +4643,17 @@ testStoragePoolDestroy(virStoragePoolPtr pool) } =20 privpool->active =3D 0; - event =3D virStoragePoolEventLifecycleNew(privpool->def->name, privpoo= l->def->uuid, + + if (privpool->def->source.adapter.type =3D=3D + VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_FC_HOST) { + if (testDestroyVport(privconn, + privpool->def->source.adapter.data.fchost.wwn= n, + privpool->def->source.adapter.data.fchost.wwp= n) < 0) + goto cleanup; + } + + event =3D virStoragePoolEventLifecycleNew(privpool->def->name, + privpool->def->uuid, VIR_STORAGE_POOL_EVENT_STOPPED, 0); =20 diff --git a/tests/fchosttest.c b/tests/fchosttest.c index 51fdcbd..dc6b9af 100644 --- a/tests/fchosttest.c +++ b/tests/fchosttest.c @@ -75,6 +75,19 @@ static const char test10_xml[] =3D " " ""; =20 +/* virStoragePoolCreateXML using parent=3D'%s' to find the vport capable H= BA */ +static const char test11_xml[] =3D +"" +" vhba_pool" +" " +" " +" " +" " +" /dev/disk/by-path" +" " +""; + + /* Test virIsVHBACapable */ static int test1(const void *data ATTRIBUTE_UNUSED) @@ -275,6 +288,54 @@ manageVHBAByNodeDevice(const void *data) } =20 =20 +/* Test manageVHBAByStoragePool + * - Test both virStoragePoolCreateXML and virStoragePoolDestroy + * - Create a storage pool vHBA allowing usage of various different + * methods based on the input data/xml argument. + * - Be sure that it's possible to destroy the storage pool as well. + */ +static int +manageVHBAByStoragePool(const void *data) +{ + const char *expect_hostname =3D "scsi_host12"; + virConnectPtr conn =3D NULL; + virStoragePoolPtr pool =3D NULL; + virNodeDevicePtr dev =3D NULL; + int ret =3D -1; + const char *vhba =3D data; + + if (!(conn =3D virConnectOpen("test:///default"))) + return -1; + + if (!(pool =3D virStoragePoolCreateXML(conn, vhba, 0))) + goto cleanup; + + if (!(dev =3D virNodeDeviceLookupByName(conn, expect_hostname))) { + VIR_DEBUG("Failed to find expected_hostname '%s'", expect_hostname= ); + ignore_value(virStoragePoolDestroy(pool)); + goto cleanup; + } + + if (virStoragePoolDestroy(pool) < 0) + goto cleanup; + + if ((dev =3D virNodeDeviceLookupByName(conn, expect_hostname))) { + VIR_DEBUG("Found expected_hostname '%s' after destroy", + expect_hostname); + goto cleanup; + } + + ret =3D 0; + + cleanup: + if (pool) + virStoragePoolFree(pool); + if (conn) + virConnectClose(conn); + return ret; +} + + static int mymain(void) { @@ -310,6 +371,9 @@ mymain(void) if (virTestRun("manageVHBAByNodeDevice-parent-fabric-wwn", manageVHBAByNodeDevice, test10_xml) < 0) ret =3D -1; + if (virTestRun("manageVHBAByStoragePool-by-parent", manageVHBAByStorag= ePool, + test11_xml) < 0) + ret =3D -1; =20 cleanup: VIR_FREE(fchost_prefix); --=20 2.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list