cli: Call validate() on is_single objects too

The way the code was nested, we skipped calling validate() on
XMLChildProperty is_single objects. There's no reason to do that,
so adjust it.

We need to do some hasattr checking here, because --os-variant and
--location objects aren't XMLBuilders with validate defined. That's
really an issue of having XMLBuilder assumptions baked into the
generic CLI parsing infrastructure. Unwinding that is for another day
This commit is contained in:
Cole Robinson 2019-06-11 11:09:56 -04:00
parent 102a49771f
commit a80242d998

View File

@ -1432,15 +1432,15 @@ class VirtCLIParser(metaclass=_InitClass):
ret = [] ret = []
try: try:
objs = self._parse(inst is None and self.guest or inst) objs = self._parse(inst is None and self.guest or inst)
if new_object: for obj in xmlutil.listify(objs):
for obj in xmlutil.listify(objs): if validate and hasattr(obj, "validate"):
if validate: obj.validate()
obj.validate() if not new_object:
continue
if isinstance(obj, Device): if isinstance(obj, Device):
self.guest.add_device(obj) self.guest.add_device(obj)
else: else:
self.guest.add_child(obj) self.guest.add_child(obj)
ret += xmlutil.listify(objs) ret += xmlutil.listify(objs)
except Exception as e: except Exception as e: