[virt-tools-list] [virt-manager PATCH] Rename hide_unsupported_rhel_options to stable_defaults and clean-up its usage

Martin Kletzander mkletzan at redhat.com
Tue Jan 21 09:37:52 UTC 2014


There were multiple problems with the setting and usage of
hide_unsupported_rhel_options.  Due to the fact that the option has
several diferent namings throughout the code, this patch is renaming
it to stable_defaults, which basically says what the option does and
makes it possible to use it without need for more than one negation
(where the old code had up to 4 of them in some places), which also
helps understanding it.

Signed-off-by: Martin Kletzander <mkletzan at redhat.com>
---
 setup.py                     | 14 +++++++-------
 tests/__init__.py            |  4 ++--
 tests/xmlconfig.py           |  6 +++---
 virt-manager.spec.in         | 10 +++++-----
 virtManager/addhardware.py   | 13 ++++++-------
 virtManager/choosecd.py      |  5 ++---
 virtManager/config.py        |  4 ++--
 virtManager/connection.py    | 25 ++++++++++++-------------
 virtManager/create.py        | 18 +++++++++---------
 virtManager/createvol.py     |  8 ++++----
 virtManager/details.py       |  4 ++--
 virtManager/domain.py        |  6 +++---
 virtManager/storagebrowse.py |  7 ++++---
 virtManager/uihelpers.py     | 12 ++++++------
 virtcli/cliconfig.py         |  5 ++---
 virtinst/__init__.py         |  4 ++--
 16 files changed, 71 insertions(+), 74 deletions(-)

diff --git a/setup.py b/setup.py
index fa4065e..6103f93 100755
--- a/setup.py
+++ b/setup.py
@@ -1,5 +1,5 @@
 #!/usr/bin/env python
-# Copyright (C) 2013 Red Hat, Inc.
+# Copyright (C) 2013, 2014 Red Hat, Inc.

 # pylint: disable=W0201
 # Attribute defined outside __init__: custom commands require breaking this
@@ -320,8 +320,8 @@ class configure(Command):
          "name of your distro's askpass package(s) (default=none)"),
         ("preferred-distros=", None,
          "Distros to list first in the New VM wizard (default=none)"),
-        ("hide-unsupported-rhel-options", None,
-         "Hide config bits that are not supported on RHEL (default=no)"),
+        ("stable-defaults", None,
+         "Hide config bits that are not considered stable (default=no)"),
         ("default-graphics=", None,
          "Default graphics type (spice or vnc) (default=spice)"),

@@ -339,7 +339,7 @@ class configure(Command):
         self.kvm_package_names = None
         self.askpass_package_names = None
         self.preferred_distros = None
-        self.hide_unsupported_rhel_options = None
+        self.stable_defaults = None
         self.default_graphics = None


@@ -359,9 +359,9 @@ class configure(Command):
             template += "askpass_packages = %s\n" % self.askpass_package_names
         if self.preferred_distros is not None:
             template += "preferred_distros = %s\n" % self.preferred_distros
-        if self.hide_unsupported_rhel_options is not None:
-            template += ("hide_unsupported_rhel_options = %s\n" %
-                         self.hide_unsupported_rhel_options)
+        if self.stable_defaults is not None:
+            template += ("stable_defaults = %s\n" %
+                         self.stable_defaults)
         if self.default_graphics is not None:
             template += "default_graphics = %s\n" % self.default_graphics

diff --git a/tests/__init__.py b/tests/__init__.py
index ea3c8c3..4ab1002 100644
--- a/tests/__init__.py
+++ b/tests/__init__.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2013 Red Hat, Inc.
+# Copyright (C) 2013, 2014 Red Hat, Inc.
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -24,7 +24,7 @@ os.environ["VIRTINST_TEST_TRACKPROPS"] = "1"
 os.environ["VIRTINST_TEST_SUITE"] = "1"

 import virtinst
-virtinst.enable_rhel_defaults = False
+virtinst.stable_defaults = False

 from virtcli import cliconfig
 # This sets all the cli bits back to their defaults
diff --git a/tests/xmlconfig.py b/tests/xmlconfig.py
index 98ac0c6..ab9b596 100644
--- a/tests/xmlconfig.py
+++ b/tests/xmlconfig.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2013 Red Hat, Inc.
+# Copyright (C) 2013, 2014 Red Hat, Inc.
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -325,7 +325,7 @@ class TestXMLConfig(unittest.TestCase):
         self._compare(g, "install-f11-norheldefaults", do_install)

         try:
-            virtinst.enable_rhel_defaults = True
+            virtinst.stable_defaults = True
             origemu = g.emulator
             g.emulator = "/usr/libexec/qemu-kvm"
             g.conn._support_cache = {}
@@ -333,7 +333,7 @@ class TestXMLConfig(unittest.TestCase):
             g.emulator = origemu
             g.conn._support_cache = {}
         finally:
-            virtinst.enable_rhel_defaults = False
+            virtinst.stable_defaults = False

         # Verify main guest wasn't polluted
         self._compare(g, "install-f11-norheldefaults", do_install)
diff --git a/virt-manager.spec.in b/virt-manager.spec.in
index 839a26a..45a3af8 100644
--- a/virt-manager.spec.in
+++ b/virt-manager.spec.in
@@ -2,7 +2,7 @@


 %define with_guestfs               0
-%define disable_unsupported_rhel   0
+%define stable_defaults            0
 %define askpass_package            "openssh-askpass"
 %define qemu_user                  "qemu"
 %define libvirt_packages           "libvirt-daemon-kvm,libvirt-daemon-config-network"
@@ -12,7 +12,7 @@
 %if 0%{?rhel}
 %define preferred_distros          "rhel,fedora"
 %define kvm_packages               "qemu-kvm"
-%define disable_unsupported_rhel   1
+%define stable_defaults            1
 %endif


@@ -125,8 +125,8 @@ machine).
 %define _askpass_package --askpass-package-names=%{askpass_package}
 %endif

-%if %{disable_unsupported_rhel}
-%define _disable_unsupported_rhel --hide-unsupported-rhel-options
+%if %{stable_defaults}
+%define _stable_defaults --stable-defaults
 %endif

 python setup.py configure \
@@ -136,7 +136,7 @@ python setup.py configure \
     %{?_libvirt_packages} \
     %{?_askpass_package} \
     %{?_preferred_distros} \
-    %{?_disable_unsupported_rhel}
+    %{?_stable_defaults}


 %install
diff --git a/virtManager/addhardware.py b/virtManager/addhardware.py
index d7ee161..183b875 100644
--- a/virtManager/addhardware.py
+++ b/virtManager/addhardware.py
@@ -1,5 +1,5 @@
 #
-# Copyright (C) 2006-2007, 2013 Red Hat, Inc.
+# Copyright (C) 2006-2007, 2013, 2014 Red Hat, Inc.
 # Copyright (C) 2006 Hugh O. Brock <hbrock at redhat.com>
 #
 # This program is free software; you can redistribute it and/or modify
@@ -546,7 +546,7 @@ class vmmAddHardware(vmmGObjectUI):
             model.append(["ide", "IDE"])
             model.append(["fdc", "Floppy"])

-            if self.vm.rhel6_defaults():
+            if self.vm.stable_defaults():
                 model.append(["scsi", "SCSI"])
                 model.append(["usb", "USB"])

@@ -1000,7 +1000,7 @@ class vmmAddHardware(vmmGObjectUI):
         return uihelpers.get_list_selection(self.widget("hw-list"))

     def update_char_device_type_model(self):
-        rhel6_blacklist = ["pipe", "udp"]
+        stable_blacklist = ["pipe", "udp"]

         # Char device type
         char_devtype = self.widget("char-device-type")
@@ -1010,8 +1010,8 @@ class vmmAddHardware(vmmGObjectUI):

         # Type name, desc
         for t in char_class.TYPES:
-            if (t in rhel6_blacklist and
-                not self.vm.rhel6_defaults()):
+            if (t in stable_blacklist and
+                self.vm.stable_defaults()):
                 continue

             desc = char_class.pretty_type(t)
@@ -1906,8 +1906,7 @@ class vmmAddHardware(vmmGObjectUI):
         if self.storage_browser is None:
             self.storage_browser = vmmStorageBrowser(conn)

-        rhel6 = self.vm.rhel6_defaults()
-        self.storage_browser.rhel6_defaults = rhel6
+        self.storage_browser.stable_defaults = self.vm.stable_defaults()

         self.storage_browser.set_finish_cb(set_storage_cb)
         self.storage_browser.set_browse_reason(reason)
diff --git a/virtManager/choosecd.py b/virtManager/choosecd.py
index 76640dd..1d46879 100644
--- a/virtManager/choosecd.py
+++ b/virtManager/choosecd.py
@@ -1,5 +1,5 @@
 #
-# Copyright (C) 2006, 2013 Red Hat, Inc.
+# Copyright (C) 2006, 2013, 2014 Red Hat, Inc.
 # Copyright (C) 2006 Hugh O. Brock <hbrock at redhat.com>
 #
 # This program is free software; you can redistribute it and/or modify
@@ -173,8 +173,7 @@ class vmmChooseCD(vmmGObjectUI):
             self.storage_browser.connect("storage-browse-finish",
                                          self.set_storage_path)

-        rhel6 = self.vm.rhel6_defaults()
-        self.storage_browser.rhel6_defaults = rhel6
+        self.storage_browser.stable_defaults = self.vm.stable_defaults()

         if self.media_type == MEDIA_FLOPPY:
             self.storage_browser.set_browse_reason(
diff --git a/virtManager/config.py b/virtManager/config.py
index a92e240..c2d5e36 100644
--- a/virtManager/config.py
+++ b/virtManager/config.py
@@ -1,5 +1,5 @@
 #
-# Copyright (C) 2006, 2012-2013 Red Hat, Inc.
+# Copyright (C) 2006, 2012-2014 Red Hat, Inc.
 # Copyright (C) 2006 Daniel P. Berrange <berrange at redhat.com>
 #
 # This program is free software; you can redistribute it and/or modify
@@ -160,7 +160,7 @@ class vmmConfig(object):
         self.keyring = None

         self.default_qemu_user = cliconfig.default_qemu_user
-        self.rhel6_defaults = not cliconfig.rhel_enable_unsupported_opts
+        self.stable_defaults = cliconfig.stable_defaults
         self.preferred_distros = cliconfig.preferred_distros
         self.hv_packages = cliconfig.hv_packages
         self.libvirt_packages = cliconfig.libvirt_packages
diff --git a/virtManager/connection.py b/virtManager/connection.py
index b165f57..4ef2241 100644
--- a/virtManager/connection.py
+++ b/virtManager/connection.py
@@ -1,5 +1,5 @@
 #
-# Copyright (C) 2006, 2013 Red Hat, Inc.
+# Copyright (C) 2006, 2013, 2014 Red Hat, Inc.
 # Copyright (C) 2006 Daniel P. Berrange <berrange at redhat.com>
 #
 # This program is free software; you can redistribute it and/or modify
@@ -307,19 +307,18 @@ class vmmConnection(vmmGObject):


     # Connection capabilities debug helpers
-    def rhel6_defaults(self, emulator):
+    def stable_defaults(self, emulator=None):
         if not self.is_qemu_system():
-            return True
-        if not str(emulator).startswith("/usr/libexec"):
-            return True
-        return self.config.rhel6_defaults
-
-    def rhel6_defaults_caps(self):
-        for guest in self.caps.guests:
-            for dom in guest.domains:
-                if dom.emulator.startswith("/usr/libexec"):
-                    return self.config.rhel6_defaults
-        return True
+            return False
+        if emulator:
+            if not str(emulator).startswith("/usr/libexec"):
+                return False
+        else:
+            for guest in self.caps.guests:
+                for dom in guest.domains:
+                    if dom.emulator.startswith("/usr/libexec"):
+                        return self.config.stable_defaults
+        return self.config.stable_defaults

     def get_cache_dir(self):
         uri = self.get_uri().replace("/", "_")
diff --git a/virtManager/create.py b/virtManager/create.py
index 87d5f0c..8c4197f 100644
--- a/virtManager/create.py
+++ b/virtManager/create.py
@@ -1,5 +1,5 @@
 #
-# Copyright (C) 2008, 2013 Red Hat, Inc.
+# Copyright (C) 2008, 2013, 2014 Red Hat, Inc.
 # Copyright (C) 2008 Cole Robinson <crobinso at redhat.com>
 #
 # This program is free software; you can redistribute it and/or modify
@@ -57,7 +57,7 @@ INSTALL_PAGE_IMPORT = 3
 INSTALL_PAGE_CONTAINER_APP = 4
 INSTALL_PAGE_CONTAINER_OS = 5

-RHEL6_OS_SUPPORT = [
+STABLE_OS_SUPPORT = [
     "rhel3", "rhel4", "rhel5.4", "rhel6",
     "win2k3", "winxp", "win2k8", "vista", "win7",
 ]
@@ -841,8 +841,8 @@ class vmmCreate(vmmGObjectUI):
         widget = self.widget("install-os-type")
         model = widget.get_model()
         model.clear()
-        filtervars = (not self._rhel6_defaults() and
-                      RHEL6_OS_SUPPORT or
+        filtervars = (self._stable_defaults() and
+                      STABLE_OS_SUPPORT or
                       None)

         types = virtinst.osdict.list_os(list_types=True)
@@ -879,8 +879,8 @@ class vmmCreate(vmmGObjectUI):
             self._add_os_row(model, None, _("Generic"), True)
             return

-        filtervars = (not self._rhel6_defaults() and
-                      RHEL6_OS_SUPPORT or
+        filtervars = (not self._stable_defaults() and
+                      STABLE_OS_SUPPORT or
                       None)
         preferred = self.config.preferred_distros

@@ -2178,14 +2178,14 @@ class vmmCreate(vmmGObjectUI):
             logging.exception("Error detecting distro.")
             self.detectedDistro = -1

-    def _rhel6_defaults(self):
+    def _stable_defaults(self):
         emu = None
         if self.guest:
             emu = self.guest.emulator
         elif self.capsdomain:
             emu = self.capsdomain.emulator

-        ret = self.conn.rhel6_defaults(emu)
+        ret = self.conn.stable_defaults(emu)
         return ret

     def _browse_file(self, cbwidget, cb=None, is_media=False, is_dir=False):
@@ -2205,7 +2205,7 @@ class vmmCreate(vmmGObjectUI):
         if self.storage_browser is None:
             self.storage_browser = vmmStorageBrowser(self.conn)

-        self.storage_browser.rhel6_defaults = self._rhel6_defaults()
+        self.storage_browser.stable_defaults = self._stable_defaults()

         self.storage_browser.set_vm_name(self.get_config_name())
         self.storage_browser.set_finish_cb(callback)
diff --git a/virtManager/createvol.py b/virtManager/createvol.py
index 8b0ad87..ad8f98c 100644
--- a/virtManager/createvol.py
+++ b/virtManager/createvol.py
@@ -1,5 +1,5 @@
 #
-# Copyright (C) 2008, 2013 Red Hat, Inc.
+# Copyright (C) 2008, 2013, 2014 Red Hat, Inc.
 # Copyright (C) 2008 Cole Robinson <crobinso at redhat.com>
 #
 # This program is free software; you can redistribute it and/or modify
@@ -212,7 +212,7 @@ class vmmCreateVolume(vmmGObjectUI):
         return None

     def populate_vol_format(self):
-        rhel6_file_whitelist = ["raw", "qcow2", "qed"]
+        stable_whitelist = ["raw", "qcow2", "qed"]
         model = self.widget("vol-format").get_model()
         model.clear()

@@ -221,9 +221,9 @@ class vmmCreateVolume(vmmGObjectUI):
             formats = self.vol.list_create_formats()

         if (self.vol.file_type == self.vol.TYPE_FILE and
-            not self.conn.rhel6_defaults_caps()):
+            self.conn.stable_defaults()):
             newfmts = []
-            for f in rhel6_file_whitelist:
+            for f in stable_whitelist:
                 if f in formats:
                     newfmts.append(f)
             formats = newfmts
diff --git a/virtManager/details.py b/virtManager/details.py
index 32d51d7..c64ed92 100644
--- a/virtManager/details.py
+++ b/virtManager/details.py
@@ -3423,12 +3423,12 @@ class vmmDetails(vmmGObjectUI):
             buses.append(["fdc", "Floppy"])
         elif devtype == virtinst.VirtualDisk.DEVICE_CDROM:
             buses.append(["ide", "IDE"])
-            if self.vm.rhel6_defaults():
+            if not self.vm.stable_defaults():
                 buses.append(["scsi", "SCSI"])
         else:
             if self.vm.is_hvm():
                 buses.append(["ide", "IDE"])
-                if self.vm.rhel6_defaults():
+                if not self.vm.stable_defaults():
                     buses.append(["scsi", "SCSI"])
                     buses.append(["usb", "USB"])
             if self.vm.get_hv_type() in ["kvm", "test"]:
diff --git a/virtManager/domain.py b/virtManager/domain.py
index ada404b..2660868 100644
--- a/virtManager/domain.py
+++ b/virtManager/domain.py
@@ -1,5 +1,5 @@
 #
-# Copyright (C) 2006, 2013 Red Hat, Inc.
+# Copyright (C) 2006, 2013, 2014 Red Hat, Inc.
 # Copyright (C) 2006 Daniel P. Berrange <berrange at redhat.com>
 #
 # This program is free software; you can redistribute it and/or modify
@@ -371,8 +371,8 @@ class vmmDomain(vmmLibvirtObject):
     def get_install_abort(self):
         return bool(self._install_abort)

-    def rhel6_defaults(self):
-        return self.conn.rhel6_defaults(self.get_emulator())
+    def stable_defaults(self):
+        return self.conn.stable_defaults(self.get_emulator())

     def is_read_only(self):
         if self.is_management_domain():
diff --git a/virtManager/storagebrowse.py b/virtManager/storagebrowse.py
index b4f93c1..dfee93f 100644
--- a/virtManager/storagebrowse.py
+++ b/virtManager/storagebrowse.py
@@ -1,5 +1,5 @@
 #
-# Copyright (C) 2009, 2013 Red Hat, Inc.
+# Copyright (C) 2009, 2013, 2014 Red Hat, Inc.
 # Copyright (C) 2009 Cole Robinson <crobinso at redhat.com>
 #
 # This program is free software; you can redistribute it and/or modify
@@ -54,9 +54,10 @@ class vmmStorageBrowser(vmmGObjectUI):

         # Arguments to pass to util.browse_local for local storage
         self.browse_reason = None
-        self.rhel6_defaults = True
         self.local_args = {}

+        self.stable_defaults = False
+
         self.builder.connect_signals({
             "on_vmm_storage_browse_delete_event" : self.close,
             "on_browse_cancel_clicked" : self.close,
@@ -332,7 +333,7 @@ class vmmStorageBrowser(vmmGObjectUI):
             if ((self.browse_reason == self.config.CONFIG_DIR_FS)
                 and fmt != 'dir'):
                 return False
-            elif not self.rhel6_defaults:
+            elif self.stable_defaults:
                 if fmt == "vmdk":
                     return False
             return True
diff --git a/virtManager/uihelpers.py b/virtManager/uihelpers.py
index 4238790..a50747d 100644
--- a/virtManager/uihelpers.py
+++ b/virtManager/uihelpers.py
@@ -1,5 +1,5 @@
 #
-# Copyright (C) 2009, 2013 Red Hat, Inc.
+# Copyright (C) 2009, 2013, 2014 Red Hat, Inc.
 # Copyright (C) 2009 Cole Robinson <crobinso at redhat.com>
 #
 # This program is free software; you can redistribute it and/or modify
@@ -162,7 +162,7 @@ def populate_video_combo(vm, combo, no_default=None):
     model.clear()
     tmpdev = virtinst.VirtualVideoDevice(vm.conn.get_backend())
     for m in tmpdev.MODELS:
-        if not vm.rhel6_defaults():
+        if vm.stable_defaults():
             if m == "qxl" and not has_spice and not has_qxl:
                 # Only list QXL video option when VM has SPICE video
                 continue
@@ -181,14 +181,14 @@ def build_sound_combo(vm, combo, no_default=False):
     set_combo_text_column(combo, 0)
     model.set_sort_column_id(0, Gtk.SortType.ASCENDING)

-    disable_rhel = not vm.rhel6_defaults()
-    rhel_soundmodels = ["ich6", "ac97"]
+    stable_defaults = vm.stable_defaults()
+    stable_soundmodels = ["ich6", "ac97"]

     for m in virtinst.VirtualAudio.MODELS:
         if m == virtinst.VirtualAudio.MODEL_DEFAULT and no_default:
             continue

-        if (disable_rhel and m not in rhel_soundmodels):
+        if (stable_defaults and m not in stable_soundmodels):
             continue

         model.append([m])
@@ -426,7 +426,7 @@ def update_storage_format_combo(vm, combo, create):

     formats = ["raw", "qcow2", "qed"]
     no_create_formats = []
-    if vm.rhel6_defaults():
+    if not vm.stable_defaults():
         formats.append("vmdk")
         no_create_formats.append("vdi")

diff --git a/virtcli/cliconfig.py b/virtcli/cliconfig.py
index 3011543..ade99f6 100644
--- a/virtcli/cliconfig.py
+++ b/virtcli/cliconfig.py
@@ -1,5 +1,5 @@
 #
-# Copyright (C) 2013 Red Hat, Inc.
+# Copyright (C) 2013, 2014 Red Hat, Inc.
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -81,8 +81,7 @@ else:
     icon_dir = os.path.join(asset_dir, "icons")

 default_qemu_user = _get_param("default_qemu_user", "root")
-rhel_enable_unsupported_opts = not bool(int(
-    _get_param("hide_unsupported_rhel_options", "0")))
+stable_defaults = bool(int(_get_param("stable_defaults", "0")))

 preferred_distros = _split_list(_get_param("preferred_distros", ""))
 hv_packages = _split_list(_get_param("hv_packages", ""))
diff --git a/virtinst/__init__.py b/virtinst/__init__.py
index 925af4c..a6a905f 100644
--- a/virtinst/__init__.py
+++ b/virtinst/__init__.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2013 Red Hat, Inc.
+# Copyright (C) 2013, 2014 Red Hat, Inc.
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -16,7 +16,7 @@
 # MA 02110-1301 USA.

 from virtcli import cliconfig, cliutils
-enable_rhel_defaults = not cliconfig.rhel_enable_unsupported_opts
+stable_defaults = cliconfig.stable_defaults
 cliutils.setup_i18n()


-- 
1.8.5.3




More information about the virt-tools-list mailing list