xenserver: Create xapi database cache in RPM preinstall step.
authorBen Pfaff <blp@nicira.com>
Thu, 28 May 2009 21:38:17 +0000 (14:38 -0700)
committerBen Pfaff <blp@nicira.com>
Fri, 29 May 2009 00:11:08 +0000 (17:11 -0700)
Until now, the RPM package for XenServer only attempted to save the xapi
database cache during the reboot process (from
/etc/init.d/management-interface), which happened well after the vswitch
was actually installed.  This meant that if connectivity to xapi was busted
at reboot time, or even just if the machine was rebooted with the reset
button instead of through a graceful reboot sequence, then the machine
would fail to come up and there would be no way to fix it without removing
the vswitch.

This commit fixes the problem by writing out the xapi database cache before
package installation and aborting the install if the operation fails.

xenserver/vswitch-xen.spec

index 57797bf83937c3ab7d005fcbfd437797d0fca1fb..5c705d421a304db57ab00bc6726451da46e89553 100644 (file)
@@ -114,6 +114,52 @@ EOF
     fi
 fi
 
+if test ! -e /etc/vswitch.dbcache; then
+    if test "$1" = 1; then
+        printf "Creating xapi database cache...  "
+    else
+        printf "warning: Open vSwitch is being re-installed or upgraded,\n"
+        printf "         but the xapi database cache is missing.\n"
+        printf "Re-creating xapi database cache...  "
+    fi
+
+    source /etc/xensource-inventory
+    if python - "$INSTALLATION_UUID" <<EOF
+import XenAPI
+import pickle
+import sys
+
+session = XenAPI.xapi_local()
+try:
+    session.xenapi.login_with_password("root", "")
+
+    vlans = session.xenapi.VLAN.get_all_records()
+    bonds = session.xenapi.Bond.get_all_records()
+    pifs = session.xenapi.PIF.get_all_records()
+    networks = session.xenapi.network.get_all_records()
+    host = session.xenapi.host.get_by_uuid(sys.argv[1])
+finally:
+    session.xenapi.session.logout()
+
+dbcache_file = "/etc/vswitch.dbcache"
+f = open(dbcache_file, 'w')
+pickle.dump({'vlans': vlans,
+             'bonds': bonds,
+             'pifs': pifs,
+             'networks': networks}, f)
+pickle.dump({'host': host}, f)
+f.close()
+EOF
+    then
+        printf "done.\n"
+    else
+        printf "FAILED\n"
+        printf "Open vSwitch can only be installed on a XenServer that\n"
+        printf "has connectivity to xapi on the pool master.  Please\n"
+        printf "fix connectivity to the pool master, then try again.\n"
+        exit 1
+    fi
+fi
 
 %post
 source /etc/xensource-inventory
@@ -148,11 +194,6 @@ if [ "$plugin" != "/root/vswitch/scripts/XSFeatureVSwitch.py" ]; then
     ln -s /root/vswitch/scripts/XSFeatureVSwitch.py /usr/lib/xsconsole/plugins-base/ || printf "Could not link to vSswitch xsconsole plugin.\n"
 fi
 
-# Modify conf files for compatibility with our interface-reconfigure
-for pif in $(xe pif-list host-uuid=$INSTALLATION_UUID params=uuid | awk '{print $5}'); do
-    /opt/xensource/libexec/interface-reconfigure --pif-uuid $pif rewrite
-done
-
 # Ensure all required services are set to run
 for s in vswitch vswitch-xapi-update; do
     if chkconfig --list $s >/dev/null 2>&1; then