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.

302 lines
10KB

  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-rocky/current-passed-ci/delorean.repo}
  21. DELOREAN_DEPS=${DELOREAN_DEPS:-https://trunk.rdoproject.org/centos7-rocky/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. # Install external Puppet modules with r10k
  31. # Uses the following variables:
  32. #
  33. # - ``GEM_BIN_DIR`` must be set to Gem bin directory
  34. # - ``PUPPETFILE_DIR`` must be set to Puppet modules directory
  35. install_external() {
  36. $SUDO ${GEM_BIN_DIR}r10k puppetfile install -v --moduledir ${PUPPETFILE_DIR} --puppetfile Puppetfile1
  37. }
  38. # Install Puppet OpenStack modules with zuul-cloner
  39. # Uses the following variables:
  40. #
  41. # - ``PUPPETFILE_DIR`` must be set to Puppet modules directory
  42. # - ``ZUUL_REF`` must be set to Zuul ref. Fallback to 'None'.
  43. # - ``ZUUL_BRANCH`` must be set to Zuul branch. Fallback to 'master'.
  44. install_openstack() {
  45. cat > clonemap.yaml <<EOF
  46. clonemap:
  47. - name: '(.*?)/puppet-(.*)'
  48. dest: '$PUPPETFILE_DIR/\2'
  49. EOF
  50. # Periodic jobs run without ref on master
  51. ZUUL_REF=${ZUUL_REF:-None}
  52. ZUUL_BRANCH=${ZUUL_BRANCH:-master}
  53. GIT_BASE_URL=${GIT_BASE_URL:-https://git.openstack.org}
  54. local project_names=$(awk '{ if ($1 == ":git") print $3 }' \
  55. Puppetfile0 | tr -d "'," | cut -d '/' -f 4- | xargs
  56. )
  57. $SUDO /usr/zuul-env/bin/zuul-cloner -m clonemap.yaml \
  58. --cache-dir /opt/git \
  59. --zuul-ref $ZUUL_REF \
  60. --zuul-branch $ZUUL_BRANCH \
  61. https://git.openstack.org $project_names
  62. }
  63. # Install all Puppet modules with r10k
  64. # Uses the following variables:
  65. #
  66. # - ``GEM_BIN_DIR`` must be set to Gem bin directory
  67. install_all() {
  68. $SUDO ${GEM_BIN_DIR}r10k puppetfile install -v --puppetfile Puppetfile
  69. }
  70. # Install Puppet OpenStack modules and dependencies by using
  71. # zuul-cloner or r10k.
  72. # Uses the following variables:
  73. #
  74. # - ``PUPPETFILE_DIR`` must be set to Puppet modules directory
  75. # - ``ZUUL_REF`` must be set to Zuul ref
  76. # - ``ZUUL_BRANCH`` must be set to Zuul branch
  77. install_modules() {
  78. # If zuul-cloner is there, have it install modules using zuul refs
  79. if [ -e /usr/zuul-env/bin/zuul-cloner ] ; then
  80. csplit Puppetfile /'Non-OpenStack modules'/ \
  81. --prefix Puppetfile \
  82. --suffix '%d'
  83. install_external
  84. install_openstack
  85. else
  86. install_all
  87. fi
  88. # Copy the Packstack Puppet module
  89. $SUDO cp -r packstack/puppet/modules/packstack ${PUPPETFILE_DIR}
  90. }
  91. if [ $(id -u) != 0 ]; then
  92. SUDO='sudo -E'
  93. # Packstack will connect as root to localhost, set-up the keypair and sshd
  94. if [ ! -f ~/.ssh/id_rsa ]; then
  95. ssh-keygen -t rsa -C "packstack-integration-test" -N "" -f ~/.ssh/id_rsa
  96. fi
  97. $SUDO mkdir -p /root/.ssh
  98. cat ~/.ssh/id_rsa.pub | $SUDO tee -a /root/.ssh/authorized_keys
  99. $SUDO chmod 0600 /root/.ssh/authorized_keys
  100. $SUDO sed -i 's/^PermitRootLogin no/PermitRootLogin without-password/g' /etc/ssh/sshd_config
  101. $SUDO service sshd restart
  102. fi
  103. # Sometimes keystone admin port is used as ephemeral port for other connections and gate jobs fail with httpd error 'Address already in use'.
  104. # We reserve port 35357 at the beginning of the job execution to mitigate this issue as much as possible.
  105. # Similar hack is done in devstack https://github.com/openstack-dev/devstack/blob/master/tools/fixup_stuff.sh#L53-L68
  106. # Get any currently reserved ports, strip off leading whitespace
  107. keystone_port=35357
  108. reserved_ports=$(sysctl net.ipv4.ip_local_reserved_ports | awk -F'=' '{print $2;}' | sed 's/^ //')
  109. if [[ -z "${reserved_ports}" ]]; then
  110. $SUDO sysctl -w net.ipv4.ip_local_reserved_ports=${keystone_port}
  111. else
  112. $SUDO sysctl -w net.ipv4.ip_local_reserved_ports=${keystone_port},${reserved_ports}
  113. fi
  114. # Make swap configuration consistent
  115. # TODO: REMOVE ME
  116. # https://review.openstack.org/#/c/300122/
  117. source ./tools/fix_disk_layout.sh
  118. # Bump ulimit to avoid too many open file errors
  119. echo "${USER} soft nofile 65536" | $SUDO tee -a /etc/security/limits.conf
  120. echo "${USER} hard nofile 65536" | $SUDO tee -a /etc/security/limits.conf
  121. echo "root soft nofile 65536" | $SUDO tee -a /etc/security/limits.conf
  122. echo "root hard nofile 65536" | $SUDO tee -a /etc/security/limits.conf
  123. # Set SELinux to enforcing/permissive as needed
  124. if [ "${SELINUX_ENFORCING}" = true ]; then
  125. $SUDO setenforce 1
  126. else
  127. $SUDO setenforce 0
  128. fi
  129. # Setup repositories
  130. if [ "${MANAGE_REPOS}" = true ]; then
  131. $SUDO curl -L ${DELOREAN} -o /etc/yum.repos.d/delorean.repo
  132. $SUDO curl -L ${DELOREAN_DEPS} -o /etc/yum.repos.d/delorean-deps.repo
  133. $SUDO yum update -y
  134. fi
  135. # Install dependencies
  136. $SUDO yum -y install puppet \
  137. yum-plugin-priorities \
  138. iproute \
  139. dstat \
  140. python-setuptools \
  141. openssl-devel \
  142. python-devel \
  143. libffi-devel \
  144. libxml2-devel \
  145. libxslt-devel \
  146. libyaml-devel \
  147. ruby-devel \
  148. openstack-selinux \
  149. policycoreutils \
  150. rubygems \
  151. wget \
  152. "@Development Tools"
  153. # Don't assume pip is installed
  154. which pip || $SUDO easy_install pip
  155. # Try to use pre-cached cirros images, if available, otherwise download them
  156. rm -rf /tmp/cirros
  157. mkdir /tmp/cirros
  158. # Select cirros arch and image version based on system architecture, and export them for use by the test scenarios.
  159. # As of April 2018, Packstack on x86 has kernel panics with the 0.4.0 cirros image. However, ppc64le requires it.
  160. # As such, for now, we set x86 boxes to use version 0.3.5, and ppc64le boxes to use 0.4.0.
  161. export CIRROS_ARCH="$(uname -p)"
  162. case $CIRROS_ARCH in
  163. x86_64)
  164. export CIRROS_VERSION="0.3.5"
  165. ;;
  166. ppc64le)
  167. export CIRROS_VERSION="0.4.0"
  168. ;;
  169. esac
  170. if [ -f ~/cache/files/cirros-$CIRROS_VERSION-$CIRROS_ARCH-uec.tar.gz ]; then
  171. tar -xzvf ~/cache/files/cirros-$CIRROS_VERSION-$CIRROS_ARCH-uec.tar.gz -C /tmp/cirros/
  172. else
  173. echo "No pre-cached uec archive found, downloading..."
  174. wget --tries=10 https://download.cirros-cloud.net/$CIRROS_VERSION/cirros-$CIRROS_VERSION-$CIRROS_ARCH-uec.tar.gz -P /tmp/cirros/
  175. tar -xzvf /tmp/cirros/cirros-$CIRROS_VERSION-$CIRROS_ARCH-uec.tar.gz -C /tmp/cirros/
  176. fi
  177. if [ -f ~/cache/files/cirros-$CIRROS_VERSION-$CIRROS_ARCH-disk.img ]; then
  178. cp -p ~/cache/files/cirros-$CIRROS_VERSION-$CIRROS_ARCH-disk.img /tmp/cirros/
  179. else
  180. echo "No pre-cached disk image found, downloading..."
  181. wget --tries=10 https://download.cirros-cloud.net/$CIRROS_VERSION/cirros-$CIRROS_VERSION-$CIRROS_ARCH-disk.img -P /tmp/cirros/
  182. fi
  183. echo "Using pre-cached images:"
  184. find /tmp/cirros -type f -printf "%m %n %u %g %s %t" -exec md5sum \{\} \;
  185. # TO-DO: Packstack should handle Hiera and Puppet configuration, so that it works
  186. # no matter the environment
  187. $SUDO su -c 'cat > /etc/puppet/puppet.conf <<EOF
  188. [main]
  189. logdir = /var/log/puppet
  190. rundir = /var/run/puppet
  191. ssldir = $vardir/ssl
  192. hiera_config = /etc/puppet/hiera.yaml
  193. [agent]
  194. classfile = $vardir/classes.txt
  195. localconfig = $vardir/localconfig
  196. EOF'
  197. $SUDO su -c 'cat > /etc/puppet/hiera.yaml <<EOF
  198. ---
  199. :backends:
  200. - yaml
  201. :yaml:
  202. :datadir: /placeholder
  203. :hierarchy:
  204. - common
  205. - defaults
  206. - "%{clientcert}"
  207. - "%{environment}"
  208. - global
  209. EOF'
  210. # To make sure wrong config files are not used
  211. if [ -d /home/jenkins/.puppet ]; then
  212. $SUDO rm -f /home/jenkins/.puppet
  213. fi
  214. $SUDO puppet config set hiera_config /etc/puppet/hiera.yaml
  215. # Setup dstat for resource usage tracing
  216. if type "dstat" 2>/dev/null; then
  217. $SUDO dstat -tcmndrylpg \
  218. --top-cpu-adv \
  219. --top-io-adv \
  220. --nocolor | $SUDO tee -a /var/log/dstat.log > /dev/null &
  221. fi
  222. # Setup packstack
  223. if [ "${INSTALL_FROM_SOURCE}" = true ]; then
  224. $SUDO pip install .
  225. export GEM_BIN_DIR=/tmp/packstackgems/bin/
  226. export PUPPETFILE_DIR=/usr/share/openstack-puppet/modules
  227. export GEM_HOME=/tmp/packstackgems
  228. $SUDO gem install gettext -v 3.2.9 --no-ri --no-rdoc
  229. $SUDO gem install r10k -v 2.6.4 --no-ri --no-rdoc
  230. # make sure there is no puppet module pre-installed
  231. $SUDO rm -rf "${PUPPETFILE_DIR:?}/"*
  232. install_modules
  233. else
  234. $SUDO yum -y install openstack-packstack
  235. fi
  236. # Make sure there are no other puppet modules in the system (happens in gate)
  237. $SUDO rm -rf /etc/puppet/modules/*
  238. # Make sure the fqdn is associated to the IP in /etc/hosts
  239. # Needed for Horizon SSL tests in Tempest
  240. echo -e "\n127.0.0.1 $(facter fqdn)" | $SUDO tee -a /etc/hosts
  241. # Generate configuration from selected scenario and run it
  242. source ./tests/${SCENARIO}.sh
  243. result=$?
  244. # Print output and generate subunit if results exist
  245. if [ -d /var/lib/tempest ]; then
  246. pushd /var/lib/tempest
  247. if [ -d .testrepository ]; then
  248. $SUDO /usr/bin/testr last || true
  249. $SUDO bash -c "/usr/bin/testr last --subunit > /var/tmp/packstack/latest/testrepository.subunit" || true
  250. elif [ -d .stestr ]; then
  251. $SUDO /usr/bin/stestr last || true
  252. $SUDO bash -c "/usr/bin/stestr last --subunit > /var/tmp/packstack/latest/testrepository.subunit" || true
  253. fi
  254. popd
  255. fi
  256. if [ "${COPY_LOGS}" = true ]; then
  257. source ./tools/copy-logs.sh
  258. recover_default_logs
  259. fi
  260. if [ "${FAILURE}" = true ]; then
  261. exit 1
  262. fi
  263. exit $result