From 39a7cbbad750656a7d89694c3b0341a5ae98d346 Mon Sep 17 00:00:00 2001 From: Cole Robinson Date: Mon, 4 Jun 2018 14:30:26 -0400 Subject: [PATCH] domain.numatune: Drop cpuset validation This type of validation should really be done at the libvirt level, particularly for a non-mandatory feature like cpuset. Otherwise it's just more code for us to test which will rarely be hit by users --- tests/clitest.py | 3 --- virtinst/domain/numatune.py | 48 ------------------------------------- virtinst/guest.py | 6 +---- 3 files changed, 1 insertion(+), 56 deletions(-) diff --git a/tests/clitest.py b/tests/clitest.py index a62a9105..dc8c6a72 100644 --- a/tests/clitest.py +++ b/tests/clitest.py @@ -578,7 +578,6 @@ c.add_compare("--boot loader=/path/to/loader,loader_secure=yes", "boot-loader-se #################################################### c = vinst.add_category("cpuram", "--hvm --nographics --noautoconsole --nodisks --pxe") -c.add_valid("--vcpus 4 --cpuset=1,3-5,") # Cpuset with trailing comma c.add_valid("--connect %(URI-XEN)s --vcpus 4 --cpuset=auto") # cpuset=auto but xen doesn't support it c.add_valid("--ram 4000000") # Ram overcommit c.add_valid("--vcpus sockets=2,threads=2") # Topology only @@ -586,8 +585,6 @@ c.add_valid("--cpu somemodel") # Simple --cpu c.add_valid("--security label=foobar.label,relabel=yes") # --security implicit static c.add_valid("--security label=foobar.label,a1,z2,b3,type=static,relabel=no") # static with commas 1 c.add_valid("--security label=foobar.label,a1,z2,b3") # --security static with commas 2 -c.add_invalid("--vcpus 32 --cpuset=969-1000") # Bogus cpuset -c.add_invalid("--vcpus 32 --cpuset=autofoo") # Bogus cpuset c.add_invalid("--clock foo_tickpolicy=merge") # Unknown timer c.add_invalid("--security foobar") # Busted --security c.add_compare("--cpuset auto --vcpus 2", "cpuset-auto") # --cpuset=auto actually works diff --git a/virtinst/domain/numatune.py b/virtinst/domain/numatune.py index b76c5fcf..f8b4d401 100644 --- a/virtinst/domain/numatune.py +++ b/virtinst/domain/numatune.py @@ -5,61 +5,13 @@ # This work is licensed under the GNU GPLv2 or later. # See the COPYING file in the top-level directory. -import re - from ..xmlbuilder import XMLBuilder, XMLProperty -def get_phy_cpus(conn): - """ - Get number of physical CPUs. - """ - hostinfo = conn.getInfo() - pcpus = hostinfo[4] * hostinfo[5] * hostinfo[6] * hostinfo[7] - return pcpus - - class DomainNumatune(XMLBuilder): """ Class for generating XML """ - - @staticmethod - def validate_cpuset(conn, val): - if val is None or val == "": - return - - if not isinstance(val, str) or len(val) == 0: - raise ValueError(_("cpuset must be string")) - if re.match("^[0-9,\-^]*$", val) is None: - raise ValueError(_("cpuset can only contain numeric, ',', '^', or " - "'-' characters")) - - pcpus = get_phy_cpus(conn) - for c in val.split(','): - # Redundant commas - if not c: - continue - - if "-" in c: - (x, y) = c.split('-', 1) - x = int(x) - y = int(y) - if x > y: - raise ValueError(_("cpuset contains invalid format.")) - if x >= pcpus or y >= pcpus: - raise ValueError(_("cpuset's pCPU numbers must be less " - "than pCPUs.")) - else: - if c.startswith("^"): - c = c[1:] - c = int(c) - - if c >= pcpus: - raise ValueError(_("cpuset's pCPU numbers must be less " - "than pCPUs.")) - - XML_NAME = "numatune" _XML_PROP_ORDER = ["memory_mode", "memory_nodeset"] diff --git a/virtinst/guest.py b/virtinst/guest.py index dea897c6..5bdbc9ed 100644 --- a/virtinst/guest.py +++ b/virtinst/guest.py @@ -189,11 +189,7 @@ class Guest(XMLBuilder): default_cb=lambda s: 1) curvcpus = XMLProperty("./vcpu/@current", is_int=True) vcpu_placement = XMLProperty("./vcpu/@placement") - - def _validate_cpuset(self, val): - DomainNumatune.validate_cpuset(self.conn, val) - cpuset = XMLProperty("./vcpu/@cpuset", - validate_cb=_validate_cpuset) + cpuset = XMLProperty("./vcpu/@cpuset") def _get_default_uuid(self): if self._random_uuid is None: