[virt-tools-list] [PATCH 1/4] virtinst: allow EGD RNG devices to have both bind and connect sources

Giuseppe Scrivano gscrivan at redhat.com
Fri Oct 25 15:13:26 UTC 2013


Remove backend_mode from VirtualRNGDevice and allow to directly specify
bind and connect sources.

Signed-off-by: Giuseppe Scrivano <gscrivan at redhat.com>
---
 tests/xmlparse-xml/change-rng-egd-in.xml  |  1 +
 tests/xmlparse-xml/change-rng-egd-out.xml |  5 ++--
 tests/xmlparse.py                         |  9 ++++---
 virtinst/devicerng.py                     | 43 ++++++++++++++++++++++++++-----
 4 files changed, 45 insertions(+), 13 deletions(-)

diff --git a/tests/xmlparse-xml/change-rng-egd-in.xml b/tests/xmlparse-xml/change-rng-egd-in.xml
index 8f39585..e468f52 100644
--- a/tests/xmlparse-xml/change-rng-egd-in.xml
+++ b/tests/xmlparse-xml/change-rng-egd-in.xml
@@ -53,6 +53,7 @@
     <rng model='virtio'>
       <rate period='2000' bytes='1234'/>
       <backend model='egd' type='udp'>
+        <source mode='bind' service='1233'/>
         <source mode='connect' host='1.2.3.4' service='1234'/>
       </backend>
     </rng>
diff --git a/tests/xmlparse-xml/change-rng-egd-out.xml b/tests/xmlparse-xml/change-rng-egd-out.xml
index 2121c43..29362c4 100644
--- a/tests/xmlparse-xml/change-rng-egd-out.xml
+++ b/tests/xmlparse-xml/change-rng-egd-out.xml
@@ -52,8 +52,9 @@
     <console type="pty"/>
     <rng model="virtio">
       <rate period="2001" bytes="4321"/>
-      <backend model="egd" type="tcp">
-        <source mode="bind" host="1.2.3.5" service="1235"/>
+      <backend model="egd" type="udp">
+        <source mode="bind" service="1236"/>
+        <source mode="connect" host="1.2.3.5" service="1235"/>
       </backend>
     </rng>
   </devices>
diff --git a/tests/xmlparse.py b/tests/xmlparse.py
index 1dd61a6..31dd383 100644
--- a/tests/xmlparse.py
+++ b/tests/xmlparse.py
@@ -746,11 +746,12 @@ class XMLParseTest(unittest.TestCase):
 
         check = self._make_checker(dev1)
         check("type", "egd")
-        check("backend_type", "udp", "tcp")
+        check("backend_type", "udp", "udp")
 
-        check("backend_source_host", "1.2.3.4", "1.2.3.5")
-        check("backend_source_service", "1234", "1235")
-        check("backend_source_mode", "connect", "bind")
+        check("connect_host", "1.2.3.4", "1.2.3.5")
+        check("connect_service", "1234", "1235")
+        check("bind_host", None, None)
+        check("bind_service", "1233", "1236")
 
         check("rate_bytes", "1234", "4321")
         check("rate_period", "2000", "2001")
diff --git a/virtinst/devicerng.py b/virtinst/devicerng.py
index c28dde0..3d12576 100644
--- a/virtinst/devicerng.py
+++ b/virtinst/devicerng.py
@@ -62,11 +62,11 @@ class VirtualRNGDevice(VirtualDevice):
         """
         users = {
             "type"                   : [self.TYPE_EGD, self.TYPE_RANDOM],
-
             "model"                  : [self.TYPE_EGD, self.TYPE_RANDOM],
-            "backend_source_host"    : [self.TYPE_EGD],
-            "backend_source_mode"    : [self.TYPE_EGD],
-            "backend_source_service" : [self.TYPE_EGD],
+            "bind_host"              : [self.TYPE_EGD],
+            "bind_service"           : [self.TYPE_EGD],
+            "connect_host"           : [self.TYPE_EGD],
+            "connect_service"        : [self.TYPE_EGD],
             "backend_type"           : [self.TYPE_EGD],
             "device"                 : [self.TYPE_RANDOM],
             "rate_bytes"             : [self.TYPE_EGD, self.TYPE_RANDOM],
@@ -77,14 +77,43 @@ class VirtualRNGDevice(VirtualDevice):
 
         return hasattr(self, propname)
 
+    def backend_mode(self):
+        ret = []
+        if self._has_mode_bind:
+            ret.append(VirtualRNGDevice.BACKEND_MODE_BIND)
+        if self._has_mode_connect:
+            ret.append(VirtualRNGDevice.BACKEND_MODE_CONNECT)
+        return ret
+
+    _XML_PROP_ORDER = ["_has_mode_bind", "_has_mode_connect"]
+
+    _has_mode_connect = XMLProperty("./backend/source[@mode='connect']/@mode")
+    def _set_connect_validate(self, val):
+        if val:
+            self._has_mode_connect = VirtualRNGDevice.BACKEND_MODE_CONNECT
+        return val
+
+    _has_mode_bind = XMLProperty("./backend/source[@mode='bind']/@mode")
+    def _set_bind_validate(self, val):
+        if val:
+            self._has_mode_bind = VirtualRNGDevice.BACKEND_MODE_BIND
+        return val
+
     type = XMLProperty(xpath="./backend/@model")
     model = XMLProperty(xpath="./@model",
                         default_cb=lambda s: "virtio")
 
     backend_type = XMLProperty(xpath="./backend/@type")
-    backend_source_host = XMLProperty(xpath="./backend/source/@host")
-    backend_source_service = XMLProperty(xpath="./backend/source/@service")
-    backend_source_mode = XMLProperty(xpath="./backend/source/@mode")
+
+    bind_host = XMLProperty(xpath="./backend/source[@mode='bind']/@host",
+                            set_converter=_set_bind_validate)
+    bind_service = XMLProperty(xpath="./backend/source[@mode='bind']/@service",
+                               set_converter=_set_bind_validate)
+
+    connect_host = XMLProperty(xpath="./backend/source[@mode='connect']/@host",
+                               set_converter=_set_connect_validate)
+    connect_service = XMLProperty(set_converter=_set_connect_validate,
+                           xpath="./backend/source[@mode='connect']/@service")
 
     rate_bytes = XMLProperty(xpath="./rate/@bytes")
     rate_period = XMLProperty(xpath="./rate/@period")
-- 
1.8.3.1




More information about the virt-tools-list mailing list