ci/deploy.sh: Allow non-root deploys 47/38547/1
authorAlexandru Avadanii <Alexandru.Avadanii@enea.com>
Mon, 17 Jul 2017 23:10:25 +0000 (23:10 +0000)
committerAlexandru Avadanii <Alexandru.Avadanii@enea.com>
Tue, 1 Aug 2017 19:20:21 +0000 (21:20 +0200)
Currently, deploying Fuel@OPNFV requires the `ci/deploy.sh` to be ran
as root user, for:
- hypervisor access (virsh);
- installing prerequisite packages;

We can support non-root deploys if we relax above restriction into:
- current user should have hypervisor access beforehand
  (new check added);
- current user has passwordless sudo rights, for installing packages;

Later, we should move the package installation out of the deploy
script (`ci/deploy.sh`), making the whole deploy possible without
sudo, only hypervisor access.

After this change, the old way (sudo ci/deploy.sh) should work just
like it used to before, so no regression/behavior change should be
introduced with this.

Change-Id: Ib2ea96aa7b6d67ba0606318407a8adeb51e6969d
Signed-off-by: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
ci/deploy.sh

index a77dd0f..2b7638e 100755 (executable)
@@ -87,7 +87,7 @@ $(notify "Disabled input parameters (not yet supported with MCP):" 3)
 -i (disabled) .iso image to be deployed (needs to be provided in a URI
    style, it can be a local resource: file:// or a remote resource http(s)://)
 
-$(notify "[NOTE] Root priviledges are needed for this script to run" 3)
+$(notify "[NOTE] sudo & virsh priviledges are needed for this script to run" 3)
 
 Example:
 
@@ -240,8 +240,13 @@ do
     esac
 done
 
-if [[ $EUID -ne 0 ]]; then
-    notify "[ERROR] This script must be run as root\n" 1>&2
+if [[ "$(sudo whoami)" != 'root' ]]; then
+    notify "This script requires sudo rights\n" 1>&2
+    exit 1
+fi
+
+if ! virsh list >/dev/null 2>&1; then
+    notify "This script requires hypervisor access\n" 1>&2
     exit 1
 fi
 
@@ -269,9 +274,9 @@ pushd "${DEPLOY_DIR}" > /dev/null
 # scenario, etc.
 
 # Install required packages
-[ -n "$(command -v apt-get)" ] && apt-get install -y \
+[ -n "$(command -v apt-get)" ] && sudo apt-get install -y \
   git make rsync mkisofs curl virtinst cpu-checker qemu-kvm
-[ -n "$(command -v yum)" ] && yum install -y \
+[ -n "$(command -v yum)" ] && sudo yum install -y \
   git make rsync genisoimage curl virt-install qemu-kvm
 
 # Check scenario file existence