[virt-tools-list] [virt-manager PATCH v2 2/4] Add CLI support and CLI test cases

Stefan Berger stefanb at linux.vnet.ibm.com
Wed Jun 26 01:45:07 UTC 2013


Signed-off-by: Stefan Berger <stefanb at linux.vnet.ibm.com>
---
 man/virt-install.pod                        | 28 +++++++++++++++++++
 tests/cli-test-xml/compare/many-devices.xml | 10 +++++++
 tests/clitest.py                            | 11 +++++++-
 virt-install                                |  1 +
 virtinst/cli.py                             | 42 +++++++++++++++++++++++++++++
 5 files changed, 91 insertions(+), 1 deletion(-)

diff --git a/man/virt-install.pod b/man/virt-install.pod
index f7b8cf6..32bbccf 100644
--- a/man/virt-install.pod
+++ b/man/virt-install.pod
@@ -1175,6 +1175,34 @@ Do not use memballoon device:
 
 --memballoon none
 
+=item --tpm=TYPE[,OPTS]
+
+Configure a virtual TPM device.
+
+Type must be B<passthrough>. Additional options are:
+
+=over 4
+
+=item B<model>
+
+The device model to present to the guest operating system. Model
+must be B<tpm-tis>.
+
+=back
+
+An example invocation:
+
+=over 4
+
+=item B<--tpm passthrough,model=tpm-tis>
+
+Make the host's TPM accessible to a single guest.
+
+=back
+
+See C<http://libvirt.org/formatdomain.html#elementsTpm> for complete
+details.
+
 =back
 
 =head2 Miscellaneous Options
diff --git a/tests/cli-test-xml/compare/many-devices.xml b/tests/cli-test-xml/compare/many-devices.xml
index a78d395..f71e3f3 100644
--- a/tests/cli-test-xml/compare/many-devices.xml
+++ b/tests/cli-test-xml/compare/many-devices.xml
@@ -76,6 +76,11 @@
     </channel>
     <smartcard mode='passthrough' type='spicevmc'>
     </smartcard>
+    <tpm model='tpm-tis'>
+      <backend type='passthrough'>
+        <device path='/dev/tpm0'/>
+      </backend>
+    </tpm>
   </devices>
   <seclabel type='static' model='testSecurity' relabel='yes'>
     <label>system_u:object_r:svirt_image_t:s0:c100,c200</label>
@@ -158,6 +163,11 @@
     </channel>
     <smartcard mode='passthrough' type='spicevmc'>
     </smartcard>
+    <tpm model='tpm-tis'>
+      <backend type='passthrough'>
+        <device path='/dev/tpm0'/>
+      </backend>
+    </tpm>
   </devices>
   <seclabel type='static' model='testSecurity' relabel='yes'>
     <label>system_u:object_r:svirt_image_t:s0:c100,c200</label>
diff --git a/tests/clitest.py b/tests/clitest.py
index 806c5d7..a1176e1 100644
--- a/tests/clitest.py
+++ b/tests/clitest.py
@@ -429,6 +429,15 @@ vinst.add_invalid("smartcard", "--smartcard passthrough,type=foo")  # Invalid ty
 vinst.add_invalid("smartcard", "--smartcard host,foobar=baz")  # --smartcard bogus
 
 
+vinst.add_category("tpm", "--noautoconsole --nodisks --pxe")
+vinst.add_valid("tpm", "--tpm passthrough")  # --tpm passthrough
+vinst.add_valid("tpm", "--tpm passthrough,model=tpm-tis")  # --tpm backend type with model
+vinst.add_valid("tpm", "--tpm passthrough,model=tpm-tis,path=/dev/tpm0")  # --tpm backend type with model and device path
+vinst.add_invalid("tpm", "--tpm")  # Missing argument
+vinst.add_invalid("tpm", "--tpm foo")  # Invalid argument
+vinst.add_invalid("tpm", "--tpm passthrough,model=foo")  # Invalid model
+
+
 vinst.add_category("xen", "--connect %(XENURI)s --noautoconsole")
 vinst.add_compare("xen", "--disk %(EXISTIMG1)s --import", "xen-default")  # Xen default
 vinst.add_compare("xen", "--disk %(EXISTIMG1)s --location %(TREEDIR)s --paravirt", "xen-pv")  # Xen PV
@@ -461,7 +470,7 @@ vinst.add_category("misc", "--nographics --noautoconsole")
 vinst.add_compare("misc", "", "noargs-fail")  # No arguments
 vinst.add_compare("misc", "--hvm --nodisks --pxe --print-step all", "simple-pxe")  # Diskless PXE install
 vinst.add_compare("misc", "--hvm --cdrom %(EXISTIMG2)s --file %(EXISTIMG1)s --os-variant win2k3 --wait 0 --vcpus cores=4", "w2k3-cdrom")  # HVM windows install with disk
-vinst.add_compare("misc", """--hvm --pxe --controller usb,model=ich9-ehci1,address=0:0:4.7,index=0 --controller usb,model=ich9-uhci1,address=0:0:4.0,index=0,master=0 --controller usb,model=ich9-uhci2,address=0:0:4.1,index=0,master=2 --controller usb,model=ich9-uhci3,address=0:0:4.2,index=0,master=4 --disk %(MANAGEDEXISTUPPER)s,cache=writeback,io=threads,perms=sh,serial=WD-WMAP9A966149 --disk %(NEWIMG1)s,sparse=false,size=.001,perms=ro,error_policy=enospace --disk device=cdrom,bus=sata --serial tcp,host=:2222,mode=bind,protocol=telnet --filesystem /source,/target,mode=squash --network user,mac=12:34:56:78:11:22 --network bridge=foobar,model=virtio --channel spicevmc --smartcard passthrough,type=spicevmc --security type=static,label='system_u:object_r:svirt_image_t:s0:c100,c200',relabel=yes  --numatune \\"1-3,5\\",mode=preferred --boot loader=/foo/bar """, "many-devices")  # Lot's of devices
+vinst.add_compare("misc", """--hvm --pxe --controller usb,model=ich9-ehci1,address=0:0:4.7,index=0 --controller usb,model=ich9-uhci1,address=0:0:4.0,index=0,master=0 --controller usb,model=ich9-uhci2,address=0:0:4.1,index=0,master=2 --controller usb,model=ich9-uhci3,address=0:0:4.2,index=0,master=4 --disk %(MANAGEDEXISTUPPER)s,cache=writeback,io=threads,perms=sh,serial=WD-WMAP9A966149 --disk %(NEWIMG1)s,sparse=false,size=.001,perms=ro,error_policy=enospace --disk device=cdrom,bus=sata --serial tcp,host=:2222,mode=bind,protocol=telnet --filesystem /source,/target,mode=squash --network user,mac=12:34:56:78:11:22 --network bridge=foobar,model=virtio --channel spicevmc --smartcard passthrough,type=spicevmc --tpm passthrough,model=tpm-tis,path=/dev/tpm0 --security type=static,label='system_u:object_r:svirt_image_t:s0:c100,c200',relabel=yes  --numatune \\"1-3,5\\",mode=preferred --boot loader=/foo/bar """, "many-devices")  # Lot's of devices
 vinst.add_compare("misc", "--connect %(DEFAULTURI)s --hvm --nodisks --pxe --cpuset auto --vcpus 2", "cpuset-auto")  # --cpuset=auto actually works
 vinst.add_valid("misc", "--hvm --disk path=virt-install,device=cdrom")  # Specifying cdrom media via --disk
 vinst.add_valid("misc", "--hvm --import --disk path=virt-install")  # FV Import install
diff --git a/virt-install b/virt-install
index 1b76015..6e1bad2 100755
--- a/virt-install
+++ b/virt-install
@@ -546,6 +546,7 @@ def build_guest_instance(conn, options):
                  guest, cli.parse_console)
     cli.get_hostdevs(options.hostdevs, guest)
     cli.get_smartcard(guest, options.smartcard)
+    cli.get_tpm(guest, options.tpm)
 
 
     # Install options
diff --git a/virtinst/cli.py b/virtinst/cli.py
index 99c49aa..74814c8 100644
--- a/virtinst/cli.py
+++ b/virtinst/cli.py
@@ -1042,6 +1042,17 @@ def get_smartcard(guest, sc_opts):
             guest.add_device(dev)
 
 
+def get_tpm(guest, tpm_opts):
+    for tpm in listify(tpm_opts):
+        try:
+            dev = parse_tpm(guest, tpm)
+        except Exception, e:
+            fail(_("Error in TPM device parameters: %s") % str(e))
+
+        if dev:
+            guest.add_device(dev)
+
+
 def get_controller(guest, sc_opts):
     for sc in listify(sc_opts):
         try:
@@ -1178,6 +1189,9 @@ def add_device_options(devg):
     devg.add_option("", "--memballoon", dest="memballoon", action="append",
                     help=_("Configure a guest memballoon device. Ex:\n"
                            "--memballoon model=virtio"))
+    devg.add_option("", "--tpm", dest="tpm", action="append",
+                    help=_("Configure a guest TPM device. Ex:\n"
+                           "--tpm type=passthrough"))
 
 
 def add_gfx_option(devg):
@@ -1901,6 +1915,34 @@ def parse_redirdev(guest, optstring, dev=None):
 
     return dev
 
+#######################
+# --tpm parsing #
+#######################
+
+
+def parse_tpm(guest, optstring, dev=None):
+    if optstring is None:
+        return None
+
+    # Peel the type off the front
+    opts = parse_optstr(optstring, remove_first="type")
+    if opts.get("type") == "none":
+        return None
+
+    if not dev:
+        dev = virtinst.VirtualTPMDevice(guest.conn, opts.get("type"))
+
+    set_param = _build_set_param(dev, opts)
+
+    set_param("model", "model")
+    set_param("type", "type")
+    set_param("path", "path")
+
+    if opts:
+        raise ValueError(_("Unknown options %s") % opts.keys())
+
+    return dev
+
 ######################
 # --watchdog parsing #
 ######################
-- 
1.8.1.4




More information about the virt-tools-list mailing list