libguestfs/SOURCES/0032-v2v-rhv-upload-plugin-...

67 lines
2.4 KiB
Diff

From 8aaf7d89ef8b686840d3683fb27c4746624088a5 Mon Sep 17 00:00:00 2001
From: Nir Soffer <nirsof@gmail.com>
Date: Sat, 30 Jun 2018 01:21:50 +0300
Subject: [PATCH] v2v: rhv-upload-plugin: Improve error handling
When optimizing the connection using unix socket, we handle these cases:
- The local host is not an oVirt host (no /etc/vdsm/vdsm.id).
- The local host is an oVirt host, but is not registered with engine.
- Creating UnixHTTPConnection() fails. Unlikely and probably a bug in
the plugin, but we can recover by using the https connection.
The current code handle these cases silently, making it harder to
understand why the unix socket optimization did no happen. Add debug
message to make this clear.
Also comment in the error handler why we take this path instead of
failing the operation.
(cherry picked from commit f5442d2f044b398efc992fb4d56c8d3096c781e6)
---
v2v/rhv-upload-plugin.py | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/v2v/rhv-upload-plugin.py b/v2v/rhv-upload-plugin.py
index f404bd758..8e4052048 100644
--- a/v2v/rhv-upload-plugin.py
+++ b/v2v/rhv-upload-plugin.py
@@ -63,7 +63,10 @@ def find_host(connection):
with builtins.open("/etc/vdsm/vdsm.id") as f:
vdsm_id = f.readline().strip()
except Exception as e:
+ # This is most likely not an oVirt host.
+ debug("cannot read /etc/vdsm/vdsm.id, using any host: %s" % e)
return None
+
debug("hw_id = %r" % vdsm_id)
hosts_service = connection.system_service().hosts_service()
@@ -72,6 +75,8 @@ def find_host(connection):
case_sensitive=False,
)
if len(hosts) == 0:
+ # This oVirt host is not registered with engine.
+ debug("cannot find host with hw_id=%r, using any host" % vdsm_id)
return None
host = hosts[0]
@@ -233,9 +238,12 @@ def open(readonly):
if host is not None and unix_socket is not None:
try:
http = UnixHTTPConnection(unix_socket)
+ except Exception as e:
+ # Very unlikely failure, but we can recover by using the https
+ # connection.
+ debug("cannot create unix socket connection, using https: %s" % e)
+ else:
debug("optimizing connection using unix socket %r" % unix_socket)
- except:
- pass
# Save everything we need to make requests in the handle.
return {
--
2.21.0