From patchwork Fri Jul 1 11:38:01 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cole Robinson X-Patchwork-Id: 71301 Delivered-To: patch@linaro.org Received: by 10.140.28.4 with SMTP id 4csp255616qgy; Fri, 1 Jul 2016 04:41:58 -0700 (PDT) X-Received: by 10.55.161.73 with SMTP id k70mr25426637qke.189.1467373318946; Fri, 01 Jul 2016 04:41:58 -0700 (PDT) Return-Path: Received: from mx4-phx2.redhat.com (mx4-phx2.redhat.com. [209.132.183.25]) by mx.google.com with ESMTPS id x143si2150386qkx.22.2016.07.01.04.41.58 (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 01 Jul 2016 04:41:58 -0700 (PDT) Received-SPF: pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.25 as permitted sender) client-ip=209.132.183.25; Authentication-Results: mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.25 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com 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 u61BcNMR029372; Fri, 1 Jul 2016 07:38:23 -0400 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 u61BcLQH032590 for ; Fri, 1 Jul 2016 07:38:21 -0400 Received: from colepc.redhat.com (ovpn-116-79.rdu2.redhat.com [10.10.116.79]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u61BcIbW004609; Fri, 1 Jul 2016 07:38:20 -0400 From: Cole Robinson To: libvir-list@redhat.com Date: Fri, 1 Jul 2016 07:38:01 -0400 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 3/4] test: Have test:///default open use file parsing 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 Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com Convert the individual XML documents into one big XML document in the format expected by the non-default test://$PATH URI, and use the same internal helpers for assembling the driver contents. --- src/test/test_driver.c | 142 +++++++++++++------------------------------------ 1 file changed, 37 insertions(+), 105 deletions(-) -- 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list diff --git a/src/test/test_driver.c b/src/test/test_driver.c index e0d3e60..3f3e405 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -407,7 +407,8 @@ testDriverNew(void) } -static const char *defaultDomainXML = +static const char *defaultConnXML = +"" "" " test" " 6695eb01-f6a4-8304-79aa-97f2502e193f" @@ -417,10 +418,8 @@ static const char *defaultDomainXML = " " " hvm" " " -""; - - -static const char *defaultNetworkXML = +"" +"" "" " default" " dd8fe884-6c02-601e-7551-cca97df1c5df" @@ -431,9 +430,8 @@ static const char *defaultNetworkXML = " " " " " " -""; - -static const char *defaultInterfaceXML = +"" +"" "" " " " " @@ -442,16 +440,34 @@ static const char *defaultInterfaceXML = " " " " " " -""; - -static const char *defaultPoolXML = +"" +"" "" " default-pool" " dfe224cb-28fb-8dd0-c4b2-64eb3f0f4566" " " " /default-pool" " " -""; +"" +"" +"" +" computer" +" " +" " +" Libvirt" +" Test driver" +" 123456" +" 11111111-2222-3333-4444-555555555555" +" " +" " +" Libvirt" +" Test Driver" +" 01/22/2007" +" " +" " +"" +""; + static const char *defaultPoolSourcesLogicalXML = "\n" @@ -476,24 +492,6 @@ static const char *defaultPoolSourcesNetFSXML = " \n" "\n"; -static const char *defaultNodeXML = -"" -" computer" -" " -" " -" Libvirt" -" Test driver" -" 123456" -" 11111111-2222-3333-4444-555555555555" -" " -" " -" Libvirt" -" Test Driver" -" 01/22/2007" -" " -" " -""; - static const unsigned long long defaultPoolCap = (100 * 1024 * 1024 * 1024ull); static const unsigned long long defaultPoolAlloc; @@ -1239,16 +1237,8 @@ testOpenDefault(virConnectPtr conn) { int u; testDriverPtr privconn = NULL; - virDomainDefPtr domdef = NULL; - virDomainObjPtr domobj = NULL; - virNetworkDefPtr netdef = NULL; - virNetworkObjPtr netobj = NULL; - virInterfaceDefPtr interfacedef = NULL; - virInterfaceObjPtr interfaceobj = NULL; - virStoragePoolDefPtr pooldef = NULL; - virStoragePoolObjPtr poolobj = NULL; - virNodeDeviceDefPtr nodedef = NULL; - virNodeDeviceObjPtr nodeobj = NULL; + xmlDocPtr doc = NULL; + xmlXPathContextPtr ctxt = NULL; virMutexLock(&defaultLock); if (defaultConnections++) { @@ -1284,84 +1274,26 @@ testOpenDefault(virConnectPtr conn) if (!(privconn->caps = testBuildCapabilities(conn))) goto error; - if (!(domdef = virDomainDefParseString(defaultDomainXML, - privconn->caps, - privconn->xmlopt, - VIR_DOMAIN_DEF_PARSE_INACTIVE))) + if (!(doc = virXMLParseStringCtxt(defaultConnXML, + _("(test driver)"), &ctxt))) goto error; - if (testDomainGenerateIfnames(domdef) < 0) - goto error; - if (!(domobj = virDomainObjListAdd(privconn->domains, - domdef, - privconn->xmlopt, - 0, NULL))) + if (testOpenParse(privconn, NULL, ctxt) < 0) goto error; - domdef = NULL; - - domobj->persistent = 1; - if (testDomainStartState(privconn, domobj, - VIR_DOMAIN_RUNNING_BOOTED) < 0) { - virObjectUnlock(domobj); - goto error; - } - - virObjectUnlock(domobj); - - if (!(netdef = virNetworkDefParseString(defaultNetworkXML))) - goto error; - if (!(netobj = virNetworkAssignDef(privconn->networks, netdef, 0))) { - virNetworkDefFree(netdef); - goto error; - } - netobj->active = 1; - virNetworkObjEndAPI(&netobj); - - if (!(interfacedef = virInterfaceDefParseString(defaultInterfaceXML))) - goto error; - if (!(interfaceobj = virInterfaceAssignDef(&privconn->ifaces, interfacedef))) { - virInterfaceDefFree(interfacedef); - goto error; - } - interfaceobj->active = 1; - virInterfaceObjUnlock(interfaceobj); - - if (!(pooldef = virStoragePoolDefParseString(defaultPoolXML))) - goto error; - - if (!(poolobj = virStoragePoolObjAssignDef(&privconn->pools, - pooldef))) { - virStoragePoolDefFree(pooldef); - goto error; - } - - if (testStoragePoolObjSetDefaults(poolobj) == -1) { - virStoragePoolObjUnlock(poolobj); - goto error; - } - poolobj->active = 1; - virStoragePoolObjUnlock(poolobj); - - /* Init default node device */ - if (!(nodedef = virNodeDeviceDefParseString(defaultNodeXML, 0, NULL))) - goto error; - if (!(nodeobj = virNodeDeviceAssignDef(&privconn->devs, - nodedef))) { - virNodeDeviceDefFree(nodedef); - goto error; - } - virNodeDeviceObjUnlock(nodeobj); defaultConn = privconn; + xmlXPathFreeContext(ctxt); + xmlFreeDoc(doc); virMutexUnlock(&defaultLock); return VIR_DRV_OPEN_SUCCESS; error: testDriverFree(privconn); + xmlXPathFreeContext(ctxt); + xmlFreeDoc(doc); conn->privateData = NULL; - virDomainDefFree(domdef); defaultConnections--; virMutexUnlock(&defaultLock); return VIR_DRV_OPEN_ERROR;