components/openstack/nova/files/zone-vnc-console
changeset 4046 47a996abe340
parent 3998 5bd484384122
child 4049 150852e281c4
--- a/components/openstack/nova/files/zone-vnc-console	Tue Mar 31 13:48:00 2015 -0700
+++ b/components/openstack/nova/files/zone-vnc-console	Wed Apr 01 17:30:47 2015 -0700
@@ -32,6 +32,7 @@
 XRANDR = "/usr/bin/xrandr"
 XSTARTUPHDR = "# WARNING: THIS FILE GENERATED BY SMF.\n" + \
               "#   DO NOT EDIT THIS FILE.  EDITS WILL BE LOST.\n"
+XRESOURCES = "[[ -f ~/.Xresources ]] && /usr/bin/xrdb -merge ~/.Xresources\n"
 XTERM = "/usr/bin/xterm"
 # Borderless, Monospsce font, point size 14, white foreground on black
 # background are reasonable defaults.
@@ -40,7 +41,7 @@
 XWININFO = "/usr/bin/xwininfo"
 # Enclose command in comments to prevent xterm consuming zlogin opts
 ZLOGINOPTS = ' -e "/usr/bin/pfexec /usr/sbin/zlogin -C -E $ZONENAME"\n'
-XSTARTUP = XSTARTUPHDR + XTERM + XTERMOPTS + ZLOGINOPTS
+XSTARTUP = XSTARTUPHDR + XRESOURCES + XTERM + XTERMOPTS + ZLOGINOPTS
 
 
 def start():
@@ -162,13 +163,18 @@
         to match using XRANDR. Treat failure as non-fatal since an
         incorrectly sized console is arguably better than none.
     """
+    class UninitializedWindowError(Exception):
+        pass
+
     class UnmappedWindowError(Exception):
         pass
 
     def _get_window_geometry(display, windowname):
         """ Find the xterm xwindow by name/title and extract its geometry
             Returns: tuple of window [width, height]
-            Raises: UnmappedWindowError if window is not viewable/unmapped
+            Raises:
+                UninitializedWindowError if window not yet initialized
+                UnmappedWindowError if window is not viewable/mapped
         """
         cmd = [XWININFO, '-d', display, '-name', windowname]
         xwininfo = subprocess.Popen(cmd, stdout=subprocess.PIPE,
@@ -177,7 +183,7 @@
         retcode = xwininfo.wait()
         if retcode != 0:
             print "Error finding console xwindow info: " + err
-            return
+            raise UninitializedWindowError
 
         width = None
         height = None
@@ -201,23 +207,38 @@
             print "No window geometry info returned by " + XWINFINFO
             raise UnmappedWindowError
 
-    retries = 5
+    retries = 10
+    sleep = 1
+    uninit_count = 0
+    unmap_count = 0
     width = 0
     height = 0
-    for tries in range(retries):
+    while uninit_count < retries and unmap_count < retries:
         try:
             width, height = _get_window_geometry(display,
                                                  'Zone Console: ' + zonename)
             print "Discovered xterm geometry: %d x %d" % (width, height)
             break
+        except UninitializedWindowError:
+            if uninit_count < retries:
+                print "xterm window not initialized yet. Retrying in %ds" \
+                    % sleep
+                uninit_count += 1
+                time.sleep(sleep)
+                continue
+            else:
+                print "xterm window is taking too long to initialize"
+                break
         except UnmappedWindowError:
-            if tries < retries:
-                print "Discovered xterm not mapped yet. Retrying in 0.5s"
-                time.sleep(0.5)
+            if unmap_count < retries:
+                print "Discovered xterm not mapped yet. Retrying in %ds" \
+                    % sleep
+                unmap_count += 1
+                time.sleep(sleep)
                 continue
             else:
                 print "Discovered xterm window is taking too long to map"
-                return
+                break
     else:
         print "Too many failed attempts to discover xterm window geometry"
         return