[virt-manager PATCH 5/9] virtinst: use fail_conflicting

Pino Toscano ptoscano at redhat.com
Thu Sep 17 06:44:02 UTC 2020


Make use of the new helper for showing a standard error message for two
conflicting cli options. This also catches one untranslatable message.

Signed-off-by: Pino Toscano <ptoscano at redhat.com>
---
 tests/test_cli.py       | 4 ++--
 virtinst/virtinstall.py | 6 +++---
 virtinst/virtxml.py     | 4 ++--
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/tests/test_cli.py b/tests/test_cli.py
index ac07fea8..50b4a28b 100644
--- a/tests/test_cli.py
+++ b/tests/test_cli.py
@@ -884,7 +884,7 @@ c.add_invalid("--hvm --boot kernel=%(TREEDIR)s/pxeboot/vmlinuz,initrd=%(TREEDIR)
 c.add_invalid("--disk none --location kernel=/dev/null,initrd=/dev/null")  # --location with manual kernel/initrd, but not URL
 c.add_invalid("--install winxp", grep="does not have a URL location")  # no URL for winxp
 c.add_invalid("--arch i686 --install fedora26", grep="does not have a URL location for the architecture 'i686")  # there's no URL for i686
-c.add_invalid("-c foo --cdrom bar", grep="Cannot specify both -c")  # check for ambiguous -c and --cdrom collision
+c.add_invalid("-c foo --cdrom bar", grep="Cannot use -c")  # check for ambiguous -c and --cdrom collision
 c.add_invalid("-c qemu:///system", grep="looks like a libvirt URI")  # error for the ambiguous -c vs --connect
 c.add_invalid("--location /", grep="Error validating install location")  # detect_distro failure
 c.add_invalid("--os-variant id=foo://bar", grep="Unknown libosinfo ID")  # bad full id
@@ -1182,7 +1182,7 @@ c.add_invalid("test --os-variant fedora26 --edit --cpu host-passthrough", grep="
 c.add_invalid("test-for-virtxml --os-variant fedora26 --remove-device --disk 1", grep="--os-variant is not supported")
 c.add_invalid("--build-xml --os-variant fedora26 --disk path=foo", grep="--os-variant is not supported")
 c.add_invalid("domain-idontexist --edit --cpu host-passthrough --start", grep="Could not find domain")
-c.add_invalid("test-state-shutoff --edit --update --boot menu=on --start", grep="Cannot mix --update")
+c.add_invalid("test-state-shutoff --edit --update --boot menu=on --start", grep="Cannot use --update")
 c.add_invalid("test --edit --update --events on_poweroff=destroy", grep="Don't know how to --update for --events")
 c.add_invalid("--edit --cpu host-passthrough --confirm", input_file=(_VIRTXMLDIR + "virtxml-stdin-edit.xml"), grep="Can't use --confirm with stdin")
 c.add_invalid("--edit --cpu host-passthrough --update", input_file=(_VIRTXMLDIR + "virtxml-stdin-edit.xml"), grep="Can't use --update with stdin")
diff --git a/virtinst/virtinstall.py b/virtinst/virtinstall.py
index 6f14ce4c..dacbb797 100644
--- a/virtinst/virtinstall.py
+++ b/virtinst/virtinstall.py
@@ -16,7 +16,7 @@ import libvirt
 
 import virtinst
 from . import cli
-from .cli import fail, print_stdout, print_stderr
+from .cli import fail, fail_conflicting, print_stdout, print_stderr
 from . import Network
 from .guest import Guest
 from .logger import log
@@ -52,7 +52,7 @@ def supports_pxe(guest):
 
 def check_cdrom_option_error(options):
     if options.cdrom_short and options.cdrom:
-        fail("Cannot specify both -c and --cdrom")
+        fail_conflicting("-c", "--cdrom")
 
     if options.cdrom_short:
         if "://" in options.cdrom_short:
@@ -176,7 +176,7 @@ def convert_old_networks(options):
     bridges = virtinst.xmlutil.listify(options.bridge)
 
     if bridges and networks:
-        fail(_("Cannot mix both --bridge and --network arguments"))
+        fail_conflicting("--bridge", "--network")
 
     if bridges:
         # Convert old --bridges to --networks
diff --git a/virtinst/virtxml.py b/virtinst/virtxml.py
index a4c1d942..dd79fee0 100644
--- a/virtinst/virtxml.py
+++ b/virtinst/virtxml.py
@@ -10,7 +10,7 @@ import sys
 import libvirt
 
 from . import cli
-from .cli import fail, print_stdout, print_stderr
+from .cli import fail, fail_conflicting, print_stdout, print_stderr
 from .devices import DeviceConsole
 from .guest import Guest
 from .logger import log
@@ -499,7 +499,7 @@ def main(conn=None):
     performed_update = False
     if options.update:
         if options.update and options.start:
-            fail(_("Cannot mix --update and --start"))
+            fail_conflicting("--update", "--start")
 
         if vm_is_running:
             devs, action = prepare_changes(active_xmlobj, options, parserclass)
-- 
2.26.2




More information about the virt-tools-list mailing list