devices: smartcard: Use CharSource

smartcard does the same internally for libvirt, so let's follow that
pattern, and fix the fallout
This commit is contained in:
Cole Robinson 2019-05-13 15:10:38 -04:00
parent 9d78759ac5
commit 43a39dc158
5 changed files with 32 additions and 1 deletions

View File

@ -483,6 +483,9 @@ Foo bar baz & yeah boii < > yeahfoo
<source mode='bind' host='127.0.0.1' service='2001'/>
<protocol type='raw'/>
</smartcard>
<smartcard mode='passthrough' type='unix'>
<source mode='bind' path='/tmp/smartcard.sock'/>
</smartcard>
<!-- redir devices -->

View File

@ -54,6 +54,13 @@
</smartcard>
<smartcard mode='passthrough' type='spicevmc'>
</smartcard>
<smartcard mode='passthrough' type='tcp'>
<source mode='bind' host='127.0.0.1' service='2001'/>
<protocol type='raw'/>
</smartcard>
<smartcard mode='passthrough' type='unix'>
<source mode='bind' path='/tmp/smartcard.sock'/>
</smartcard>
</devices>
<seclabel type='static' model='selinux'>
<label>foolabel</label>

View File

@ -54,6 +54,13 @@
</smartcard>
<smartcard mode="host">
</smartcard>
<smartcard mode="passthrough" type="tcp">
<source mode="bind" host="127.0.0.1" service="2001"/>
<protocol type="raw"/>
</smartcard>
<smartcard mode="passthrough" type="unix">
<source mode="bind" path="/tmp/smartcard.sock"/>
</smartcard>
</devices>
<seclabel type="static" model="selinux">
<label>foolabel</label>

View File

@ -966,6 +966,8 @@ class XMLParseTest(unittest.TestCase):
dev1 = guest.devices.smartcard[0]
dev2 = guest.devices.smartcard[1]
dev3 = guest.devices.smartcard[2]
dev4 = guest.devices.smartcard[3]
check = self._make_checker(dev1)
check("type", None, "tcp")
@ -974,6 +976,16 @@ class XMLParseTest(unittest.TestCase):
check("mode", "passthrough", "host")
check("type", "spicevmc", None)
check = self._make_checker(dev3)
check("type", "tcp")
check("source.host", "127.0.0.1")
check("source.service", 2001)
check = self._make_checker(dev4)
check("type", "unix")
check("source.path", "/tmp/smartcard.sock")
check("source.mode", "bind")
self._alter_compare(guest.get_xml(), outfile)
def testAlterRedirdev(self):

View File

@ -4,8 +4,9 @@
# This work is licensed under the GNU GPLv2 or later.
# See the COPYING file in the top-level directory.
from .char import CharSource
from .device import Device
from ..xmlbuilder import XMLProperty
from ..xmlbuilder import XMLChildProperty, XMLProperty
class DeviceSmartcard(Device):
@ -14,6 +15,7 @@ class DeviceSmartcard(Device):
mode = XMLProperty("./@mode")
type = XMLProperty("./@type")
source = XMLChildProperty(CharSource, is_single=True)
##################