Install utility to deploy OpenStack on multiple hosts.
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.

run_tests.sh 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. #!/bin/bash -ex
  2. # Copyright 2015 Red Hat, Inc.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  5. # not use this file except in compliance with the License. You may obtain
  6. # a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. # License for the specific language governing permissions and limitations
  14. # under the License.
  15. export PATH=$PATH:/usr/local/sbin:/usr/sbin
  16. SCENARIO=${SCENARIO:-scenario001}
  17. # We could want to override the default repositories or install behavior
  18. INSTALL_FROM_SOURCE=${INSTALL_FROM_SOURCE:-true}
  19. MANAGE_REPOS=${MANAGE_REPOS:-true}
  20. DELOREAN=${DELOREAN:-https://trunk.rdoproject.org/centos7-master/current-passed-ci/delorean.repo}
  21. DELOREAN_DEPS=${DELOREAN_DEPS:-https://trunk.rdoproject.org/centos7-master/delorean-deps.repo}
  22. GIT_BASE_URL=${GIT_BASE_URL:-https://git.openstack.org}
  23. ADDITIONAL_ARGS=${ADDITIONAL_ARGS:-}
  24. SELINUX_ENFORCING=${SELINUX_ENFORCING:-true}
  25. # If logs should be retrieved automatically
  26. COPY_LOGS=${COPY_LOGS:-true}
  27. # Let's add an option for a secondary node, to act as a compute
  28. CONTROLLER_NODE=${CONTROLLER_NODE:-}
  29. COMPUTE_NODE=${COMPUTE_NODE:-}
  30. # Use dnf as package manager if it exist
  31. type -p dnf && export PKG_MGR=dnf || export PKG_MGR=yum
  32. # Install external Puppet modules with r10k
  33. # Uses the following variables:
  34. #
  35. # - ``GEM_BIN_DIR`` must be set to Gem bin directory
  36. # - ``PUPPETFILE_DIR`` must be set to Puppet modules directory
  37. install_external() {
  38. $SUDO ${GEM_BIN_DIR}r10k puppetfile install -v --moduledir ${PUPPETFILE_DIR} --puppetfile Puppetfile1
  39. }
  40. # Install Puppet OpenStack modules with zuul-cloner
  41. # Uses the following variables:
  42. #
  43. # - ``PUPPETFILE_DIR`` must be set to Puppet modules directory
  44. # - ``ZUUL_REF`` must be set to Zuul ref. Fallback to 'None'.
  45. # - ``ZUUL_BRANCH`` must be set to Zuul branch. Fallback to 'master'.
  46. install_openstack() {
  47. cat > clonemap.yaml <<EOF
  48. clonemap:
  49. - name: '(.*?)/puppet-(.*)'
  50. dest: '$PUPPETFILE_DIR/\2'
  51. EOF
  52. # Periodic jobs run without ref on master
  53. ZUUL_REF=${ZUUL_REF:-None}
  54. ZUUL_BRANCH=${ZUUL_BRANCH:-master}
  55. GIT_BASE_URL=${GIT_BASE_URL:-https://git.openstack.org}
  56. local project_names=$(awk '{ if ($1 == ":git") print $3 }' \
  57. Puppetfile0 | tr -d "'," | cut -d '/' -f 4- | xargs
  58. )
  59. $SUDO /usr/zuul-env/bin/zuul-cloner -m clonemap.yaml \
  60. --cache-dir /opt/git \
  61. --zuul-ref $ZUUL_REF \
  62. --zuul-branch $ZUUL_BRANCH \
  63. https://git.openstack.org $project_names
  64. }
  65. # Install all Puppet modules with r10k
  66. # Uses the following variables:
  67. #
  68. # - ``GEM_BIN_DIR`` must be set to Gem bin directory
  69. install_all() {
  70. $SUDO ${GEM_BIN_DIR}r10k puppetfile install -v --puppetfile Puppetfile
  71. }
  72. # Install Puppet OpenStack modules and dependencies by using
  73. # zuul-cloner or r10k.
  74. # Uses the following variables:
  75. #
  76. # - ``PUPPETFILE_DIR`` must be set to Puppet modules directory
  77. # - ``ZUUL_REF`` must be set to Zuul ref
  78. # - ``ZUUL_BRANCH`` must be set to Zuul branch
  79. install_modules() {
  80. # If zuul-cloner is there, have it install modules using zuul refs
  81. if [ -e /usr/zuul-env/bin/zuul-cloner ] ; then
  82. csplit Puppetfile /'Non-OpenStack modules'/ \
  83. --prefix Puppetfile \
  84. --suffix '%d'
  85. install_external
  86. install_openstack
  87. else
  88. install_all
  89. fi
  90. # Copy the Packstack Puppet module
  91. $SUDO cp -r packstack/puppet/modules/packstack ${PUPPETFILE_DIR}
  92. }
  93. if [ $(id -u) != 0 ]; then
  94. SUDO='sudo -E'
  95. # Packstack will connect as root to localhost, set-up the keypair and sshd
  96. if [ ! -f ~/.ssh/id_rsa ]; then
  97. ssh-keygen -t rsa -C "packstack-integration-test" -N "" -f ~/.ssh/id_rsa
  98. fi
  99. $SUDO mkdir -p /root/.ssh
  100. cat ~/.ssh/id_rsa.pub | $SUDO tee -a /root/.ssh/authorized_keys
  101. $SUDO chmod 0600 /root/.ssh/authorized_keys
  102. $SUDO sed -i 's/^PermitRootLogin no/PermitRootLogin without-password/g' /etc/ssh/sshd_config
  103. $SUDO service sshd restart
  104. fi
  105. # Make swap configuration consistent
  106. # TODO: REMOVE ME
  107. # https://review.openstack.org/#/c/300122/
  108. source ./tools/fix_disk_layout.sh
  109. # Bump ulimit to avoid too many open file errors
  110. echo "${USER} soft nofile 65536" | $SUDO tee -a /etc/security/limits.conf
  111. echo "${USER} hard nofile 65536" | $SUDO tee -a /etc/security/limits.conf
  112. echo "root soft nofile 65536" | $SUDO tee -a /etc/security/limits.conf
  113. echo "root hard nofile 65536" | $SUDO tee -a /etc/security/limits.conf
  114. # Set SELinux to enforcing/permissive as needed
  115. if [ "${SELINUX_ENFORCING}" = true ]; then
  116. $SUDO setenforce 1
  117. else
  118. $SUDO setenforce 0
  119. fi
  120. # Setup repositories
  121. if [ "${MANAGE_REPOS}" = true ]; then
  122. $SUDO curl -L ${DELOREAN} -o /etc/yum.repos.d/delorean.repo
  123. $SUDO curl -L ${DELOREAN_DEPS} -o /etc/yum.repos.d/delorean-deps.repo
  124. $SUDO $PKG_MGR update -y
  125. fi
  126. # Install dependencies
  127. $SUDO $PKG_MGR -y install puppet \
  128. iproute \
  129. iptables \
  130. iptables-services \
  131. dstat \
  132. openssl-devel \
  133. libffi-devel \
  134. libxml2-devel \
  135. libxslt-devel \
  136. libyaml-devel \
  137. ruby-devel \
  138. openstack-selinux \
  139. policycoreutils \
  140. rubygems \
  141. wget \
  142. gettext \
  143. diffstat \
  144. doxygen \
  145. patch \
  146. patchutils \
  147. subversion \
  148. systemtap
  149. # Some dependencies are not installed on RHEL/CentOS 8, or are renamed
  150. OS_NAME=$(facter operatingsystem)
  151. OS_VERSION=$(facter operatingsystemmajrelease)
  152. if ([ "$OS_NAME" = "RedHat" ] || [ "$OS_NAME" = "CentOS" ]) && [ $OS_VERSION -gt 7 ]; then
  153. $SUDO $PKG_MGR -y install python3-setuptools \
  154. python3-devel
  155. else
  156. $SUDO $PKG_MGR -y install python-setuptools \
  157. python-devel \
  158. yum-plugin-priorities
  159. fi
  160. # Don't assume pip is installed
  161. which pip3 && PIP=pip3
  162. if [ -z $PIP ]; then
  163. if ([ "$OS_NAME" = "RedHat" ] || [ "$OS_NAME" = "CentOS" ]) && [ $OS_VERSION -gt 7 ]; then
  164. $SUDO $PKG_MGR -y install python3-pip
  165. PIP=pip3
  166. else
  167. which pip || $SUDO easy_install pip
  168. PIP=pip
  169. fi
  170. fi
  171. # Try to use pre-cached cirros images, if available, otherwise download them
  172. rm -rf /tmp/cirros
  173. mkdir /tmp/cirros
  174. # Select cirros arch and image version based on system architecture, and export them for use by the test scenarios.
  175. # As of April 2018, Packstack on x86 has kernel panics with the 0.4.0 cirros image. However, ppc64le requires it.
  176. # As such, for now, we set x86 boxes to use version 0.3.5, and ppc64le boxes to use 0.4.0.
  177. export CIRROS_ARCH="$(uname -p)"
  178. case $CIRROS_ARCH in
  179. x86_64)
  180. export CIRROS_VERSION="0.3.5"
  181. ;;
  182. ppc64le)
  183. export CIRROS_VERSION="0.4.0"
  184. ;;
  185. esac
  186. if [ -f ~/cache/files/cirros-$CIRROS_VERSION-$CIRROS_ARCH-uec.tar.gz ]; then
  187. tar -xzvf ~/cache/files/cirros-$CIRROS_VERSION-$CIRROS_ARCH-uec.tar.gz -C /tmp/cirros/
  188. else
  189. echo "No pre-cached uec archive found, downloading..."
  190. wget --tries=10 http://download.cirros-cloud.net/$CIRROS_VERSION/cirros-$CIRROS_VERSION-$CIRROS_ARCH-uec.tar.gz -P /tmp/cirros/
  191. tar -xzvf /tmp/cirros/cirros-$CIRROS_VERSION-$CIRROS_ARCH-uec.tar.gz -C /tmp/cirros/
  192. fi
  193. if [ -f ~/cache/files/cirros-$CIRROS_VERSION-$CIRROS_ARCH-disk.img ]; then
  194. cp -p ~/cache/files/cirros-$CIRROS_VERSION-$CIRROS_ARCH-disk.img /tmp/cirros/
  195. else
  196. echo "No pre-cached disk image found, downloading..."
  197. wget --tries=10 http://download.cirros-cloud.net/$CIRROS_VERSION/cirros-$CIRROS_VERSION-$CIRROS_ARCH-disk.img -P /tmp/cirros/
  198. fi
  199. echo "Using pre-cached images:"
  200. find /tmp/cirros -type f -printf "%m %n %u %g %s %t" -exec md5sum \{\} \;
  201. # TO-DO: Packstack should handle Hiera and Puppet configuration, so that it works
  202. # no matter the environment
  203. $SUDO su -c 'cat > /etc/puppet/puppet.conf <<EOF
  204. [main]
  205. logdir = /var/log/puppet
  206. rundir = /var/run/puppet
  207. ssldir = $vardir/ssl
  208. hiera_config = /etc/puppet/hiera.yaml
  209. [agent]
  210. classfile = $vardir/classes.txt
  211. localconfig = $vardir/localconfig
  212. EOF'
  213. $SUDO su -c 'cat > /etc/puppet/hiera.yaml <<EOF
  214. ---
  215. :backends:
  216. - yaml
  217. :yaml:
  218. :datadir: /placeholder
  219. :hierarchy:
  220. - common
  221. - defaults
  222. - "%{clientcert}"
  223. - "%{environment}"
  224. - global
  225. EOF'
  226. # To make sure wrong config files are not used
  227. if [ -d /home/jenkins/.puppet ]; then
  228. $SUDO rm -f /home/jenkins/.puppet
  229. fi
  230. $SUDO puppet config set hiera_config /etc/puppet/hiera.yaml
  231. # Setup dstat for resource usage tracing
  232. if type "dstat" 2>/dev/null; then
  233. $SUDO dstat -tcmndrylpg \
  234. --top-cpu-adv \
  235. --top-io-adv \
  236. --nocolor | $SUDO tee -a /var/log/dstat.log > /dev/null &
  237. fi
  238. # Setup packstack
  239. if [ "${INSTALL_FROM_SOURCE}" = true ]; then
  240. $SUDO $PIP install --prefix=/usr .
  241. # In Fedora when running with sudo gems are installed at /usr/local/bin/ even when GEM_HOME/GEM_BIN_DIR are set
  242. if [ "${PKG_MGR}" = "dnf" ]; then
  243. export GEM_BIN_DIR=/usr/local/bin/
  244. else
  245. export GEM_BIN_DIR=/tmp/packstackgems/bin/
  246. fi
  247. export PUPPETFILE_DIR=/usr/share/openstack-puppet/modules
  248. export GEM_HOME=/tmp/packstackgems
  249. $SUDO gem install r10k -v 2.6.4 --no-ri --no-rdoc
  250. # make sure there is no puppet module pre-installed
  251. $SUDO rm -rf "${PUPPETFILE_DIR:?}/"*
  252. install_modules
  253. else
  254. $SUDO $PKG_MGR -y install openstack-packstack
  255. fi
  256. # Make sure there are no other puppet modules in the system (happens in gate)
  257. $SUDO rm -rf /etc/puppet/modules/*
  258. # Make sure the fqdn is associated to the IP in /etc/hosts
  259. # Needed for Horizon SSL tests in Tempest
  260. echo -e "\n127.0.0.1 $(facter fqdn)" | $SUDO tee -a /etc/hosts
  261. # Generate configuration from selected scenario and run it
  262. source ./tests/${SCENARIO}.sh
  263. result=$?
  264. # Print output and generate subunit if results exist
  265. if [ -d /var/lib/tempest ]; then
  266. # FIXME(jpena): Work around Fedora image issues with umask
  267. $SUDO chown -R $USER /var/lib/tempest
  268. pushd /var/lib/tempest
  269. if [ -d .testrepository ]; then
  270. $SUDO /usr/bin/testr last || true
  271. $SUDO bash -c "/usr/bin/testr last --subunit > /var/tmp/packstack/latest/testrepository.subunit" || true
  272. elif [ -d .stestr ]; then
  273. $SUDO /usr/bin/stestr last || true
  274. $SUDO bash -c "/usr/bin/stestr last --subunit > /var/tmp/packstack/latest/testrepository.subunit" || true
  275. fi
  276. popd
  277. fi
  278. if [ "${COPY_LOGS}" = true ]; then
  279. source ./tools/copy-logs.sh
  280. recover_default_logs
  281. fi
  282. if [ "${FAILURE}" = true ]; then
  283. exit 1
  284. fi
  285. exit $result