[libvirt] [PATCH 5/5] test: Support loading node device info from file/XML

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Also add some XML examples.

Signed-off-by: Cole Robinson <crobinso@xxxxxxxxxx>
---
 examples/xml/test/testdev.xml        |   16 +++++++++++++
 examples/xml/test/testnode.xml       |    1 +
 examples/xml/test/testnodeinline.xml |   19 ++++++++++++++++
 src/test/test_driver.c               |   40 +++++++++++++++++++++++++++++++++-
 4 files changed, 75 insertions(+), 1 deletions(-)
 create mode 100644 examples/xml/test/testdev.xml

diff --git a/examples/xml/test/testdev.xml b/examples/xml/test/testdev.xml
new file mode 100644
index 0000000..c49caa7
--- /dev/null
+++ b/examples/xml/test/testdev.xml
@@ -0,0 +1,16 @@
+<device>
+  <name>File_test_device</name>
+  <capability type='system'>
+    <hardware>
+      <vendor>Libvirt</vendor>
+      <version>Test driver</version>
+      <serial>123456</serial>
+      <uuid>11111111-2222-3333-4444-555555555555</uuid>
+    </hardware>
+    <firmware>
+      <vendor>Libvirt</vendor>
+      <version>Test Driver</version>
+      <release_date>01/22/2007</release_date>
+    </firmware>
+  </capability>
+</device>
diff --git a/examples/xml/test/testnode.xml b/examples/xml/test/testnode.xml
index 1ad7a10..adc5440 100644
--- a/examples/xml/test/testnode.xml
+++ b/examples/xml/test/testnode.xml
@@ -14,6 +14,7 @@
   <pool file="testpool.xml">
     <volume file="testvol.xml"/>
   </pool>
+  <device file="testdev.xml"/>
 
   <cpu>
     <mhz>6000</mhz>
diff --git a/examples/xml/test/testnodeinline.xml b/examples/xml/test/testnodeinline.xml
index 1810d4d..b353f39 100644
--- a/examples/xml/test/testnodeinline.xml
+++ b/examples/xml/test/testnodeinline.xml
@@ -97,6 +97,25 @@
       </dhcp>
     </ip>
   </network>
+
+<device>
+  <name>File_test_device</name>
+  <capability type='system'>
+    <hardware>
+      <vendor>Libvirt</vendor>
+      <version>Test driver</version>
+      <serial>123456</serial>
+      <uuid>11111111-2222-3333-4444-555555555555</uuid>
+    </hardware>
+    <firmware>
+      <vendor>Libvirt</vendor>
+      <version>Test Driver</version>
+      <release_date>01/22/2007</release_date>
+    </firmware>
+  </capability>
+</device>
+
+
   <cpu>
     <mhz>6000</mhz>
     <model>i986</model>
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 2a413ee..764faf2 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -547,7 +547,8 @@ static int testOpenFromFile(virConnectPtr conn,
     char *str;
     xmlDocPtr xml = NULL;
     xmlNodePtr root = NULL;
-    xmlNodePtr *domains = NULL, *networks = NULL, *ifaces = NULL, *pools = NULL;
+    xmlNodePtr *domains = NULL, *networks = NULL, *ifaces = NULL,
+               *pools = NULL, *devs = NULL;
     xmlXPathContextPtr ctxt = NULL;
     virNodeInfoPtr nodeInfo;
     virNetworkObjPtr net;
@@ -841,6 +842,43 @@ static int testOpenFromFile(virConnectPtr conn,
     }
     VIR_FREE(pools);
 
+    ret = virXPathNodeSet(conn, "/node/device", ctxt, &devs);
+    if (ret < 0) {
+        testError(NULL, VIR_ERR_XML_ERROR, "%s", _("node device list"));
+        goto error;
+    }
+    for (i = 0 ; i < ret ; i++) {
+        virNodeDeviceDefPtr def;
+        virNodeDeviceObjPtr dev;
+        char *relFile = virXMLPropString(devs[i], "file");
+
+        if (relFile != NULL) {
+            char *absFile = testBuildFilename(file, relFile);
+            VIR_FREE(relFile);
+
+            if (!absFile) {
+                testError(NULL, VIR_ERR_INTERNAL_ERROR, "%s",
+                          _("resolving device filename"));
+                goto error;
+            }
+
+            def = virNodeDeviceDefParseFile(conn, absFile, 0);
+            VIR_FREE(absFile);
+            if (!def)
+                goto error;
+        } else {
+            if ((def = virNodeDeviceDefParseNode(conn, xml, devs[i], 0)) == NULL)
+                goto error;
+        }
+        if (!(dev = virNodeDeviceAssignDef(conn, &privconn->devs, def))) {
+            virNodeDeviceDefFree(def);
+            goto error;
+        }
+        virNodeDeviceObjUnlock(dev);
+    }
+    VIR_FREE(devs);
+
+
     xmlXPathFreeContext(ctxt);
     xmlFreeDoc(xml);
     testDriverUnlock(privconn);
-- 
1.6.5.rc2

--
Libvir-list mailing list
Libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]