2018-10-24 07:57:06 +00:00
|
|
|
#!/bin/bash
|
|
|
|
# Note: execute this file from the project root directory
|
|
|
|
|
|
|
|
#####
|
|
|
|
#
|
|
|
|
# Make sure we can build an image and deploy it inside vSphere!
|
|
|
|
#
|
|
|
|
#####
|
|
|
|
|
2019-06-02 13:20:42 +00:00
|
|
|
set -e
|
|
|
|
|
2018-10-24 07:57:06 +00:00
|
|
|
. /usr/share/beakerlib/beakerlib.sh
|
2019-05-21 13:39:33 +00:00
|
|
|
. $(dirname $0)/lib/lib.sh
|
2018-10-24 07:57:06 +00:00
|
|
|
|
2019-03-08 10:29:11 +00:00
|
|
|
CLI="${CLI:-./src/bin/composer-cli}"
|
2018-10-24 07:57:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
rlJournalStart
|
|
|
|
rlPhaseStartSetup
|
|
|
|
if [ -z "$V_HOST" ]; then
|
|
|
|
rlFail "V_HOST is empty!"
|
|
|
|
else
|
|
|
|
rlLogInfo "V_HOST=$V_HOST"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$V_USERNAME" ]; then
|
|
|
|
rlFail "V_USERNAME is empty!"
|
|
|
|
else
|
|
|
|
rlLogInfo "V_USERNAME=$V_USERNAME"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$V_PASSWORD" ]; then
|
|
|
|
rlFail "V_PASSWORD is empty!"
|
|
|
|
else
|
|
|
|
rlLogInfo "V_PASSWORD is configured"
|
|
|
|
fi
|
|
|
|
|
|
|
|
V_DATACENTER="${V_DATACENTER:-RH_Engineering}"
|
|
|
|
rlLogInfo "V_DATACENTER=$V_DATACENTER"
|
|
|
|
|
2019-04-17 17:27:04 +00:00
|
|
|
V_CLUSTER="${V_CLUSTER:-vMotion-Cluster}"
|
2018-10-24 07:57:06 +00:00
|
|
|
rlLogInfo "V_CLUSTER=$V_CLUSTER"
|
|
|
|
|
2019-04-17 17:27:04 +00:00
|
|
|
V_NETWORK="${V_NETWORK:-vMotion-Network}"
|
2018-10-24 07:57:06 +00:00
|
|
|
rlLogInfo "V_NETWORK=$V_NETWORK"
|
|
|
|
|
2019-03-21 15:26:08 +00:00
|
|
|
V_DATASTORE="${V_DATASTORE:-iSCSI-Node2}"
|
2018-10-24 07:57:06 +00:00
|
|
|
rlLogInfo "V_DATASTORE=$V_DATASTORE"
|
|
|
|
|
|
|
|
V_FOLDER="${V_FOLDER:-Composer}"
|
|
|
|
rlLogInfo "V_FOLDER=$V_FOLDER"
|
|
|
|
|
|
|
|
if ! rlCheckRpm "python3-pip"; then
|
|
|
|
rlRun -t -c "dnf -y install python3-pip"
|
|
|
|
rlAssertRpm python3-pip
|
|
|
|
fi
|
|
|
|
|
|
|
|
rlRun -t -c "pip3 install pyvmomi"
|
|
|
|
|
|
|
|
TMP_DIR=`mktemp -d /tmp/composer-vmware.XXXXX`
|
2018-12-05 08:34:31 +00:00
|
|
|
SAMPLES="$TMP_DIR/pyvmomi-community-samples"
|
2018-10-24 07:57:06 +00:00
|
|
|
if [ ! -d "$SAMPLES" ]; then
|
2018-12-05 08:34:31 +00:00
|
|
|
rlRun -t -c "git clone https://github.com/weldr/pyvmomi-community-samples $SAMPLES"
|
2018-10-24 07:57:06 +00:00
|
|
|
pushd $SAMPLES && git checkout composer_testing && popd
|
|
|
|
fi
|
2018-12-05 08:34:31 +00:00
|
|
|
SAMPLES="$SAMPLES/samples"
|
2018-10-24 07:57:06 +00:00
|
|
|
rlPhaseEnd
|
|
|
|
|
|
|
|
rlPhaseStartTest "compose start"
|
2019-01-25 16:53:50 +00:00
|
|
|
rlAssertEquals "SELinux operates in enforcing mode" "$(getenforce)" "Enforcing"
|
2018-12-06 13:32:35 +00:00
|
|
|
SSH_KEY_DIR=`mktemp -d /tmp/composer-ssh-keys.XXXXXX`
|
|
|
|
rlRun -t -c "ssh-keygen -t rsa -N '' -f $SSH_KEY_DIR/id_rsa"
|
|
|
|
PUB_KEY=`cat $SSH_KEY_DIR/id_rsa.pub`
|
2018-10-24 07:57:06 +00:00
|
|
|
|
|
|
|
cat > $TMP_DIR/vmware.toml << __EOF__
|
|
|
|
name = "vmware"
|
|
|
|
description = "HTTP image for vmware"
|
|
|
|
version = "0.0.1"
|
|
|
|
|
2019-04-11 06:02:42 +00:00
|
|
|
[[packages]]
|
2018-10-24 07:57:06 +00:00
|
|
|
name = "httpd"
|
|
|
|
version = "*"
|
|
|
|
|
|
|
|
[[customizations.user]]
|
|
|
|
name = "root"
|
|
|
|
key = "$PUB_KEY"
|
2019-04-08 09:00:41 +00:00
|
|
|
|
|
|
|
[customizations.kernel]
|
|
|
|
append = "custom_cmdline_arg"
|
2018-10-24 07:57:06 +00:00
|
|
|
__EOF__
|
|
|
|
|
2018-12-05 08:06:24 +00:00
|
|
|
rlRun -t -c "$CLI blueprints push $TMP_DIR/vmware.toml"
|
2018-10-24 07:57:06 +00:00
|
|
|
|
|
|
|
UUID=`$CLI compose start vmware vmdk`
|
|
|
|
rlAssertEquals "exit code should be zero" $? 0
|
|
|
|
|
|
|
|
UUID=`echo $UUID | cut -f 2 -d' '`
|
|
|
|
rlPhaseEnd
|
|
|
|
|
|
|
|
rlPhaseStartTest "compose finished"
|
|
|
|
if [ -n "$UUID" ]; then
|
2019-05-20 17:13:16 +00:00
|
|
|
until $CLI compose info $UUID | grep 'FINISHED\|FAILED'; do
|
2018-10-24 07:57:06 +00:00
|
|
|
rlLogInfo "Waiting for compose to finish ..."
|
|
|
|
sleep 30
|
|
|
|
done;
|
|
|
|
else
|
|
|
|
rlFail "Compose UUID is empty!"
|
|
|
|
fi
|
|
|
|
rlPhaseEnd
|
|
|
|
|
2019-04-17 17:27:04 +00:00
|
|
|
rlPhaseStartTest "Upload VMDK image in vCenter"
|
2018-10-24 07:57:06 +00:00
|
|
|
rlRun -t -c "$CLI compose image $UUID"
|
|
|
|
IMAGE="$UUID-disk.vmdk"
|
|
|
|
|
|
|
|
python3 $SAMPLES/upload_file_to_datastore.py -S -s $V_HOST -u $V_USERNAME -p $V_PASSWORD \
|
|
|
|
-d $V_DATASTORE -l `readlink -f $IMAGE` -r $IMAGE
|
|
|
|
rlAssert0 "Image upload successfull" $?
|
|
|
|
rlPhaseEnd
|
|
|
|
|
|
|
|
rlPhaseStartTest "Start VM instance"
|
2018-11-08 11:34:08 +00:00
|
|
|
VM_NAME="Composer-Auto-VM-$UUID"
|
2018-10-24 07:57:06 +00:00
|
|
|
INSTANCE_UUID=`python3 $SAMPLES/create_vm.py -S -s $V_HOST -u $V_USERNAME -p $V_PASSWORD \
|
|
|
|
--datacenter $V_DATACENTER -c $V_CLUSTER -f $V_FOLDER -d $V_DATASTORE \
|
|
|
|
--portgroup $V_NETWORK -v $IMAGE -m 2048 -g rhel7_64Guest -n $VM_NAME \
|
|
|
|
--power-on`
|
|
|
|
|
|
|
|
if [ -z "$INSTANCE_UUID" ]; then
|
|
|
|
rlFail "INSTANCE_UUID is empty!"
|
|
|
|
else
|
|
|
|
rlLogInfo "INSTANCE_UUID=$INSTANCE_UUID"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# wait for instance to become running and had assigned a public IP
|
|
|
|
IP_ADDRESS="None"
|
|
|
|
while [ "$IP_ADDRESS" == "None" ]; do
|
|
|
|
rlLogInfo "IP_ADDRESS is not assigned yet ..."
|
|
|
|
sleep 30
|
|
|
|
IP_ADDRESS=`python3 $SAMPLES/find_by_uuid.py -S -s $V_HOST -u $V_USERNAME -p $V_PASSWORD \
|
2019-06-04 09:05:11 +00:00
|
|
|
--uuid $INSTANCE_UUID | grep 'ip address' | tr -d ' ' | cut -f2- -d:`
|
2018-10-24 07:57:06 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
rlLogInfo "Running instance IP_ADDRESS=$IP_ADDRESS"
|
|
|
|
|
|
|
|
rlLogInfo "Waiting 30sec for instance to initialize ..."
|
|
|
|
sleep 30
|
|
|
|
rlPhaseEnd
|
|
|
|
|
|
|
|
rlPhaseStartTest "Verify VM instance"
|
2019-04-17 14:12:12 +00:00
|
|
|
# run generic tests to verify the instance
|
|
|
|
verify_image root "$IP_ADDRESS" "-i $SSH_KEY_DIR/id_rsa"
|
2018-10-24 07:57:06 +00:00
|
|
|
rlPhaseEnd
|
|
|
|
|
|
|
|
rlPhaseStartCleanup
|
|
|
|
# note: vmdk disk is removed when destroying the VM
|
|
|
|
python3 $SAMPLES/destroy_vm.py -S -s $V_HOST -u $V_USERNAME -p $V_PASSWORD --uuid $INSTANCE_UUID
|
|
|
|
rlAssert0 "VM destroyed" $?
|
|
|
|
rlRun -t -c "$CLI compose delete $UUID"
|
2018-12-06 13:32:35 +00:00
|
|
|
rlRun -t -c "rm -rf $IMAGE $TMP_DIR $SSH_KEY_DIR"
|
2018-10-24 07:57:06 +00:00
|
|
|
rlPhaseEnd
|
|
|
|
|
|
|
|
rlJournalEnd
|
|
|
|
rlJournalPrintText
|