[PATCH] workarounds and fixes for new gtk-vnc integration in console.py

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, 31 Aug 2007, Bernhard Kaindl wrote:

Note: The message which was displayed when the gtk-vnc widget got the
ECONNREFUSED (Connection refused) error when connecting to <hostname>:5900
sounds a bit misleading to me.

socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 4
connect(4, {sa_family=AF_INET, sin_port=htons(5900), sin_addr=inet_addr("<my host's LAN IP address here>")}, 16) = -1 ECONNREFUSED (Connection refused)

The message resulting from this was:

"Console was disconnected from guest"

Another message like this still apppeared when starting a new QEMU / KVM guest
from virt-manager, and the changes which I did in that regard to fix this
are found in the cumulated patch below.

I added some comments, so I also attached it as a MIME attachment:

--- virt-manager--devel/src/virtManager/console.py	2007/08/30 23:11:35	1.1
+++ virt-manager--devel/src/virtManager/console.py	2007/08/31 00:53:58
@@ -74,8 +74,9 @@
         self.window.get_widget("console-pages").append_page(self.vncViewer)
         self.vncViewer.realize()
         self.vncViewer.show()
-        self.vncViewerFailures = 0
+        self.vncViewerRetriesScheduled = 0
# Simple rename to be more exact to what I'm using it now.
         self.vncViewerRetryDelay = 125
+        self.connected = 0
# New: to keep track if connected or not (stop retries when connected)

         self.notifyID = None
         try:
@@ -231,44 +232,61 @@
            return 1
         return 0

+    def view_vm_status(self):
+        status = self.vm.status()
+        if status == libvirt.VIR_DOMAIN_SHUTOFF:
+            self.activate_unavailable_page(_("Guest not running"))
+        else:
+            if status == libvirt.VIR_DOMAIN_CRASHED:
+                self.activate_unavailable_page(_("Guest has crashed"))
# Helper for displaying more accurate status
+
     def _vnc_disconnected(self, src):
+        self.connected = 0
         logging.debug("VNC disconnected")
-        self.vncViewerFailures = self.vncViewerFailures + 1
-        self.activate_unavailable_page(_("Console was disconnected from guest"))
# separately moved away to other places, see futher and it becomes clear
         if not self.is_visible():
             return

-        if self.vncViewerFailures < 10:
-            self.schedule_retry()
-        else:
-            logging.error("Too many connection failures, not retrying again")
+        if self.vm.status() in [ libvirt.VIR_DOMAIN_SHUTOFF, libvirt.VIR_DOMAIN_CRASHED ]:
+            self.view_vm_status()
+            return
# Well, there is no point in scheduling login retries to the gues when it is down
# make use of self.view_vm_status() to view more explicit status information
+
+        self.activate_unavailable_page(_("TCP/IP error: VNC connection to hypervisor host got refused or disconnected!"))
# Updated version of "Console was disconnected from guest" until gtk-vnc supports the signal vnc-connection-refused
+        self.schedule_retry()
# retry couting moved to schedule_retry, so no counting done here (and elsewhere)

     def _vnc_initialized(self, src):
+        self.connected = 1
         logging.debug("VNC initialized")
         self.activate_viewer_page()

         # Had a succesfull connect, so reset counters now
-        self.vncViewerFailures = 0
+        self.vncViewerRetriesScheduled = 0
# Simple rename to be more exact to what I'm using it now.
         self.vncViewerRetryDelay = 125

     def schedule_retry(self):
+        self.vncViewerRetriesScheduled = self.vncViewerRetriesScheduled + 1
+        if self.vncViewerRetriesScheduled >= 10:
+            logging.error("Too many connection failures, not retrying again")
+            return
# retry couting moved to schedule_retry, retriy counting for all users of this function
         logging.warn("Retrying connection in %d ms", self.vncViewerRetryDelay)
         gobject.timeout_add(self.vncViewerRetryDelay, self.retry_login)
         if self.vncViewerRetryDelay < 2000:
             self.vncViewerRetryDelay = self.vncViewerRetryDelay * 2

     def retry_login(self):
+        if self.connected:
+            return
# retrying login if we are already logged in results in strange errors
         gtk.gdk.threads_enter()
         try:
             logging.debug("Got timed retry")
             self.try_login()
-            return False
+            return
# return code not used AFAICS, can as well just return without status
         finally:
             gtk.gdk.threads_leave()

     def try_login(self, src=None):
         if self.vm.get_id() < 0:
-            self.activate_unavailable_page(_("Console not available for inactive guest"))
# self.vm.get_id() < 0 means that the guest is not running, but "Console not available for inactive guest"
# reads like a error meesage so make it more simple:
+            self.activate_unavailable_page(_("Guest not running"))
# and schedule a retry in case the guest was just started but takes ~300ms to start in case of QEMU/KVM:
+            self.schedule_retry()
             return

         logging.debug("Trying console login")
@@ -320,7 +338,7 @@
                 self.vncViewer.set_credential(credList[i], "libvirt")
             else:
                 # Force it to stop re-trying
-                self.vncViewerFailures = 10
+                self.vncViewerRetriesScheduled = 10
# Simple rename to be more exact to what I'm using it now.
                 self.vncViewer.close()
                 self.activate_unavailable_page(_("Unsupported console authentication type"))

@@ -503,7 +521,7 @@
             if self.window.get_widget("console-pages").get_current_page() != PAGE_UNAVAILABLE:
                 self.vncViewer.close()
                 self.window.get_widget("console-pages").set_current_page(PAGE_UNAVAILABLE)
-            self.activate_unavailable_page(_("Console not available for inactive guest"))
+            self.view_vm_status()
# display more exact message
         else:
             if status == libvirt.VIR_DOMAIN_PAUSED:
                 if self.window.get_widget("console-pages").get_current_page() == PAGE_VNCVIEWER:
@@ -543,7 +561,7 @@
                     if self.vncViewer.is_open():
                         self.activate_viewer_page()
                     else:
-                        self.vncViewerFailures = 0
+                        self.vncViewerRetriesScheduled = 0
# Simple rename to be more exact to what I'm using it now.
                         self.vncViewerRetryDelay = 125
                         self.try_login()
                         self.ignorePause = False

Without this patch, a the console of a newly started KVM / QEMU guest is only shown after
toggling pause if the console window was open while starting it, and also some intermittent
messages which could cause unneccesary confusion are displayed. I can split it up, but
it should be rather clear what it does.

Bernhard
--- virt-manager--devel/src/virtManager/console.py	2007/08/30 23:11:35	1.1
+++ virt-manager--devel/src/virtManager/console.py	2007/08/31 00:53:58
@@ -74,8 +74,9 @@
         self.window.get_widget("console-pages").append_page(self.vncViewer)
         self.vncViewer.realize()
         self.vncViewer.show()
-        self.vncViewerFailures = 0
+        self.vncViewerRetriesScheduled = 0
         self.vncViewerRetryDelay = 125
+        self.connected = 0
 
         self.notifyID = None
         try:
@@ -231,44 +232,61 @@
            return 1
         return 0
 
+    def view_vm_status(self):
+        status = self.vm.status()
+        if status == libvirt.VIR_DOMAIN_SHUTOFF:
+            self.activate_unavailable_page(_("Guest not running"))
+        else:
+            if status == libvirt.VIR_DOMAIN_CRASHED:
+                self.activate_unavailable_page(_("Guest has crashed"))
+
     def _vnc_disconnected(self, src):
+        self.connected = 0
         logging.debug("VNC disconnected")
-        self.vncViewerFailures = self.vncViewerFailures + 1
-        self.activate_unavailable_page(_("Console was disconnected from guest"))
         if not self.is_visible():
             return
 
-        if self.vncViewerFailures < 10:
-            self.schedule_retry()
-        else:
-            logging.error("Too many connection failures, not retrying again")
+        if self.vm.status() in [ libvirt.VIR_DOMAIN_SHUTOFF, libvirt.VIR_DOMAIN_CRASHED ]:
+            self.view_vm_status()
+            return
+
+        self.activate_unavailable_page(_("TCP/IP error: VNC connection to hypervisor host got refused or disconnected!"))
+        self.schedule_retry()
 
     def _vnc_initialized(self, src):
+        self.connected = 1
         logging.debug("VNC initialized")
         self.activate_viewer_page()
 
         # Had a succesfull connect, so reset counters now
-        self.vncViewerFailures = 0
+        self.vncViewerRetriesScheduled = 0
         self.vncViewerRetryDelay = 125
 
     def schedule_retry(self):
+        self.vncViewerRetriesScheduled = self.vncViewerRetriesScheduled + 1
+        if self.vncViewerRetriesScheduled >= 10:
+            logging.error("Too many connection failures, not retrying again")
+            return
         logging.warn("Retrying connection in %d ms", self.vncViewerRetryDelay)
         gobject.timeout_add(self.vncViewerRetryDelay, self.retry_login)
         if self.vncViewerRetryDelay < 2000:
             self.vncViewerRetryDelay = self.vncViewerRetryDelay * 2
 
     def retry_login(self):
+        if self.connected:
+            return
         gtk.gdk.threads_enter()
         try:
             logging.debug("Got timed retry")
             self.try_login()
-            return False
+            return
         finally:
             gtk.gdk.threads_leave()
 
     def try_login(self, src=None):
         if self.vm.get_id() < 0:
-            self.activate_unavailable_page(_("Console not available for inactive guest"))
+            self.activate_unavailable_page(_("Guest not running"))
+            self.schedule_retry()
             return
 
         logging.debug("Trying console login")
@@ -320,7 +338,7 @@
                 self.vncViewer.set_credential(credList[i], "libvirt")
             else:
                 # Force it to stop re-trying
-                self.vncViewerFailures = 10
+                self.vncViewerRetriesScheduled = 10
                 self.vncViewer.close()
                 self.activate_unavailable_page(_("Unsupported console authentication type"))
 
@@ -503,7 +521,7 @@
             if self.window.get_widget("console-pages").get_current_page() != PAGE_UNAVAILABLE:
                 self.vncViewer.close()
                 self.window.get_widget("console-pages").set_current_page(PAGE_UNAVAILABLE)
-            self.activate_unavailable_page(_("Console not available for inactive guest"))
+            self.view_vm_status()
         else:
             if status == libvirt.VIR_DOMAIN_PAUSED:
                 if self.window.get_widget("console-pages").get_current_page() == PAGE_VNCVIEWER:
@@ -543,7 +561,7 @@
                     if self.vncViewer.is_open():
                         self.activate_viewer_page()
                     else:
-                        self.vncViewerFailures = 0
+                        self.vncViewerRetriesScheduled = 0
                         self.vncViewerRetryDelay = 125
                         self.try_login()
                         self.ignorePause = False
_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/et-mgmt-tools

[Index of Archives]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux