Change in vdsm[ovirt-3.2]: Integrate Smartcard support

ofrenkel at redhat.com ofrenkel at redhat.com
Tue Jan 1 16:02:02 UTC 2013


Hello Tomas Jelinek, Antoni Segura Puimedon, Peter V. Saveliev,

I'd like you to do a code review.  Please visit

    http://gerrit.ovirt.org/10547

to review the following change.

Change subject: Integrate Smartcard support
......................................................................

Integrate Smartcard support

This patch is a VDSM part of the integrating
the smartcard support to the ovirt:

This VDSM part integrates the smartcard  in
a supported way, not just as an unsupported custom hook.

It also removes the smartcard hook itself.

Change-Id: I7cdaef420c8381d588f6215e66e6a80dd9d2e44b
Signed-off-by: Tomas Jelinek <tjelinek at redhat.com>
Signed-off-by: Peter V. Saveliev <peet at redhat.com>
Signed-off-by: Antoni S. Puimedon <asegurap at redhat.com>
---
M configure.ac
M tests/libvirtvmTests.py
M vdsm.spec.in
M vdsm/libvirtvm.py
M vdsm/vm.py
M vdsm_api/vdsmapi-schema.json
M vdsm_hooks/Makefile.am
M vdsm_hooks/README
D vdsm_hooks/smartcard/Makefile.am
D vdsm_hooks/smartcard/README
D vdsm_hooks/smartcard/before_vm_start.py
11 files changed, 116 insertions(+), 77 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/47/10547/1

diff --git a/configure.ac b/configure.ac
index a6265b5..3489e38 100644
--- a/configure.ac
+++ b/configure.ac
@@ -209,7 +209,6 @@
 	vdsm_hooks/qos/Makefile
 	vdsm_hooks/qemucmdline/Makefile
 	vdsm_hooks/scratchpad/Makefile
-	vdsm_hooks/smartcard/Makefile
 	vdsm_hooks/smbios/Makefile
 	vdsm_hooks/sriov/Makefile
 	vdsm_hooks/vhostmd/Makefile
diff --git a/tests/libvirtvmTests.py b/tests/libvirtvmTests.py
index 4ed7318..bd68f2a 100644
--- a/tests/libvirtvmTests.py
+++ b/tests/libvirtvmTests.py
@@ -91,6 +91,13 @@
             domxml.appendOs()
             self.assertXML(domxml.dom, xml, 'os')
 
+    def testSmartcardXML(self):
+        smartcardXML = '<smartcard mode="passthrough" type="spicevmc"/>'
+        dev = {'device': 'smartcard',
+               'specParams': {'mode': 'passthrough', 'type': 'spicevmc'}}
+        smartcard = libvirtvm.SmartCardDevice(self.conf, self.log, **dev)
+        self.assertXML(smartcard.getXML(), smartcardXML)
+
     def testFeaturesXML(self):
         featuresXML = """
             <features>
diff --git a/vdsm.spec.in b/vdsm.spec.in
index 1978fa9..f9e238b 100644
--- a/vdsm.spec.in
+++ b/vdsm.spec.in
@@ -353,14 +353,6 @@
 the disk will be erased when the VM destroyed.
 VM cannot be migrated when using scratchpad hook
 
-%package hook-smartcard
-Summary:        Smartcard support for Spice protocol in VDSM
-BuildArch:      noarch
-
-%description hook-smartcard
-Smartcard hook add support for spice in VDSM.
-Smartcard hook enable user to use its smartcard inside virtual machines.
-
 %package hook-smbios
 Summary:        Adding custom smbios entries to libvirt domain via VDSM
 BuildArch:      noarch
@@ -886,10 +878,6 @@
 %{_libexecdir}/%{vdsm_name}/hooks/before_vm_start/50_scratchpad
 %{_libexecdir}/%{vdsm_name}/hooks/before_vm_migrate_source/50_scratchpad
 %{_libexecdir}/%{vdsm_name}/hooks/after_vm_destroy/50_scratchpad
-
-%files hook-smartcard
-%defattr(-, root, root, -)
-%{_libexecdir}/%{vdsm_name}/hooks/before_vm_start/50_smartcard
 
 %files hook-smbios
 %defattr(-, root, root, -)
diff --git a/vdsm/libvirtvm.py b/vdsm/libvirtvm.py
index 219e382..fe140ec 100644
--- a/vdsm/libvirtvm.py
+++ b/vdsm/libvirtvm.py
@@ -1243,6 +1243,21 @@
         return m
 
 
+class SmartCardDevice(LibvirtVmDevice):
+    def getXML(self):
+        """
+        Add smartcard section to domain xml
+
+        <smartcard mode='passthrough' type='spicevmc'>
+          <address ... />
+        </smartcard>
+        """
+        card = self.createXmlElem(self.device, None, ['address'])
+        card.setAttribute('mode', self.specParams['mode'])
+        card.setAttribute('type', self.specParams['type'])
+        return card
+
+
 class RedirDevice(LibvirtVmDevice):
     def getXML(self):
         """
@@ -1395,6 +1410,7 @@
         self._getUnderlyingControllerDeviceInfo()
         self._getUnderlyingBalloonDeviceInfo()
         self._getUnderlyingWatchdogDeviceInfo()
+        self._getUnderlyingSmartcardDeviceInfo()
         # Obtain info of all unknown devices. Must be last!
         self._getUnderlyingUnknownDeviceInfo()
 
@@ -1486,7 +1502,8 @@
                   vm.BALLOON_DEVICES: BalloonDevice,
                   vm.WATCHDOG_DEVICES: WatchdogDevice,
                   vm.REDIR_DEVICES: RedirDevice,
-                  vm.CONSOLE_DEVICES: ConsoleDevice}
+                  vm.CONSOLE_DEVICES: ConsoleDevice,
+                  vm.SMARTCARD_DEVICES: SmartCardDevice}
 
         for devType, devClass in devMap.items():
             for dev in devices[devType]:
@@ -2800,6 +2817,31 @@
                     dev['address'] = address
                     dev['alias'] = alias
 
+    def _getUnderlyingSmartcardDeviceInfo(self):
+        """
+        Obtain smartcard device info from libvirt.
+        """
+        smartcardxml = _domParseStr(self._lastXMLDesc).childNodes[0].\
+            getElementsByTagName('devices')[0].\
+            getElementsByTagName('smartcard')
+        for x in smartcardxml:
+            if not x.getElementsByTagName('address'):
+                continue
+
+            address = self._getUnderlyingDeviceAddress(x)
+            alias = x.getElementsByTagName('alias')[0].getAttribute('name')
+
+            for dev in self._devices[vm.SMARTCARD_DEVICES]:
+                if not hasattr(dev, 'address'):
+                    dev.address = address
+                    dev.alias = alias
+
+            for dev in self.conf['devices']:
+                if dev['device'] == vm.SMARTCARD_DEVICES and \
+                        not dev.get('address'):
+                    dev['address'] = address
+                    dev['alias'] = alias
+
     def _getUnderlyingWatchdogDeviceInfo(self):
         """
         Obtain watchdog device info from libvirt.
diff --git a/vdsm/vm.py b/vdsm/vm.py
index 49fcb11..9610644 100644
--- a/vdsm/vm.py
+++ b/vdsm/vm.py
@@ -47,6 +47,7 @@
 REDIR_DEVICES = 'redir'
 WATCHDOG_DEVICES = 'watchdog'
 CONSOLE_DEVICES = 'console'
+SMARTCARD_DEVICES = 'smartcard'
 
 """
 A module containing classes needed for VM communication.
@@ -364,7 +365,8 @@
                          SOUND_DEVICES: [], VIDEO_DEVICES: [],
                          CONTROLLER_DEVICES: [], GENERAL_DEVICES: [],
                          BALLOON_DEVICES: [], REDIR_DEVICES: [],
-                         WATCHDOG_DEVICES: [], CONSOLE_DEVICES: []}
+                         WATCHDOG_DEVICES: [], CONSOLE_DEVICES: [],
+                         SMARTCARD_DEVICES: []}
 
     def _get_lastStatus(self):
         PAUSED_STATES = ('Powering down', 'RebootInProgress', 'Up')
@@ -447,7 +449,8 @@
                    SOUND_DEVICES: [], VIDEO_DEVICES: [],
                    CONTROLLER_DEVICES: [], GENERAL_DEVICES: [],
                    BALLOON_DEVICES: [], REDIR_DEVICES: [],
-                   WATCHDOG_DEVICES: [], CONSOLE_DEVICES: []}
+                   WATCHDOG_DEVICES: [], CONSOLE_DEVICES: [],
+                   SMARTCARD_DEVICES: []}
         for dev in self.conf.get('devices'):
             try:
                 devices[dev['type']].append(dev)
@@ -485,6 +488,7 @@
             devices[GENERAL_DEVICES] = []
             devices[BALLOON_DEVICES] = []
             devices[WATCHDOG_DEVICES] = []
+            devices[SMARTCARD_DEVICES] = self.getConfSmartcard()
             devices[REDIR_DEVICES] = []
             devices[CONSOLE_DEVICES] = []
         else:
@@ -549,6 +553,17 @@
 
         return vcards
 
+    def getConfSmartcard(self):
+        """
+        Normalize smartcard device (now there is only one)
+        """
+        cards = []
+        if self.conf.get('smartcard'):
+            cards.append({'device': SMARTCARD_DEVICES,
+                          'specParams': {'mode': 'passthrough',
+                                         'type': 'spicevmc'}})
+        return cards
+
     def getConfSound(self):
         """
         Normalize sound device provided by conf.
diff --git a/vdsm_api/vdsmapi-schema.json b/vdsm_api/vdsmapi-schema.json
index c72ec4b..7c9ef22 100644
--- a/vdsm_api/vdsmapi-schema.json
+++ b/vdsm_api/vdsmapi-schema.json
@@ -1685,11 +1685,13 @@
 #
 # @console:     A console device
 #
+# @smartcard:   A smartcard device
+#
 # Since: 4.10.0
 ##
 {'enum': 'VmDeviceType',
  'data': ['disk', 'interface', 'video', 'sound', 'controller', 'balloon',
-          'channel', 'console']}
+          'channel', 'console', 'smartcard']}
 
 ##
 # @VmDiskDeviceType:
@@ -2356,6 +2358,48 @@
           'address': 'VmDeviceAddress', 'alias': 'str', 'deviceId': 'UUID'}}
 
 ##
+# @VmSmartcardDeviceSpecParams:
+#
+# Additional VM smartcard device parameters.
+#
+# Since: 4.10.3
+##
+{'type': 'VmSmartcardDeviceSpecParams', 'data': {}}
+
+##
+# @VmSmartcardDeviceType:
+#
+# An enumeration of VM smartcard device types.
+#
+# @smartcard: A smartcard
+#
+# Since: 4.10.3
+##
+{'enum': 'VmSmartcardDeviceType', 'data': ['smartcard']}
+
+##
+# @VmSmartcardDevice:
+#
+# Properties of a VM smartcard device.
+#
+# @deviceType:  The device type (always @smartcard)
+#
+# @device:      The the type of smartcard device
+#
+# @address:     Device hardware address
+#
+# @alias:       Alias used to identify this device in commands
+#
+# @specParams:  #optional Additional device parameters
+#
+# Since: 4.10.3
+##
+{'type': 'VmSmartcardDevice',
+ 'data': {'deviceType': 'VmDeviceType', 'device': 'VmSmartcardDeviceType',
+          'address': 'VmDeviceAddress', 'alias': 'str',
+          '*specParams': 'VmSmartcardDeviceSpecParams'}}
+
+##
 # @VmConsoleDevice:
 #
 # Properties of a VM console device.
@@ -2382,7 +2426,8 @@
  'data': {'deviceType': 'VmDeviceType',},
  'union': ['VmDiskDevice', 'VmInterfaceDevice', 'VmVideoDevice',
           'VmSoundDevice', 'VmControllerDevice', 'VmBalloonDevice',
-          'VmChannelDevice', 'VmWatchdogDevice', 'VmConsoleDevice']}
+          'VmChannelDevice', 'VmWatchdogDevice', 'VmConsoleDevice',
+          'VmSmartcardDevice']}
 
 ##
 # @VmShortStatus:
diff --git a/vdsm_hooks/Makefile.am b/vdsm_hooks/Makefile.am
index 9f00d4d..0e27a98 100644
--- a/vdsm_hooks/Makefile.am
+++ b/vdsm_hooks/Makefile.am
@@ -37,7 +37,6 @@
 	promisc \
 	qos \
 	scratchpad \
-	smartcard \
 	smbios \
 	sriov \
 	vmdisk \
diff --git a/vdsm_hooks/README b/vdsm_hooks/README
index b45b93e..1659610 100644
--- a/vdsm_hooks/README
+++ b/vdsm_hooks/README
@@ -24,7 +24,7 @@
 
    If you want to enable more then one custom hook use the semicolon as
    a separator:
-   # rhevm-config -s UserDefinedVMProperties='pincpu=^[0-9]+$;smartcard=^(true|false)$' --cver=3.0
+   # rhevm-config -s UserDefinedVMProperties='pincpu=^[0-9]+$;sap_agent=^(true|false)$' --cver=3.0
 
    The convention is [hook name]=[value], the value is evaluate with regular expression,
    If you find regular expression too complex, you can always use the following command:
@@ -47,7 +47,7 @@
       pincpu=1
       if you want to use more then on hook and you did enable it with the rhevm-config
       tool, you can use the semicolon as a separator:
-      pincpu=1;smartcard=true
+      pincpu=1;sap_agent=true
    b. Another option is to use "Run Once" dialog which mean that you add a custom property
       only this time to the VM, next time that you run the VM it will run without the
       custom property that you provided.
diff --git a/vdsm_hooks/smartcard/Makefile.am b/vdsm_hooks/smartcard/Makefile.am
deleted file mode 100644
index dfefff5..0000000
--- a/vdsm_hooks/smartcard/Makefile.am
+++ /dev/null
@@ -1,18 +0,0 @@
-# Copyright 2008 Red Hat, Inc. and/or its affiliates.
-#
-# Licensed to you under the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.  See the files README and
-# LICENSE_GPL_v2 which accompany this distribution.
-#
-
-EXTRA_DIST = \
-	before_vm_start.py
-
-install-data-local:
-	$(MKDIR_P) $(DESTDIR)$(vdsmhooksdir)/before_vm_start
-	$(INSTALL_SCRIPT) $(srcdir)/before_vm_start.py \
-		$(DESTDIR)$(vdsmhooksdir)/before_vm_start/50_smartcard
-
-uninstall-local:
-	$(RM) $(DESTDIR)$(vdsmhooksdir)/before_vm_start/50_smartcard
diff --git a/vdsm_hooks/smartcard/README b/vdsm_hooks/smartcard/README
deleted file mode 100644
index bd376bf..0000000
--- a/vdsm_hooks/smartcard/README
+++ /dev/null
@@ -1,9 +0,0 @@
-smartcard hook:
-===============
-add smartcard support for spice
-
-syntax:
-smartcard: smartcard=true
-
-libvirt xml:
-<smartcard mode='passthrough' type='spicevmc'/>
diff --git a/vdsm_hooks/smartcard/before_vm_start.py b/vdsm_hooks/smartcard/before_vm_start.py
deleted file mode 100755
index 1944978..0000000
--- a/vdsm_hooks/smartcard/before_vm_start.py
+++ /dev/null
@@ -1,29 +0,0 @@
-#!/usr/bin/python
-
-import os
-import sys
-import hooking
-import traceback
-
-'''
-smartcard vdsm hook
-adding to domain xml
-<smartcard mode='passthrough' type='spicevmc'/>
-'''
-
-if 'smartcard' in os.environ:
-    try:
-        sys.stderr.write('smartcard: adding smartcard support\n')
-        domxml = hooking.read_domxml()
-
-        devices = domxml.getElementsByTagName('devices')[0]
-        card = domxml.createElement('smartcard')
-        card.setAttribute('mode', 'passthrough')
-        card.setAttribute('type', 'spicevmc')
-
-        devices.appendChild(card)
-
-        hooking.write_domxml(domxml)
-    except:
-        sys.stderr.write('smartcard: [unexpected error]: %s\n' % traceback.format_exc())
-        sys.exit(2)


--
To view, visit http://gerrit.ovirt.org/10547
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7cdaef420c8381d588f6215e66e6a80dd9d2e44b
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: ovirt-3.2
Gerrit-Owner: Omer Frenkel <ofrenkel at redhat.com>
Gerrit-Reviewer: Antoni Segura Puimedon <asegurap at redhat.com>
Gerrit-Reviewer: Peter V. Saveliev <peet at redhat.com>
Gerrit-Reviewer: Tomas Jelinek <tjelinek at redhat.com>


More information about the vdsm-patches mailing list