OpenStack in a snap!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

197 lines
6.1 KiB

  1. #!/bin/bash
  2. ##############################################################################
  3. #
  4. # This is a "basic" test script for Microstack. It will install the
  5. # microstack snap, spin up a test instance, and verify that the test
  6. # instance is accessible, and can access the Internet.
  7. #
  8. # The basic test accepts two command line arguments:
  9. #
  10. # -u <channel> # First installs a released snap from the named
  11. # # channel, in order to test basic upgrade functionality.
  12. # -m # Run tests in a multipass machine.
  13. # -d <distro> # Ubuntu distro of the multipass machine to run tests
  14. # # within. Defaults to bionic.
  15. #
  16. ##############################################################################
  17. # Configuration and checks
  18. set -e
  19. export PATH=/snap/bin:$PATH
  20. UPGRADE_FROM="none"
  21. FORCE_QEMU=false
  22. PREFIX=""
  23. DISTRO="bionic"
  24. HORIZON_IP="10.20.20.1"
  25. while getopts u:d:mq option
  26. do
  27. case "${option}"
  28. in
  29. u) UPGRADE_FROM=${OPTARG};;
  30. q) FORCE_QEMU=true;;
  31. m) PREFIX="multipass";;
  32. esac
  33. done
  34. if [ ! -f microstack_stein_amd64.snap ]; then
  35. echo "microstack_stein_amd64.snap not found."
  36. echo "Please run snapcraft before executing the tests."
  37. exit 1
  38. fi
  39. # Functions
  40. dump_logs () {
  41. export DUMP_DIR=/tmp
  42. if [ $(whoami) == 'zuul' ]; then
  43. export DUMP_DIR="/home/zuul/zuul-output/logs";
  44. fi
  45. $PREFIX sudo journalctl -xe --no-pager > /tmp/journalctl.output
  46. $PREFIX sudo tar cvzf $DUMP_DIR/dump.tar.gz \
  47. /var/snap/microstack/common/log \
  48. /var/log/syslog \
  49. /tmp/journalctl.output
  50. if [[ $PREFIX == *"multipass"* ]]; then
  51. multipass copy-files $MACHINE:/tmp/dump.tar.gz .
  52. fi
  53. }
  54. # Setup
  55. echo "++++++++++++++++++++++++++++++++++++++++++++++++++"
  56. echo "++ Starting tests on localhost ++"
  57. echo "++ Upgrade from: $UPGRADE_FROM ++"
  58. echo "++++++++++++++++++++++++++++++++++++++++++++++++++"
  59. # Possibly run in a multipass machine
  60. if [ "$PREFIX" == "multipass" ]; then
  61. sudo snap install --classic --edge multipass
  62. which petname || sudo snap install petname
  63. MACHINE=$(petname)
  64. PREFIX="multipass exec $MACHINE --"
  65. multipass launch --cpus 2 --mem 16G $DISTRO --name $MACHINE
  66. multipass copy-files microstack_stein_amd64.snap $MACHINE:
  67. HORIZON_IP=`multipass info $MACHINE | grep IPv4 | cut -d":" -f2 \
  68. | tr -d '[:space:]'`
  69. fi
  70. # Possibly install a release of the snap before running a test.
  71. if [ "${UPGRADE_FROM}" != "none" ]; then
  72. $PREFIX sudo snap install --classic --${UPGRADE_FROM} microstack
  73. fi
  74. # Install the snap under test -- try again if the machine is not yet ready.
  75. $PREFIX sudo snap install --classic --dangerous microstack*.snap
  76. $PREFIX sudo /snap/bin/microstack.init
  77. # Comment out the above and uncomment below to install the version of
  78. # the snap from the store.
  79. # TODO: add this as a flag.
  80. # $PREFIX sudo snap install --classic --edge microstack
  81. # If kvm processor extensions not supported, switch to qemu
  82. # TODO: just do this in the install step of the snap
  83. if ! [ $($PREFIX egrep "vmx|svm" /proc/cpuinfo | wc -l) -gt 0 ]; then
  84. FORCE_QEMU=true;
  85. fi
  86. if [ "$FORCE_QEMU" == "true" ]; then
  87. cat<<EOF > /tmp/hypervisor.conf
  88. [DEFAULT]
  89. compute_driver = libvirt.LibvirtDriver
  90. [workarounds]
  91. disable_rootwrap = True
  92. [libvirt]
  93. virt_type = qemu
  94. cpu_mode = host-model
  95. EOF
  96. if [[ $PREFIX == *"multipass"* ]]; then
  97. multipass copy-files /tmp/hypervisor.conf $MACHINE:/tmp/hypervisor.conf
  98. fi
  99. $PREFIX sudo cp /tmp/hypervisor.conf \
  100. /var/snap/microstack/common/etc/nova/nova.conf.d/hypervisor.conf
  101. $PREFIX sudo snap restart microstack
  102. fi
  103. # Run microstack.launch
  104. $PREFIX /snap/bin/microstack.launch breakfast || (dump_logs && exit 1)
  105. # Verify that endpoints are setup correctly
  106. # List of endpoints should contain 10.20.20.1
  107. if ! $PREFIX /snap/bin/microstack.openstack endpoint list | grep "10.20.20.1"; then
  108. echo "Endpoints are not set to 10.20.20.1!";
  109. exit 1;
  110. fi
  111. # List of endpoints should not contain localhost
  112. if $PREFIX /snap/bin/microstack.openstack endpoint list | grep "localhost"; then
  113. echo "Endpoints are not set to 10.20.20.1!";
  114. exit 1;
  115. fi
  116. # Verify that microstack.launch completed
  117. IP=$($PREFIX /snap/bin/microstack.openstack server list | grep breakfast | cut -d" " -f9)
  118. echo "Waiting for ping..."
  119. PINGS=1
  120. MAX_PINGS=40 # We might sometimes be testing qemu emulation, so we
  121. # want to give this some time ...
  122. until $PREFIX ping -c 1 $IP &>/dev/null; do
  123. PINGS=$(($PINGS + 1));
  124. if test $PINGS -gt $MAX_PINGS; then
  125. echo "Unable to ping machine!";
  126. exit 1;
  127. fi
  128. done;
  129. ATTEMPTS=1
  130. MAX_ATTEMPTS=40 # See above for note about qemu
  131. USERNAME=$($PREFIX whoami | tr -d '\r') # Possibly get username from
  132. # remote host, for use in
  133. # composing home dir below.
  134. until $PREFIX ssh -oStrictHostKeyChecking=no -i \
  135. /home/$USERNAME/.ssh/id_microstack cirros@$IP -- \
  136. ping -c 1 91.189.94.250; do
  137. ATTEMPTS=$(($ATTEMPTS + 1));
  138. if test $ATTEMPTS -gt $MAX_ATTEMPTS; then
  139. echo "Unable to access Internet from machine!";
  140. exit 1;
  141. fi
  142. sleep 5
  143. done;
  144. echo "++++++++++++++++++++++++++++++++++++++++++++++++++"
  145. echo "++ Running Horizon GUI tests ++"
  146. echo "++++++++++++++++++++++++++++++++++++++++++++++++++"
  147. export HORIZON_IP
  148. if [[ $PREFIX == *"multipass"* ]]; then
  149. echo "Opening $HORIZON_IP:80 up to the outside world."
  150. cat<<EOF > /tmp/_10_hosts.py
  151. # Allow all hosts to connect to this machine
  152. ALLOWED_HOSTS = ['*',]
  153. EOF
  154. multipass copy-files /tmp/_10_hosts.py $MACHINE:/tmp/_10_hosts.py
  155. $PREFIX sudo cp /tmp/_10_hosts.py \
  156. /var/snap/microstack/common/etc/horizon/local_settings.d/
  157. $PREFIX sudo snap restart microstack
  158. fi
  159. tests/test_horizonlogin.py
  160. echo "Horizon tests complete!."
  161. unset HORIZON_IP
  162. # Cleanup
  163. echo "++++++++++++++++++++++++++++++++++++++++++++++++++"
  164. echo "++ Completed tests. Cleaning up ++"
  165. echo "++++++++++++++++++++++++++++++++++++++++++++++++++"
  166. unset IP
  167. if [[ $PREFIX == *"multipass"* ]]; then
  168. sudo multipass delete $MACHINE
  169. sudo multipass purge
  170. else
  171. sudo snap remove --purge microstack
  172. fi