Improve hotplug script error reporting via xenstore.
authorkfraser@localhost.localdomain <kfraser@localhost.localdomain>
Wed, 7 Feb 2007 16:22:55 +0000 (16:22 +0000)
committerkfraser@localhost.localdomain <kfraser@localhost.localdomain>
Wed, 7 Feb 2007 16:22:55 +0000 (16:22 +0000)
Use this to detect and report up-front in vif-bridge script whether
the bridge device exists or not.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
tools/examples/vif-bridge
tools/examples/xen-hotplug-common.sh
tools/python/xen/xend/server/DevController.py

index 0935ad2fae9a22275512ad4e329b7b6096dcd47b..6bee562c4be2342e1a1ebee40189347245bb677b 100755 (executable)
@@ -46,6 +46,13 @@ then
   fi
 fi
 
+RET=0
+ip link show $bridge 1>/dev/null 2>&1 || RET=1
+if [ "$RET" -eq 1 ]
+then
+    fatal "Could not find bridge device $bridge"
+fi
+
 case "$command" in
     online)
        setup_bridge_port "$vif"
index c825dae5935add842b2c3b1a43ea0f1652e80ac9..980a62704e49acbaaf999c33285442618b6a5e54 100644 (file)
@@ -28,14 +28,15 @@ export LANG="POSIX"
 unset $(set | grep ^LC_ | cut -d= -f1)
 
 fatal() {
-  xenstore_write "$XENBUS_PATH"/hotplug-status error
+  xenstore_write "$XENBUS_PATH/hotplug-error" "$*" \
+                 "$XENBUS_PATH/hotplug-status" error
   log err "$@"
   exit 1
 }
 
 success() {
   # Tell DevController that backend is "connected"
-  xenstore_write "$XENBUS_PATH"/hotplug-status connected
+  xenstore_write "$XENBUS_PATH/hotplug-status" connected
 }
 
 do_or_die() {
index 8256d2265f0c41942d5a091c00394a070338afdc..47f03e19949586da05b7312f3c0b6391096b035d 100644 (file)
@@ -153,9 +153,9 @@ class DevController:
         log.debug("Waiting for %s.", devid)
 
         if not self.hotplug:
-            return 
-        
-        status = self.waitForBackend(devid)
+            return
+
+        (status, err) = self.waitForBackend(devid)
 
         if status == Timeout:
             self.destroyDevice(devid, False)
@@ -165,25 +165,22 @@ class DevController:
 
         elif status == Error:
             self.destroyDevice(devid, False)
-            raise VmError("Device %s (%s) could not be connected. "
-                          "Backend device not found." %
-                          (devid, self.deviceClass))
-
+            if err is None:
+                raise VmError("Device %s (%s) could not be connected. "
+                              "Backend device not found." %
+                              (devid, self.deviceClass))
+            else:
+                raise VmError("Device %s (%s) could not be connected. "
+                              "%s" % (devid, self.deviceClass, err))
         elif status == Missing:
             # Don't try to destroy the device; it's already gone away.
             raise VmError("Device %s (%s) could not be connected. "
                           "Device not found." % (devid, self.deviceClass))
 
         elif status == Busy:
-            err = None
-            frontpath = self.frontendPath(devid)
-            backpath = xstransact.Read(frontpath, "backend")
-            if backpath:
-                err = xstransact.Read(backpath, HOTPLUG_ERROR_NODE)
-            if not err:
-                err = "Busy."
-                
             self.destroyDevice(devid, False)
+            if err is None:
+                err = "Busy."
             raise VmError("Device %s (%s) could not be connected.\n%s" %
                           (devid, self.deviceClass, err))
 
@@ -478,17 +475,21 @@ class DevController:
         frontpath = self.frontendPath(devid)
         backpath = xstransact.Read(frontpath, "backend")
 
+
         if backpath:
             statusPath = backpath + '/' + HOTPLUG_STATUS_NODE
             ev = Event()
             result = { 'status': Timeout }
-            
+
             xswatch(statusPath, hotplugStatusCallback, ev, result)
 
             ev.wait(DEVICE_CREATE_TIMEOUT)
-            return result['status']
+
+            err = xstransact.Read(backpath, HOTPLUG_ERROR_NODE)
+
+            return (result['status'], err)
         else:
-            return Missing
+            return (Missing, None)
 
 
     def backendPath(self, backdom, devid):