virt-xml: Warn if libvirt discards our defined changes

This can happen if we try to remove a default device, like
 a ps2 mouse on x86, but it can happen for many other reasons as well

https://bugzilla.redhat.com/show_bug.cgi?id=1405263
This commit is contained in:
Cole Robinson 2019-06-16 17:01:32 -04:00
parent f7854d0a84
commit 53f075ab76
2 changed files with 11 additions and 0 deletions

View File

@ -1086,6 +1086,7 @@ c = vixml.add_category("misc", "")
c.add_valid("--help") # basic --help test
c.add_valid("--sound=? --tpm=?") # basic introspection test
c.add_valid("test-state-shutoff --edit --update --boot menu=on", grep="The VM is not running") # --update with inactive VM, should work but warn
c.add_valid("test-state-shutoff --edit --boot menu=on", grep="XML did not change after domain define") # menu=on is discarded because <bootloader> is specified
c.add_valid("test-for-virtxml --edit --graphics password=foo --update --confirm", input_text="no\nno\n") # prompt exiting
c.add_valid("test-for-virtxml --edit --cpu host-passthrough --no-define --start --confirm", input_text="no") # transient prompt exiting
c.add_valid("test-for-virtxml --edit --metadata name=test-for-virtxml", grep="requested changes will have no effect")

View File

@ -103,6 +103,12 @@ def get_domain_and_guest(conn, domstr):
return (domain, inactive_xmlobj, active_xmlobj)
def defined_xml_is_unchanged(conn, domain, original_xml):
rawxml = get_xmldesc(domain, inactive=True)
new_xml = virtinst.Guest(conn, parsexml=rawxml)
return new_xml != original_xml
################
# Change logic #
################
@ -522,6 +528,7 @@ def main(conn=None):
# It's hard to hit this case with the test suite
return 0 # pragma: no cover
original_xml = inactive_xmlobj.get_xml()
devs, action = prepare_changes(inactive_xmlobj, options, parserclass)
if not options.define:
if options.start:
@ -547,6 +554,9 @@ def main(conn=None):
elif vm_is_running and not performed_update:
print_stdout(
_("Changes will take effect after the domain is fully powered off."))
elif defined_xml_is_unchanged(conn, domain, original_xml):
logging.warning(_("XML did not change after domain define. You may "
"have changed a value that libvirt is setting by default."))
return 0