2018-12-12 11:38:09 +00:00
|
|
|
#!/bin/bash
|
|
|
|
# Note: execute this file from the project root directory
|
|
|
|
|
|
|
|
#####
|
|
|
|
#
|
|
|
|
# Make sure we can build an image and deploy it inside Azure!
|
|
|
|
#
|
|
|
|
#####
|
|
|
|
|
2019-06-17 12:35:31 +00:00
|
|
|
set -e
|
|
|
|
|
2018-12-12 11:38:09 +00:00
|
|
|
. /usr/share/beakerlib/beakerlib.sh
|
2019-06-17 12:35:31 +00:00
|
|
|
. $(dirname $0)/lib/lib.sh
|
2018-12-12 11:38:09 +00:00
|
|
|
|
2019-03-08 10:29:11 +00:00
|
|
|
CLI="${CLI:-./src/bin/composer-cli}"
|
2019-08-01 11:45:56 +00:00
|
|
|
VENV=`mktemp -d /tmp/venv.XXX`
|
2018-12-12 11:38:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
rlJournalStart
|
|
|
|
rlPhaseStartSetup
|
2019-10-18 17:07:09 +00:00
|
|
|
# NOTE: see test/README.md for information how to obtain these
|
|
|
|
# UUIDs and what configuration is expected on the Azure side
|
2018-12-12 11:38:09 +00:00
|
|
|
if [ -z "$AZURE_SUBSCRIPTION_ID" ]; then
|
|
|
|
rlFail "AZURE_SUBSCRIPTION_ID is empty!"
|
|
|
|
else
|
|
|
|
rlLogInfo "AZURE_SUBSCRIPTION_ID is configured"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$AZURE_TENANT" ]; then
|
|
|
|
rlFail "AZURE_TENANT is empty!"
|
|
|
|
else
|
|
|
|
rlLogInfo "AZURE_TENANT is configured"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$AZURE_CLIENT_ID" ]; then
|
|
|
|
rlFail "AZURE_CLIENT_ID is empty!"
|
|
|
|
else
|
|
|
|
rlLogInfo "AZURE_CLIENT_ID is configured"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$AZURE_SECRET" ]; then
|
|
|
|
rlFail "AZURE_SECRET is empty!"
|
|
|
|
else
|
|
|
|
rlLogInfo "AZURE_SECRET is configured"
|
|
|
|
fi
|
|
|
|
|
|
|
|
export AZURE_RESOURCE_GROUP="${AZURE_RESOURCE_GROUP:-composer}"
|
|
|
|
rlLogInfo "AZURE_RESOURCE_GROUP=$AZURE_RESOURCE_GROUP"
|
|
|
|
|
|
|
|
export AZURE_STORAGE_ACCOUNT="${AZURE_STORAGE_ACCOUNT:-composerredhat}"
|
|
|
|
rlLogInfo "AZURE_STORAGE_ACCOUNT=$AZURE_STORAGE_ACCOUNT"
|
|
|
|
|
|
|
|
export AZURE_STORAGE_CONTAINER="${AZURE_STORAGE_CONTAINER:-composerredhat}"
|
|
|
|
rlLogInfo "AZURE_STORAGE_CONTAINER=$AZURE_STORAGE_CONTAINER"
|
|
|
|
|
2018-12-17 11:04:57 +00:00
|
|
|
if ! rlCheckRpm "python2-pip"; then
|
|
|
|
rlRun -t -c "yum -y install python2-pip"
|
|
|
|
rlAssertRpm python2-pip
|
2018-12-12 11:38:09 +00:00
|
|
|
fi
|
|
|
|
|
2019-08-01 11:45:56 +00:00
|
|
|
rlAssertRpm python-virtualenv
|
|
|
|
rlRun -t -c "virtualenv $VENV"
|
|
|
|
source $VENV/bin/activate
|
2019-01-25 13:32:03 +00:00
|
|
|
|
2019-01-03 11:11:12 +00:00
|
|
|
rlRun -t -c "pip install --upgrade pip setuptools"
|
2018-12-18 11:00:16 +00:00
|
|
|
rlRun -t -c "pip install ansible[azure] futures"
|
2018-12-12 11:38:09 +00:00
|
|
|
rlPhaseEnd
|
|
|
|
|
|
|
|
rlPhaseStartTest "compose start"
|
2019-01-25 16:53:50 +00:00
|
|
|
rlAssertEquals "SELinux operates in enforcing mode" "$(getenforce)" "Enforcing"
|
2018-12-12 11:38:09 +00:00
|
|
|
UUID=`$CLI compose start example-http-server vhd`
|
|
|
|
rlAssertEquals "exit code should be zero" $? 0
|
|
|
|
|
|
|
|
UUID=`echo $UUID | cut -f 2 -d' '`
|
|
|
|
rlPhaseEnd
|
|
|
|
|
|
|
|
rlPhaseStartTest "compose finished"
|
|
|
|
if [ -n "$UUID" ]; then
|
2019-06-17 12:35:31 +00:00
|
|
|
until $CLI compose details $UUID | grep 'FINISHED\|FAILED'; do
|
2018-12-12 11:38:09 +00:00
|
|
|
rlLogInfo "Waiting for compose to finish ..."
|
|
|
|
sleep 30
|
|
|
|
done;
|
|
|
|
else
|
|
|
|
rlFail "Compose UUID is empty!"
|
|
|
|
fi
|
|
|
|
rlPhaseEnd
|
|
|
|
|
|
|
|
rlPhaseStartTest "Upload image to Azure"
|
|
|
|
rlRun -t -c "$CLI compose image $UUID"
|
|
|
|
IMAGE="$UUID-disk.vhd"
|
|
|
|
OS_IMAGE_NAME="Composer-$UUID-Automated-Import"
|
|
|
|
|
|
|
|
rlRun -t -c "ansible localhost -m azure_rm_storageblob -a \
|
|
|
|
'resource_group=$AZURE_RESOURCE_GROUP \
|
|
|
|
storage_account_name=$AZURE_STORAGE_ACCOUNT \
|
|
|
|
container=$AZURE_STORAGE_CONTAINER \
|
|
|
|
blob=$IMAGE src=$IMAGE blob_type=page'"
|
|
|
|
|
|
|
|
# create image from blob
|
|
|
|
rlRun -t -c "ansible localhost -m azure_rm_image -a \
|
|
|
|
'resource_group=$AZURE_RESOURCE_GROUP name=$OS_IMAGE_NAME os_type=Linux location=eastus \
|
|
|
|
source=https://$AZURE_STORAGE_ACCOUNT.blob.core.windows.net/$AZURE_STORAGE_CONTAINER/$IMAGE'"
|
|
|
|
rlPhaseEnd
|
|
|
|
|
|
|
|
rlPhaseStartTest "Start VM instance"
|
|
|
|
VM_NAME="Composer-Auto-VM-$UUID"
|
|
|
|
|
|
|
|
SSH_KEY_DIR=`mktemp -d /tmp/composer-ssh-keys.XXXXXX`
|
|
|
|
rlRun -t -c "ssh-keygen -t rsa -N '' -f $SSH_KEY_DIR/id_rsa"
|
|
|
|
SSH_PUB_KEY=`cat $SSH_KEY_DIR/id_rsa.pub`
|
|
|
|
|
2019-02-05 16:08:10 +00:00
|
|
|
now=$(date -u '+%FT%T')
|
|
|
|
|
2018-12-12 11:38:09 +00:00
|
|
|
TMP_DIR=`mktemp -d /tmp/composer-azure.XXXXX`
|
|
|
|
cat > $TMP_DIR/azure-playbook.yaml << __EOF__
|
|
|
|
---
|
|
|
|
- hosts: localhost
|
|
|
|
connection: local
|
|
|
|
tasks:
|
|
|
|
- name: Create a VM
|
|
|
|
azure_rm_virtualmachine:
|
|
|
|
resource_group: $AZURE_RESOURCE_GROUP
|
|
|
|
name: $VM_NAME
|
|
|
|
vm_size: Standard_B2s
|
|
|
|
location: eastus
|
|
|
|
admin_username: azure-user
|
|
|
|
ssh_password_enabled: false
|
|
|
|
ssh_public_keys:
|
|
|
|
- path: /home/azure-user/.ssh/authorized_keys
|
|
|
|
key_data: "$SSH_PUB_KEY"
|
|
|
|
image:
|
|
|
|
name: $OS_IMAGE_NAME
|
|
|
|
resource_group: $AZURE_RESOURCE_GROUP
|
2019-02-05 16:08:10 +00:00
|
|
|
tags:
|
|
|
|
"first_seen": "$now"
|
2019-02-05 16:09:29 +00:00
|
|
|
storage_account_name: $AZURE_STORAGE_ACCOUNT
|
2018-12-12 11:38:09 +00:00
|
|
|
__EOF__
|
|
|
|
|
|
|
|
rlRun -t -c "ansible-playbook $TMP_DIR/azure-playbook.yaml"
|
|
|
|
|
|
|
|
response=`ansible localhost -m azure_rm_virtualmachine -a "resource_group=$AZURE_RESOURCE_GROUP name=$VM_NAME"`
|
|
|
|
rlAssert0 "Received VM info successfully" $?
|
|
|
|
rlLogInfo "$response"
|
|
|
|
|
|
|
|
IP_ADDRESS=`echo "$response" | grep '"ipAddress":' | cut -f4 -d'"'`
|
|
|
|
rlLogInfo "Running instance IP_ADDRESS=$IP_ADDRESS"
|
|
|
|
|
|
|
|
rlLogInfo "Waiting 60sec for instance to initialize ..."
|
|
|
|
sleep 60
|
|
|
|
rlPhaseEnd
|
|
|
|
|
|
|
|
rlPhaseStartTest "Verify VM instance"
|
2019-04-17 14:12:12 +00:00
|
|
|
# run generic tests to verify the instance
|
|
|
|
verify_image azure-user "$IP_ADDRESS" "-i $SSH_KEY_DIR/id_rsa"
|
2018-12-12 11:38:09 +00:00
|
|
|
rlPhaseEnd
|
|
|
|
|
|
|
|
rlPhaseStartCleanup
|
|
|
|
rlRun -t -c "ansible localhost -m azure_rm_virtualmachine -a 'resource_group=$AZURE_RESOURCE_GROUP name=$VM_NAME location=eastus state=absent'"
|
|
|
|
rlRun -t -c "ansible localhost -m azure_rm_image -a 'resource_group=$AZURE_RESOURCE_GROUP name=$OS_IMAGE_NAME state=absent'"
|
|
|
|
rlRun -t -c "ansible localhost -m azure_rm_storageblob -a 'resource_group=$AZURE_RESOURCE_GROUP storage_account_name=$AZURE_STORAGE_ACCOUNT container=$AZURE_STORAGE_CONTAINER blob=$IMAGE state=absent'"
|
|
|
|
rlRun -t -c "$CLI compose delete $UUID"
|
2019-08-01 11:45:56 +00:00
|
|
|
rlRun -t -c "rm -rf $IMAGE $SSH_KEY_DIR $TMP_DIR $VENV"
|
2018-12-12 11:38:09 +00:00
|
|
|
rlPhaseEnd
|
|
|
|
|
|
|
|
rlJournalEnd
|
|
|
|
rlJournalPrintText
|