[node-patches] Change in ovirt-node[master]: ui: Catch UI execptions at App level

fabiand at fedoraproject.org fabiand at fedoraproject.org
Wed Feb 6 09:06:14 UTC 2013


Fabian Deutsch has uploaded a new change for review.

Change subject: ui: Catch UI execptions at App level
......................................................................

ui: Catch UI execptions at App level

Previously the stacktrace was printed in the case of an exception. Now
an exception, occuring in the UI, will be catched, logged and printed on
the screen.

Change-Id: Ie52115e19881686b33ecc925ccbc61924fd386f1
Signed-off-by: Fabian Deutsch <fabiand at fedoraproject.org>
---
M scripts/tui/src/ovirt/node/app.py
M scripts/tui/src/ovirt/node/config/defaults.py
M scripts/tui/src/ovirt/node/exceptions.py
M scripts/tui/src/ovirt/node/installer/installation_device_page.py
M scripts/tui/src/ovirt/node/utils/network.py
5 files changed, 54 insertions(+), 16 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/89/11789/1

diff --git a/scripts/tui/src/ovirt/node/app.py b/scripts/tui/src/ovirt/node/app.py
index 30fa39d..b3e74f2 100644
--- a/scripts/tui/src/ovirt/node/app.py
+++ b/scripts/tui/src/ovirt/node/app.py
@@ -18,13 +18,6 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 # MA  02110-1301, USA.  A copy of the GNU General Public License is
 # also available at http://www.gnu.org/copyleft/gpl.html.
-
-"""
-Representing the whole application (not just the TUI).
-Basically the application consists of two parts: Page-Plugins and the UI
-which communicate with each other.
-"""
-
 from ovirt.node import base, utils, plugins, ui
 from ovirt.node.config import defaults
 from ovirt.node.ui import urwid_builder
@@ -32,6 +25,14 @@
 import argparse
 import logging
 import logging.config
+import sys
+
+"""
+Representing the whole application (not just the TUI).
+Basically the application consists of two parts: Page-Plugins and the UI
+which communicate with each other.
+"""
+
 
 LOGGING = {
     'version': 1,
@@ -60,10 +61,15 @@
             'filename': '/tmp/ovirt.debug.log',
             'mode': 'w'
         },
+        'stderr': {
+            'level': 'ERROR',
+            'class': 'logging.StreamHandler',
+            'stream': sys.stderr
+        }
     },
     'loggers': {
         'ovirt': {
-            'handlers': ['debug'],
+            'handlers': ['debug', 'stderr'],
             'level': 'DEBUG',
         },
         'ovirt.node': {
@@ -280,12 +286,22 @@
 
         self.ui.header = "\n %s\n" % str(self.product)
         self.ui.footer = "Press esc to quit."
-        self.ui.run()
+
+        try:
+            self.ui.run()
+        except Exception as e:
+            self.logger.error("An error appeared in the UI: %s" % repr(e))
 
     def quit(self):
         self.logger.info("Quitting")
         self.ui.quit()
 
+    def notice(self, msg):
+        children = [ui.Label("app.notice.text", msg)]
+        dialog = ui.Dialog("app.notice", "Notice", children)
+        dialog.buttons = [ui.CloseButton("app.notice.close")]
+        #self.ui._notice(dialog)
+
     def _check_outstanding_changes(self):
         has_outstanding_changes = False
         if self.current_plugin():
diff --git a/scripts/tui/src/ovirt/node/config/defaults.py b/scripts/tui/src/ovirt/node/config/defaults.py
index 326f0a9..f2aa5dd 100644
--- a/scripts/tui/src/ovirt/node/config/defaults.py
+++ b/scripts/tui/src/ovirt/node/config/defaults.py
@@ -1197,7 +1197,25 @@
     def update(self, init, root_install, overcommit, root_size, efi_size,
                swap_size, logging_size, config_size, data_size):
         # FIXME no checking!
-        pass
+        return {"OVIRT_INIT": ",".join(init),
+                "OVIRT_ROOT_INSTALL": "y" if root_install else None,
+                "OVIRT_INSTALL": "1" if install else None}
+
+    def retrieve(self):
+        cfg = dict(NodeConfigFileSection.retrieve(self))
+        cfg.update({"init": cfg["init"].split(",") if cfg["init"] else [],
+                    "root_install": cfg["root_install"] == "y",
+                    "install": cfg["install"] == "1"})
+        return cfg
 
     def transaction(self):
         return None
+
+    def install_on(self, init):
+        """Convenience function which can be used to set the parameters which
+        are going to be picked up by the installer backend to install Node on
+        the given storage with the given othere params
+        """
+        self.update(init=init,
+                    install=True)
+
diff --git a/scripts/tui/src/ovirt/node/exceptions.py b/scripts/tui/src/ovirt/node/exceptions.py
index eae160d..d55f358 100644
--- a/scripts/tui/src/ovirt/node/exceptions.py
+++ b/scripts/tui/src/ovirt/node/exceptions.py
@@ -31,6 +31,9 @@
     def __str__(self):
         return repr(self.message)
 
+    def __repr__(self):
+        return "<%s %s>" % (self.__class__.__name__, repr(self.message))
+
 
 class InvalidData(ExceptionWithMessage):
     """E.g. if a string contains characters which are not allowed
diff --git a/scripts/tui/src/ovirt/node/installer/installation_device_page.py b/scripts/tui/src/ovirt/node/installer/installation_device_page.py
index edd3fec..e3216bf 100644
--- a/scripts/tui/src/ovirt/node/installer/installation_device_page.py
+++ b/scripts/tui/src/ovirt/node/installer/installation_device_page.py
@@ -40,7 +40,10 @@
         return self._model or {}
 
     def validators(self):
-        return {}
+        has_selection = lambda v: "At least one installation device" \
+            if not self.widgets["installation.device.current"].selection() \
+            else True
+        return {"installation.device.current": has_selection}
 
     def ui_content(self):
         page_title = "Please select the disk(s) to use for installation " \
diff --git a/scripts/tui/src/ovirt/node/utils/network.py b/scripts/tui/src/ovirt/node/utils/network.py
index fdadf54..9f80cb6 100644
--- a/scripts/tui/src/ovirt/node/utils/network.py
+++ b/scripts/tui/src/ovirt/node/utils/network.py
@@ -19,8 +19,6 @@
 # MA  02110-1301, USA.  A copy of the GNU General Public License is
 # also available at http://www.gnu.org/copyleft/gpl.html.
 from ovirt.node import base, utils, config
-from socket import inet_ntoa
-from struct import pack
 import glob
 import gudev
 import logging
@@ -29,6 +27,8 @@
 import ovirt.node.utils.fs
 import ovirt.node.utils.process as process
 import re
+import socket
+import struct
 
 """
 Some convenience functions related to networking
@@ -44,8 +44,6 @@
     # pylint: disable-msg=E0611
     from gi.repository import NetworkManager, NMClient  # @UnresolvedImport
     # pylint: enable-msg=E0611
-    import socket
-    import struct
     NetworkManager
     _nm_client = NMClient.Client.new()
 except Exception as e:
@@ -473,7 +471,7 @@
     """
     mask = int(str(mask))
     bits = 0xffffffff ^ (1 << 32 - mask) - 1
-    return inet_ntoa(pack('>I', bits))
+    return socket.inet_ntoa(struct.pack('>I', bits))
 
 
 class IPAddress(base.Base):


--
To view, visit http://gerrit.ovirt.org/11789
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie52115e19881686b33ecc925ccbc61924fd386f1
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-node
Gerrit-Branch: master
Gerrit-Owner: Fabian Deutsch <fabiand at fedoraproject.org>



More information about the node-patches mailing list