Support oslo-rootwrap in lib/cinder

Make lib/cinder support both cinder-rootwrap (current case) and
oslo-rootwrap (future case) to handle the Cinder transition towards
oslo-rootwrap usage peacefully.

Related blueprint:
https://blueprints.launchpad.net/cinder/+spec/cinder-oslo-rootwrap

Change-Id: I663986304bd74cb6d72d51c553540fb5f9db1d1d
diff --git a/lib/cinder b/lib/cinder
index ef3bd81..cbe732e 100644
--- a/lib/cinder
+++ b/lib/cinder
@@ -174,6 +174,12 @@
 
     # Set the paths of certain binaries
     CINDER_ROOTWRAP=$(get_rootwrap_location cinder)
+    if [[ ! -x $CINDER_ROOTWRAP ]]; then
+        CINDER_ROOTWRAP=$(get_rootwrap_location oslo)
+        if [[ ! -x $CINDER_ROOTWRAP ]]; then
+            die $LINENO "No suitable rootwrap found."
+        fi
+    fi
 
     # If Cinder ships the new rootwrap filters files, deploy them
     # (owned by root) and add a parameter to $CINDER_ROOTWRAP
@@ -189,11 +195,16 @@
         sudo chown -R root:root $CINDER_CONF_DIR/rootwrap.d
         sudo chmod 644 $CINDER_CONF_DIR/rootwrap.d/*
         # Set up rootwrap.conf, pointing to /etc/cinder/rootwrap.d
-        sudo cp $CINDER_DIR/etc/cinder/rootwrap.conf $CINDER_CONF_DIR/
+        if [[ -f $CINDER_DIR/etc/cinder/rootwrap.conf ]]; then
+            sudo cp $CINDER_DIR/etc/cinder/rootwrap.conf $CINDER_CONF_DIR/
+        else
+            # rootwrap.conf is no longer shipped in Cinder itself
+            echo "filters_path=" | sudo tee $CINDER_CONF_DIR/rootwrap.conf > /dev/null
+        fi
         sudo sed -e "s:^filters_path=.*$:filters_path=$CINDER_CONF_DIR/rootwrap.d:" -i $CINDER_CONF_DIR/rootwrap.conf
         sudo chown root:root $CINDER_CONF_DIR/rootwrap.conf
         sudo chmod 0644 $CINDER_CONF_DIR/rootwrap.conf
-        # Specify rootwrap.conf as first parameter to cinder-rootwrap
+        # Specify rootwrap.conf as first parameter to rootwrap
         CINDER_ROOTWRAP="$CINDER_ROOTWRAP $CINDER_CONF_DIR/rootwrap.conf"
         ROOTWRAP_CINDER_SUDOER_CMD="$CINDER_ROOTWRAP *"
     fi