Simple VM booting script on a target CMP node
- integrated with 'prepare.sh'
- using separate user and project
- autodetect of vars and opts
- can be updated with different actions
available in 'openstack server --help'
Change-Id: I4e5621ff8f577d5c414227a311f469d40f907732
Related-PROD: PROD-33607
diff --git a/scripts/cmp_check.sh b/scripts/cmp_check.sh
new file mode 100644
index 0000000..5426f65
--- /dev/null
+++ b/scripts/cmp_check.sh
@@ -0,0 +1,80 @@
+#!/bin/bash
+cmp_name=${1}
+vmname=vm_${1}_01
+
+function waitfor () {
+ counter=0
+ while [ ${counter} -lt 6 ]; do
+ ids=( $(openstack server list --name ${vmname} --status ${1} -f value -c ID) )
+ if [ ${#ids[@]} -eq 0 ]; then
+ sleep 5
+ counter=$((counter + 1))
+ else
+ printf "# '${vmname}' reached status ${1}\n"
+ break
+ fi
+ done
+}
+
+function getid() {
+ openstack server list --name ${1} -f value -c ID
+}
+
+function vm_create() {
+ set -x
+ openstack server create --nic net-id=${fixed_net_left_id} --image ${cirros35_id} --flavor ${flavor_tiny_id} --key-name ${keypair_id} --security-group ${secgroup_all_id} --availability-zone nova:${1} ${2} 2>&1 >/dev/nul
+ set +x
+}
+
+function vm_action() {
+ openstack server ${1} ${2}
+}
+
+# temp file for commands
+cmds=$(mktemp)
+#trap "rm -f ${cmds}" EXIT
+#echo "# Using tempfile: '${cmds}'"
+
+# trap "source adminrc" EXIT
+
+echo "### CMP check for booting VMs"
+if [ ! -f cvp.manifest ]; then
+ echo "ERROR: No cvp.manifest file detected. Consider running prepare.sh"
+ exit 1
+else
+ source cvp.manifest
+fi
+
+if [ -z ${cmp_name} ]; then
+ echo "CMP node name not specified"
+ exit 1
+fi
+
+echo "# Sourcing cvprc"
+source cvprc
+
+echo "# Checking for previously created VMs"
+vmid=( $(getid ${vmname}) )
+if [ ${#vmid[@]} -ne 0 ]; then
+ echo "# Found previously created VMs. Cleaning."
+ vm_action delete ${vmid[@]}
+else
+ echo "# ...no VMs found"
+fi
+
+printf "### Checking '${cmp_name}': Create, Pause, Unpause, Delete a VM\n"
+echo "# ... creating VM on ${cmp_name} using name of ${vmname}"
+vm_create ${cmp_name} ${vmname}
+waitfor ACTIVE
+vmid=$(openstack server list --name ${vmname} -f value -c ID)
+
+vm_action pause ${vmid}
+waitfor PAUSED
+vm_action unpause ${vmid}
+waitfor ACTIVE
+
+echo "# ... deleting create VM (${vmid})"
+vm_action delete ${vmid}
+
+printf "\n# Done checking ${cmp_name}\n"
+