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
This commit is contained in:
Cole Robinson 2018-06-04 14:30:26 -04:00
parent 4370fd7c6c
commit 39a7cbbad7
3 changed files with 1 additions and 56 deletions

View File

@ -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

View File

@ -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 <numatune> 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"]

View File

@ -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: