From nobody Mon Mar 30 03:46:30 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.25 as permitted sender) client-ip=209.132.183.25; envelope-from=libvir-list-bounces@redhat.com; helo=mx4-phx2.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.25 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx4-phx2.redhat.com (mx4-phx2.redhat.com [209.132.183.25]) by mx.zohomail.com with SMTPS id 1488639862603929.1891413580888; Sat, 4 Mar 2017 07:04:22 -0800 (PST) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx4-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v24F0VLe026493; Sat, 4 Mar 2017 10:00:32 -0500 Received: from smtp.corp.redhat.com (int-mx16.intmail.prod.int.phx2.redhat.com [10.5.11.28]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v24F0SEH009870 for ; Sat, 4 Mar 2017 10:00:28 -0500 Received: by smtp.corp.redhat.com (Postfix) id CBF332D654; Sat, 4 Mar 2017 15:00:28 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-78.phx2.redhat.com [10.3.116.78]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8881F2D653 for ; Sat, 4 Mar 2017 15:00:28 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Sat, 4 Mar 2017 10:00:24 -0500 Message-Id: <20170304150024.30063-4-jferlan@redhat.com> In-Reply-To: <20170304150024.30063-1-jferlan@redhat.com> References: <20170304150024.30063-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.74 on 10.5.11.28 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 3/3] test: Make common test*ObjFindByUUID helpers 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" Make common helpers testNetworkObjFindByUUID and testStoragePoolObjFindByUU= ID which will replace the repeated patter for each to find objects by UUID. As a bonus, the error message processing will also provide the failed uuids= tr rather than a generic error message. Signed-off-by: John Ferlan --- src/test/test_driver.c | 96 +++++++++++++++++++++++++++-------------------= ---- 1 file changed, 52 insertions(+), 44 deletions(-) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index e4402cc..1c54069 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -3216,6 +3216,24 @@ static int testDomainInterfaceStats(virDomainPtr dom= ain, } =20 =20 +static virNetworkObjPtr +testNetworkObjFindByUUID(testDriverPtr privconn, + const unsigned char *uuid) +{ + virNetworkObjPtr net; + char uuidstr[VIR_UUID_STRING_BUFLEN]; + + if (!(net =3D virNetworkObjFindByUUID(privconn->networks, uuid))) { + virUUIDFormat(uuid, uuidstr); + virReportError(VIR_ERR_NO_NETWORK, + _("no network with matching uuid '%s'"), + uuidstr); + } + + return net; +} + + static virNetworkPtr testNetworkLookupByUUID(virConnectPtr conn, const unsigned char *uuid) { @@ -3223,11 +3241,8 @@ static virNetworkPtr testNetworkLookupByUUID(virConn= ectPtr conn, virNetworkObjPtr net; virNetworkPtr ret =3D NULL; =20 - net =3D virNetworkObjFindByUUID(privconn->networks, uuid); - if (net =3D=3D NULL) { - virReportError(VIR_ERR_NO_NETWORK, NULL); + if (!(net =3D testNetworkObjFindByUUID(privconn, uuid))) goto cleanup; - } =20 ret =3D virGetNetwork(conn, net->def->name, net->def->uuid); =20 @@ -3326,11 +3341,9 @@ static int testNetworkIsActive(virNetworkPtr net) virNetworkObjPtr obj; int ret =3D -1; =20 - obj =3D virNetworkObjFindByUUID(privconn->networks, net->uuid); - if (!obj) { - virReportError(VIR_ERR_NO_NETWORK, NULL); + if (!(obj =3D testNetworkObjFindByUUID(privconn, net->uuid))) goto cleanup; - } + ret =3D virNetworkObjIsActive(obj); =20 cleanup: @@ -3344,11 +3357,9 @@ static int testNetworkIsPersistent(virNetworkPtr net) virNetworkObjPtr obj; int ret =3D -1; =20 - obj =3D virNetworkObjFindByUUID(privconn->networks, net->uuid); - if (!obj) { - virReportError(VIR_ERR_NO_NETWORK, NULL); + if (!(obj =3D testNetworkObjFindByUUID(privconn, net->uuid))) goto cleanup; - } + ret =3D obj->persistent; =20 cleanup: @@ -3462,12 +3473,8 @@ testNetworkUpdate(virNetworkPtr net, VIR_NETWORK_UPDATE_AFFECT_CONFIG, -1); =20 - network =3D virNetworkObjFindByUUID(privconn->networks, net->uuid); - if (!network) { - virReportError(VIR_ERR_NO_NETWORK, - "%s", _("no network with matching uuid")); + if (!(network =3D testNetworkObjFindByUUID(privconn, net->uuid))) goto cleanup; - } =20 /* VIR_NETWORK_UPDATE_AFFECT_CURRENT means "change LIVE if network * is active, else change CONFIG @@ -4049,6 +4056,28 @@ testStoragePoolObjFindByName(testDriverPtr privconn, } =20 =20 +static virStoragePoolObjPtr +testStoragePoolObjFindByUUID(testDriverPtr privconn, + const unsigned char *uuid) +{ + virStoragePoolObjPtr pool; + char uuidstr[VIR_UUID_STRING_BUFLEN]; + + testDriverLock(privconn); + pool =3D virStoragePoolObjFindByUUID(&privconn->pools, uuid); + testDriverUnlock(privconn); + + if (!pool) { + virUUIDFormat(uuid, uuidstr); + virReportError(VIR_ERR_NO_STORAGE_POOL, + _("no storage pool with matching uuid '%s'"), + uuidstr); + } + + return pool; +} + + static virStoragePoolPtr testStoragePoolLookupByUUID(virConnectPtr conn, const unsigned char *uuid) @@ -4057,14 +4086,8 @@ testStoragePoolLookupByUUID(virConnectPtr conn, virStoragePoolObjPtr pool; virStoragePoolPtr ret =3D NULL; =20 - testDriverLock(privconn); - pool =3D virStoragePoolObjFindByUUID(&privconn->pools, uuid); - testDriverUnlock(privconn); - - if (pool =3D=3D NULL) { - virReportError(VIR_ERR_NO_STORAGE_POOL, NULL); + if (!(pool =3D testStoragePoolObjFindByUUID(privconn, uuid))) goto cleanup; - } =20 ret =3D virGetStoragePool(conn, pool->def->name, pool->def->uuid, NULL, NULL); @@ -4222,13 +4245,9 @@ static int testStoragePoolIsActive(virStoragePoolPtr= pool) virStoragePoolObjPtr obj; int ret =3D -1; =20 - testDriverLock(privconn); - obj =3D virStoragePoolObjFindByUUID(&privconn->pools, pool->uuid); - testDriverUnlock(privconn); - if (!obj) { - virReportError(VIR_ERR_NO_STORAGE_POOL, NULL); + if (!(obj =3D testStoragePoolObjFindByUUID(privconn, pool->uuid))) goto cleanup; - } + ret =3D virStoragePoolObjIsActive(obj); =20 cleanup: @@ -4243,13 +4262,9 @@ static int testStoragePoolIsPersistent(virStoragePoo= lPtr pool) virStoragePoolObjPtr obj; int ret =3D -1; =20 - testDriverLock(privconn); - obj =3D virStoragePoolObjFindByUUID(&privconn->pools, pool->uuid); - testDriverUnlock(privconn); - if (!obj) { - virReportError(VIR_ERR_NO_STORAGE_POOL, NULL); + if (!(obj =3D testStoragePoolObjFindByUUID(privconn, pool->uuid))) goto cleanup; - } + ret =3D obj->configFile ? 1 : 0; =20 cleanup: @@ -4781,15 +4796,8 @@ testStoragePoolListAllVolumes(virStoragePoolPtr obj, =20 virCheckFlags(0, -1); =20 - testDriverLock(privconn); - pool =3D virStoragePoolObjFindByUUID(&privconn->pools, obj->uuid); - testDriverUnlock(privconn); - - if (!pool) { - virReportError(VIR_ERR_NO_STORAGE_POOL, "%s", - _("no storage pool with matching uuid")); + if (!(pool =3D testStoragePoolObjFindByUUID(privconn, obj->uuid))) goto cleanup; - } =20 if (!virStoragePoolObjIsActive(pool)) { virReportError(VIR_ERR_OPERATION_INVALID, "%s", --=20 2.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list