Blame 0006-Integrate-Smartcard-support.patch

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