From 19cf6b6bba3e8871b68b9f0992db7d121f25647c Mon Sep 17 00:00:00 2001
From: Julien Leduc <julien.leduc@cern.ch>
Date: Thu, 9 Nov 2017 15:50:32 +0100
Subject: [PATCH] Unloading tapes that can be left in the mhvtl drive from the
 previous CI (crashed) run.

---
 .../docker/ctafrontend/cc7/opt/run/bin/init.sh             | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/continuousintegration/docker/ctafrontend/cc7/opt/run/bin/init.sh b/continuousintegration/docker/ctafrontend/cc7/opt/run/bin/init.sh
index 1b6272ca2d..35c5e98f71 100755
--- a/continuousintegration/docker/ctafrontend/cc7/opt/run/bin/init.sh
+++ b/continuousintegration/docker/ctafrontend/cc7/opt/run/bin/init.sh
@@ -76,6 +76,13 @@ if [ ! $LIBRARYTYPE == "mhvtl" ]; then
 else
   # library management
   # BEWARE STORAGE SLOTS START @1 and DRIVE SLOTS START @0!!
+  # Emptying drives and move tapes to home slots
+  echo "Unloading tapes that could be remaining in the drives from previous runs"
+  mtx -f /dev/${LIBRARYDEVICE} status
+  for unload in $(mtx -f /dev/${LIBRARYDEVICE}  status | grep '^Data Transfer Element' | grep -vi ':empty' | sed -e 's/Data Transfer Element /drive/;s/:.*Storage Element /-slot/;s/ .*//'); do
+    # normally, there is no need to rewind with virtual tapes...
+    mtx -f /dev/${LIBRARYDEVICE} unload $(echo ${unload} | sed -e 's/^.*-slot//') $(echo ${unload} | sed -e 's/drive//;s/-.*//') || echo "COULD NOT UNLOAD TAPE"
+  done
   echo "Labelling tapes using the first drive in ${LIBRARYNAME}: ${DRIVENAMES[${driveslot}]} on /dev/${DRIVEDEVICES[${driveslot}]}:"
   for ((i=0; i<${#TAPES[@]}; i++)); do
     vid=${TAPES[${i}]}
-- 
GitLab