Run script only if volume device is found
[functest.git] / functest / opnfv_tests / openstack / cinder / write_data.sh
1 #!/bin/sh -e
2
3 # Copyright (c) 2018 Enea AB and others
4
5 # This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10
11 DEST=$(mktemp -d)
12 VOL_DEV_NAME=${1:-vdb}
13 echo "VOL_DEV_NAME: $VOL_DEV_NAME"
14
15 echo "$(lsblk -l -o NAME)"
16
17 if [ ! -z $(lsblk -l -o NAME | grep $VOL_DEV_NAME) ]; then
18     sudo /usr/sbin/mkfs.ext4 -F /dev/$VOL_DEV_NAME
19     sudo mount /dev/$VOL_DEV_NAME $DEST
20     sudo touch $DEST/new_data
21     if [ -f $DEST/new_data ]; then
22         echo "New data added to the volume!"
23         sudo umount $DEST
24     fi
25 else
26     echo "Failed to write data!"
27     exit 1
28 fi
29
30 exit 0