[NEW PATCH] BZ#733669 Improve error reporting for wrong local hostname (via gerrit-bot)

Federico Simoncelli fsimonce at redhat.com
Thu Sep 15 09:50:18 UTC 2011


New patch submitted by Federico Simoncelli (fsimonce at redhat.com)

You can review this change at: http://gerrit.usersys.redhat.com/924

commit fa835dba88dd21c63429c921f453a26514a77294
Author: Federico Simoncelli <fsimonce at redhat.com>
Date:   Fri Sep 9 17:01:26 2011 +0000

    BZ#733669 Improve error reporting for wrong local hostname
    
    This patch improves the error reporting when migration fails.
    It is mainly designed to return the new error 'wrongHost' to
    the manager when the migration destination has a wrong local
    hostname (which will cause the migration to fail without any
    informative message).
    Additionally it checks the local hostname during the bootstrap
    process and produces a warning if needed.
    
    In this patch:
    * add local hostname check during bootstrap (report a warning)
    * return the new error 'wrongHost' if migration destination has
      a wrong local hostname
    * source node must return a specific error when migration fails
    
    Change-Id: Iaf0ae2d62772b01d05d9d5e62d2433c1758d69b1

diff --git a/vds_bootstrap/vds_bootstrap.py b/vds_bootstrap/vds_bootstrap.py
index 3f8423c..4074a57 100755
--- a/vds_bootstrap/vds_bootstrap.py
+++ b/vds_bootstrap/vds_bootstrap.py
@@ -51,6 +51,8 @@ import traceback
 import random
 import re
 import ConfigParser
+import ethtool
+import socket
 
 # set logging before deployUtil is first used
 rnum = str(random.randint(100,1000000))
@@ -599,6 +601,37 @@ gpgcheck=0
 
         return fReturn
 
+    def checkLocalHostname(self):
+        self.status = "OK"
+        self.rc = True
+        self.message = "Local hostname is correct."
+
+        try:
+            localip = map(ethtool.get_ipaddr, ethtool.get_active_devices())
+        except:
+            logging.error("ethtool error", exc_info=True)
+            localip = ()
+
+        try:
+            fqdnip = socket.gethostbyname(socket.gethostname())
+        except:
+            logging.error("gethostbyname error", exc_info=True)
+            fqdnip = None
+
+        if fqdnip is None or fqdnip not in localip:
+            if len(localip) < 1:
+                self.message = "Unable to get local ip addresses."
+            elif fqdnip is None:
+                self.message = "Unable to resolve local hostname."
+            else:
+                self.message = "Local hostname is configured badly."
+            self.status = "WARN"
+            logging.error(self.message)
+
+        self._xmlOutput('CheckLocalHostname',
+                        self.status, None, None, self.message)
+        return self.rc
+
     def setNetworking(self, iurl):
         """
             Create rhevm bridge.
@@ -761,6 +794,10 @@ def VdsValidation(iurl, subject, random_num, rev_num, orgName, systime, usevdcre
         logging.error('createConf failed')
         return False
 
+    if not oDeploy.checkLocalHostname():
+        logging.error('checkLocalHostname test failed')
+        return False
+
     if not oDeploy.setNetworking(iurl):
         logging.error('setNetworking test failed')
         return False
diff --git a/vdsm/clientIF.py b/vdsm/clientIF.py
index 241a86a..a428e7c 100644
--- a/vdsm/clientIF.py
+++ b/vdsm/clientIF.py
@@ -781,7 +781,7 @@ class clientIF:
 
         if not utils.validLocalHostname():
             self.log.error('Migration failed: local hostname is not correct')
-            return errCode['createErr']
+            return errCode['wrongHost']
 
         response = self.create(params)
         if response['status']['code']:
diff --git a/vdsm/define.py b/vdsm/define.py
index ca30ddf..78e7563 100644
--- a/vdsm/define.py
+++ b/vdsm/define.py
@@ -36,6 +36,7 @@ errCode = { 'noVM':         {'status': {'code': 1, 'message': 'Virtual machine d
             'ticketErr':    {'status': {'code':18, 'message': 'Error while setting spice ticket'}},
             'nonresp':      {'status': {'code':19, 'message': 'Guest agent non-responsive'}},
 # codes 20-29 are reserved for add/delNetwork
+            'wrongHost':    {'status': {'code':39, 'message': 'Migration destination has an invalid hostname'}},
             'unavail':      {'status': {'code':40, 'message': 'Resource unavailable'}},
             'changeDisk':   {'status': {'code':41, 'message': 'Failed to change disk image'}},
             'destroyErr':   {'status': {'code':42, 'message': 'Virtual machine destroy error'}},
diff --git a/vdsm/libvirtvm.py b/vdsm/libvirtvm.py
index 221589b..64ee74a 100644
--- a/vdsm/libvirtvm.py
+++ b/vdsm/libvirtvm.py
@@ -296,6 +296,7 @@ class MigrationSourceThread(vm.MigrationSourceThread):
             hooks.before_vm_migrate_source(self._vm._dom.XMLDesc(0), self._vm.conf)
             response = self.destServer.migrationCreate(self._machineParams)
             if response['status']['code']:
+                self.status = response
                 raise RuntimeError('migration destination error: ' + response['status']['message'])
             if config.getboolean('vars', 'ssl'):
                 transport = 'tls'
diff --git a/vdsm/vm.py b/vdsm/vm.py
index 8a87db6..40d32ca 100644
--- a/vdsm/vm.py
+++ b/vdsm/vm.py
@@ -183,7 +183,8 @@ class MigrationSourceThread(threading.Thread):
             self._vm.lastStatus = 'Migration Source'
 
     def _recover(self, message):
-        self.status = errCode['migrateErr']
+        if not self.status['status']['code']:
+            self.status = errCode['migrateErr']
         self.log.error(message)
         if self._mode != 'file':
             try:




More information about the vdsm-patches mailing list