diff --git a/tests/cli-test-xml/compare/virt-install-many-devices.xml b/tests/cli-test-xml/compare/virt-install-many-devices.xml index 713ae13a2..c0b81a8c4 100644 --- a/tests/cli-test-xml/compare/virt-install-many-devices.xml +++ b/tests/cli-test-xml/compare/virt-install-many-devices.xml @@ -67,7 +67,12 @@ - + + + + + + diff --git a/tests/cli-test-xml/compare/virt-xml-edit-select-disk-path.xml b/tests/cli-test-xml/compare/virt-xml-edit-select-disk-path.xml index b656649c8..e6e7a3b57 100644 --- a/tests/cli-test-xml/compare/virt-xml-edit-select-disk-path.xml +++ b/tests/cli-test-xml/compare/virt-xml-edit-select-disk-path.xml @@ -1,5 +1,5 @@ - - + + - diff --git a/tests/cli-test-xml/compare/virt-xml-remove-disk-index.xml b/tests/cli-test-xml/compare/virt-xml-remove-disk-index.xml index 48b786544..fb7a25084 100644 --- a/tests/cli-test-xml/compare/virt-xml-remove-disk-index.xml +++ b/tests/cli-test-xml/compare/virt-xml-remove-disk-index.xml @@ -4,7 +4,9 @@ - - - -- +- +- +- - - - diff --git a/tests/clitest.py b/tests/clitest.py index 9f2d88b7a..d2cfb409a 100644 --- a/tests/clitest.py +++ b/tests/clitest.py @@ -454,7 +454,7 @@ c.add_compare(""" \ --disk device=cdrom,bus=sata,read_bytes_sec=1,read_iops_sec=2,total_bytes_sec=10,total_iops_sec=20,write_bytes_sec=5,write_iops_sec=6 \ --disk size=1 \ --disk %(BLOCKVOL)s \ ---disk /dev/default-pool/iso-vol \ +--disk /dev/default-pool/iso-vol,seclabel.model=dac,seclabel1.model=selinux,seclabel1.relabel=no,seclabel0.label=foo,bar,baz \ --disk /dev/default-pool/iso-vol,format=qcow2 \ --disk source_pool=rbd-ceph,source_volume=some-rbd-vol,size=.1 \ --disk pool=rbd-ceph,size=.1 \ @@ -861,6 +861,8 @@ c.add_compare("--host-device 0x0781:0x5151,driver_name=vfio", "edit-simple-host- c = vixml.add_category("edit selection", "test-for-virtxml --print-diff --define", compare_check="1.2.2") # compare_check=input type=keyboard output c.add_invalid("--edit target=vvv --disk /dev/null") # no match found +c.add_invalid("--edit seclabel2.model=dac --disk /dev/null") # no match found +c.add_valid("--edit seclabel.model=dac --disk /dev/null") # match found c.add_compare("--edit 3 --sound pcspk", "edit-pos-num", compare_check="1.3.5") # compare_check=new graphics listen output c.add_compare("--edit -1 --video qxl", "edit-neg-num", compare_check="1.2.11") # compare_check=video ram output change c.add_compare("--edit all --host-device driver_name=vfio", "edit-all") diff --git a/tests/testdriver.xml b/tests/testdriver.xml index ed07cd435..7f12c037a 100644 --- a/tests/testdriver.xml +++ b/tests/testdriver.xml @@ -141,7 +141,9 @@ - + + +
diff --git a/virtinst/cli.py b/virtinst/cli.py index ccaa06c1e..810742a43 100644 --- a/virtinst/cli.py +++ b/virtinst/cli.py @@ -24,6 +24,7 @@ import collections import logging import logging.handlers import os +import re import shlex import subprocess import sys @@ -809,6 +810,7 @@ class _VirtCLIArgument(object): is_onoff = False lookup_cb = None is_novalue = False + find_inst_cb = None @staticmethod def make_arg(attrname, cliname, **kwargs): @@ -836,7 +838,7 @@ class _VirtCLIArgument(object): checks if we are the parser for 'bar' """ for argname in [cls.cliname] + util.listify(cls.aliases): - if argname == cliname: + if re.match("^%s$" % argname, cliname): return True return False @@ -872,6 +874,10 @@ class _VirtCLIArgument(object): if self.val == "default" and self.ignore_default: return + if self.find_inst_cb: + inst = self.find_inst_cb(parser, # pylint: disable=not-callable + inst, self.val, self, True) + try: if self.attrname: eval("inst." + self.attrname) # pylint: disable=eval-used @@ -902,6 +908,12 @@ class _VirtCLIArgument(object): {"device_type": getattr(inst, "virtual_device_type", ""), "property_name": self.key}) + if self.find_inst_cb: + inst = self.find_inst_cb(parser, # pylint: disable=not-callable + inst, self.val, self, False) + if not inst: + return False + if self.lookup_cb: return self.lookup_cb(parser, # pylint: disable=not-callable inst, self.val, self) @@ -1178,11 +1190,11 @@ class VirtCLIParser(object): try: for inst in objlist: optdict = self.optdict.copy() - valid = False + valid = True for param in self._optdict_to_param_list(optdict): paramret = param.lookup_param(self, inst) - if paramret is True: - valid = True + if paramret is False: + valid = False break if valid: ret.append(inst) @@ -1727,6 +1739,22 @@ class ParserDisk(VirtCLIParser): def noset_cb(self, inst, val, virtarg): ignore = self, inst, val, virtarg + def seclabel_find_inst_cb(self, inst, val, virtarg, can_edit): + disk = inst + num = 0 + if re.search("\d+", virtarg.key): + num = int(re.search("\d+", virtarg.key).group()) + + if can_edit: + while len(disk.seclabels) < (num + 1): + disk.add_seclabel() + try: + return disk.seclabels[num] + except IndexError: + if not can_edit: + return None + raise + def _parse(self, inst): if self.optstr == "none": return @@ -1863,6 +1891,14 @@ ParserDisk.add_arg("iotune_wis", "write_iops_sec") ParserDisk.add_arg("iotune_tis", "total_iops_sec") ParserDisk.add_arg("sgio", "sgio") +# VirtualDisk.seclabels properties +ParserDisk.add_arg("model", "seclabel[0-9]*.model", + find_inst_cb=ParserDisk.seclabel_find_inst_cb) +ParserDisk.add_arg("relabel", "seclabel[0-9]*.relabel", is_onoff=True, + find_inst_cb=ParserDisk.seclabel_find_inst_cb) +ParserDisk.add_arg("label", "seclabel[0-9]*.label", can_comma=True, + find_inst_cb=ParserDisk.seclabel_find_inst_cb) + ##################### # --network parsing # diff --git a/virtinst/devicedisk.py b/virtinst/devicedisk.py index 4b56795cc..cbcfd9453 100644 --- a/virtinst/devicedisk.py +++ b/virtinst/devicedisk.py @@ -753,6 +753,10 @@ class VirtualDisk(VirtualDevice): iotune_wis = XMLProperty("./iotune/write_iops_sec", is_int=True) seclabels = XMLChildProperty(_DiskSeclabel, relative_xpath="./source") + def add_seclabel(self): + obj = _DiskSeclabel(self.conn) + self.add_child(obj) + return obj #################################