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.

294 lines
9.9KB

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