[virt-tools-list] [virt-manager PATCH v2 21/25] osdict: Deal with media on get_install_script()

Fabiano Fidêncio fidencio at redhat.com
Tue Feb 26 09:43:52 UTC 2019


In case a media is passed to the get_install_script() method, let's:
- Check whether the media supports install scripts;
  - In case it doesn't, let's just raise a RuntimeError;
- Try to get the install-script from the media itself (instead of trying
  to get the install-script from the OS;
  - In case the script is found, return it;
  - Otherwise, fallback for checking the OS for install-scripts, as done
    before.

There's a small change needed in the _get_install_script() helper in
order to decide whether to raise a RuntimeError or just return None
depending on whether we're checking the media or the OS for the
install-scripts

Signed-off-by: Fabiano Fidêncio <fidencio at redhat.com>
---
 virtinst/osdict.py | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/virtinst/osdict.py b/virtinst/osdict.py
index 307559d2..255ccd35 100644
--- a/virtinst/osdict.py
+++ b/virtinst/osdict.py
@@ -512,8 +512,11 @@ class _OsVariant(object):
         return filtered_treelist.get_nth(0).get_url()
 
     def get_install_script(self, profile, media=None):
-        def _get_install_script(script_list):
+        def _get_install_script(script_list, from_media=False):
             if script_list.get_length == 0:
+                if from_media:
+                    return None
+
                 raise RuntimeError(
                     _("%s does not support unattended installation."),
                     self.name)
@@ -540,7 +543,15 @@ class _OsVariant(object):
             return None
 
         if media:
-            return None
+            if not media.supports_install_script():
+                raise RuntimeError(
+                        _("%s does not support unattended installation."),
+                        self.name)
+
+            script = _get_install_script(
+                    media.get_install_script_list(), from_media=True)
+            if script:
+                return script
 
         return _get_install_script(self._os.get_install_script_list())
 
-- 
2.20.1




More information about the virt-tools-list mailing list