2018-11-16 06:34:15 +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-02 13:20:42 +00:00
|
|
|
set -e
|
|
|
|
|
2018-11-16 06:34:15 +00:00
|
|
|
. /usr/share/beakerlib/beakerlib.sh
|
2019-05-21 13:39:33 +00:00
|
|
|
. $(dirname $0)/lib/lib.sh
|
2018-11-16 06:34:15 +00:00
|
|
|
|
2019-03-08 10:29:11 +00:00
|
|
|
CLI="${CLI:-./src/bin/composer-cli}"
|
2018-11-16 06:34:15 +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-11-16 06:34:15 +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"
|
|
|
|
|
|
|
|
if ! rlCheckRpm "python3-pip"; then
|
|
|
|
rlRun -t -c "dnf -y install python3-pip"
|
|
|
|
rlAssertRpm python3-pip
|
|
|
|
fi
|
|
|
|
|
|
|
|
rlRun -t -c "pip3 install ansible[azure]"
|
|
|
|
rlPhaseEnd
|
|
|
|
|
|
|
|
rlPhaseStartTest "compose start"
|
2019-01-25 16:53:50 +00:00
|
|
|
rlAssertEquals "SELinux operates in enforcing mode" "$(getenforce)" "Enforcing"
|
2018-11-16 06:34:15 +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"
|
2019-09-06 16:56:19 +00:00
|
|
|
wait_for_compose $UUID
|
2018-11-16 06:34:15 +00:00
|
|
|
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"
|
|
|
|
|
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"
|
|
|
|
SSH_PUB_KEY=`cat $SSH_KEY_DIR/id_rsa.pub`
|
2018-11-16 06:34:15 +00:00
|
|
|
|
2019-02-05 16:08:10 +00:00
|
|
|
now=$(date -u '+%FT%T')
|
|
|
|
|
2018-12-06 13:35:04 +00:00
|
|
|
TMP_DIR=`mktemp -d /tmp/composer-azure.XXXXX`
|
|
|
|
cat > $TMP_DIR/azure-playbook.yaml << __EOF__
|
2018-11-16 06:34:15 +00:00
|
|
|
---
|
|
|
|
- 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-11-16 06:34:15 +00:00
|
|
|
__EOF__
|
|
|
|
|
2018-12-06 13:35:04 +00:00
|
|
|
rlRun -t -c "ansible-playbook $TMP_DIR/azure-playbook.yaml"
|
2018-11-16 06:34:15 +00:00
|
|
|
|
|
|
|
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"
|
2020-01-13 16:04:19 +00:00
|
|
|
# run generic tests to verify the instance and check if cloud-init is installed and running
|
2019-04-17 14:12:12 +00:00
|
|
|
verify_image azure-user "$IP_ADDRESS" "-i $SSH_KEY_DIR/id_rsa"
|
2020-01-13 16:04:19 +00:00
|
|
|
rlRun -t -c "ssh -o StrictHostKeyChecking=no -i $SSH_KEY_DIR/id_rsa azure-user@$IP_ADDRESS 'rpm -q cloud-init'"
|
|
|
|
rlRun -t -c "ssh -o StrictHostKeyChecking=no -i $SSH_KEY_DIR/id_rsa azure-user@$IP_ADDRESS 'systemctl status cloud-init'"
|
2018-11-16 06:34:15 +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"
|
2018-12-06 13:35:04 +00:00
|
|
|
rlRun -t -c "rm -rf $IMAGE $SSH_KEY_DIR $TMP_DIR"
|
2018-11-16 06:34:15 +00:00
|
|
|
rlPhaseEnd
|
|
|
|
|
|
|
|
rlJournalEnd
|
|
|
|
rlJournalPrintText
|