blob: d2989379fe76d0fb2ddf86acd5cf34adaea20004 [file] [log] [blame]
Dean Troyer9acc12a2013-08-09 15:09:31 -05001#!/usr/bin/env bash
2
3# **fixup_stuff.sh**
4
5# fixup_stuff.sh
6#
7# All distro and package specific hacks go in here
Adam Spierscb961592013-10-05 12:11:07 +01008#
Dean Troyer9acc12a2013-08-09 15:09:31 -05009# - prettytable 0.7.2 permissions are 600 in the package and
10# pip 1.4 doesn't fix it (1.3 did)
Adam Spierscb961592013-10-05 12:11:07 +010011#
Dean Troyer9acc12a2013-08-09 15:09:31 -050012# - httplib2 0.8 permissions are 600 in the package and
13# pip 1.4 doesn't fix it (1.3 did)
Adam Spierscb961592013-10-05 12:11:07 +010014#
Attila Fazekas1f316be2015-01-26 16:39:57 +010015# - Fedora:
Dean Troyer49ba2242013-08-09 19:51:20 -050016# - set selinux not enforcing
Attila Fazekas1f316be2015-01-26 16:39:57 +010017# - uninstall firewalld (f20 only)
18
Dean Troyer49ba2242013-08-09 19:51:20 -050019
Dean Troyerdc97cb72015-03-28 08:20:50 -050020# If ``TOP_DIR`` is set we're being sourced rather than running stand-alone
Dean Troyer04a35112014-08-15 14:03:52 -050021# or in a sub-shell
22if [[ -z "$TOP_DIR" ]]; then
23 set -o errexit
24 set -o xtrace
Dean Troyer9acc12a2013-08-09 15:09:31 -050025
Dean Troyer04a35112014-08-15 14:03:52 -050026 # Keep track of the current directory
27 TOOLS_DIR=$(cd $(dirname "$0") && pwd)
28 TOP_DIR=$(cd $TOOLS_DIR/..; pwd)
Dean Troyer9acc12a2013-08-09 15:09:31 -050029
Dean Troyerdc97cb72015-03-28 08:20:50 -050030 # Change dir to top of DevStack
Dean Troyer04a35112014-08-15 14:03:52 -050031 cd $TOP_DIR
Dean Troyer9acc12a2013-08-09 15:09:31 -050032
Dean Troyer04a35112014-08-15 14:03:52 -050033 # Import common functions
34 source $TOP_DIR/functions
Dean Troyer9acc12a2013-08-09 15:09:31 -050035
Dean Troyer04a35112014-08-15 14:03:52 -050036 FILES=$TOP_DIR/files
37fi
Dean Troyer9acc12a2013-08-09 15:09:31 -050038
Morgan Fainberg6cae83e2014-06-12 15:08:48 -070039# Keystone Port Reservation
40# -------------------------
Dean Troyerdc97cb72015-03-28 08:20:50 -050041# Reserve and prevent ``KEYSTONE_AUTH_PORT`` and ``KEYSTONE_AUTH_PORT_INT`` from
Morgan Fainberg6cae83e2014-06-12 15:08:48 -070042# being used as ephemeral ports by the system. The default(s) are 35357 and
43# 35358 which are in the Linux defined ephemeral port range (in disagreement
44# with the IANA ephemeral port range). This is a workaround for bug #1253482
45# where Keystone will try and bind to the port and the port will already be
46# in use as an ephemeral port by another process. This places an explicit
47# exception into the Kernel for the Keystone AUTH ports.
IWAMOTO Toshihiro4d835e32018-02-05 16:57:41 +090048function fixup_keystone {
49 keystone_ports=${KEYSTONE_AUTH_PORT:-35357},${KEYSTONE_AUTH_PORT_INT:-35358}
Morgan Fainberg6cae83e2014-06-12 15:08:48 -070050
IWAMOTO Toshihiro4d835e32018-02-05 16:57:41 +090051 # Only do the reserved ports when available, on some system (like containers)
52 # where it's not exposed we are almost pretty sure these ports would be
53 # exclusive for our DevStack.
54 if sysctl net.ipv4.ip_local_reserved_ports >/dev/null 2>&1; then
55 # Get any currently reserved ports, strip off leading whitespace
56 reserved_ports=$(sysctl net.ipv4.ip_local_reserved_ports | awk -F'=' '{print $2;}' | sed 's/^ //')
Morgan Fainberg6cae83e2014-06-12 15:08:48 -070057
IWAMOTO Toshihiro4d835e32018-02-05 16:57:41 +090058 if [[ -z "${reserved_ports}" ]]; then
59 # If there are no currently reserved ports, reserve the keystone ports
60 sudo sysctl -w net.ipv4.ip_local_reserved_ports=${keystone_ports}
61 else
62 # If there are currently reserved ports, keep those and also reserve the
63 # Keystone specific ports. Duplicate reservations are merged into a single
64 # reservation (or range) automatically by the kernel.
65 sudo sysctl -w net.ipv4.ip_local_reserved_ports=${keystone_ports},${reserved_ports}
66 fi
Chmouel Boudjnah8fceb492014-10-02 20:58:20 +020067 else
IWAMOTO Toshihiro4d835e32018-02-05 16:57:41 +090068 echo_summary "WARNING: unable to reserve keystone ports"
Chmouel Boudjnah8fceb492014-10-02 20:58:20 +020069 fi
IWAMOTO Toshihiro4d835e32018-02-05 16:57:41 +090070}
Morgan Fainberg6cae83e2014-06-12 15:08:48 -070071
Jens Harbott8d1b20b2018-11-22 13:17:01 +000072# Ubuntu Repositories
73#--------------------
Clark Boylanc9a9e412017-03-29 10:28:55 -070074# We've found that Libvirt on Xenial is flaky and crashes enough to be
75# a regular top e-r bug. Opt into Ubuntu Cloud Archive if on Xenial to
76# get newer Libvirt.
Amrith Kumarbb436d32017-05-10 08:21:04 -040077# Make it possible to switch this based on an environment variable as
78# libvirt 2.5.0 doesn't handle nested virtualization quite well and this
79# is required for the trove development environment.
Jens Harbott8d1b20b2018-11-22 13:17:01 +000080# Also enable universe since it is missing when installing from ISO.
81function fixup_ubuntu {
82 if [[ "$DISTRO" != "xenial" && "$DISTRO" != "bionic" ]]; then
IWAMOTO Toshihiro4d835e32018-02-05 16:57:41 +090083 return
84 fi
85
Clark Boylanc9a9e412017-03-29 10:28:55 -070086 # This pulls in apt-add-repository
87 install_package "software-properties-common"
Jens Harbott8d1b20b2018-11-22 13:17:01 +000088
89 # Enable universe
90 sudo add-apt-repository -y universe
91
92 if [[ "${ENABLE_UBUNTU_CLOUD_ARCHIVE}" == "False" || "$DISTRO" != "xenial" ]]; then
93 return
94 fi
Matt Riedemann23df4da2018-03-19 14:27:01 -040095 # Use UCA for newer libvirt.
Clark Boylanc9a9e412017-03-29 10:28:55 -070096 if [[ -f /etc/ci/mirror_info.sh ]] ; then
97 # If we are on a nodepool provided host and it has told us about where
98 # we can find local mirrors then use that mirror.
99 source /etc/ci/mirror_info.sh
100
Matt Riedemann23df4da2018-03-19 14:27:01 -0400101 sudo apt-add-repository -y "deb $NODEPOOL_UCA_MIRROR xenial-updates/queens main"
Clark Boylanc9a9e412017-03-29 10:28:55 -0700102 else
103 # Otherwise use upstream UCA
Matt Riedemann23df4da2018-03-19 14:27:01 -0400104 sudo add-apt-repository -y cloud-archive:queens
Clark Boylanc9a9e412017-03-29 10:28:55 -0700105 fi
Ian Wienand71d20e62017-04-21 11:48:12 +1000106
107 # Disable use of libvirt wheel since a cached wheel build might be
108 # against older libvirt binary. Particularly a problem if using
109 # the openstack wheel mirrors, but can hit locally too.
110 # TODO(clarkb) figure out how to use upstream wheel again.
111 iniset -sudo /etc/pip.conf "global" "no-binary" "libvirt-python"
112
Paul Belanger1f92d442017-04-13 12:07:57 -0400113 # Force update our APT repos, since we added UCA above.
114 REPOS_UPDATED=False
115 apt_get_update
IWAMOTO Toshihiro4d835e32018-02-05 16:57:41 +0900116}
Dean Troyer49ba2242013-08-09 19:51:20 -0500117
118# Python Packages
119# ---------------
120
Dean Troyer65f1af62013-10-16 12:10:13 -0500121# get_package_path python-package # in import notation
Ian Wienandaee18c72014-02-21 15:35:08 +1100122function get_package_path {
Dean Troyer65f1af62013-10-16 12:10:13 -0500123 local package=$1
124 echo $(python -c "import os; import $package; print(os.path.split(os.path.realpath($package.__file__))[0])")
125}
126
127
Dean Troyer9acc12a2013-08-09 15:09:31 -0500128# Pre-install affected packages so we can fix the permissions
Dean Troyer65f1af62013-10-16 12:10:13 -0500129# These can go away once we are confident that pip 1.4.1+ is available everywhere
130
IWAMOTO Toshihiro4d835e32018-02-05 16:57:41 +0900131function fixup_python_packages {
132 # Fix prettytable 0.7.2 permissions
133 # Don't specify --upgrade so we use the existing package if present
134 pip_install 'prettytable>=0.7'
135 PACKAGE_DIR=$(get_package_path prettytable)
136 # Only fix version 0.7.2
137 dir=$(echo $PACKAGE_DIR/prettytable-0.7.2*)
138 if [[ -d $dir ]]; then
139 sudo chmod +r $dir/*
140 fi
Dean Troyer65f1af62013-10-16 12:10:13 -0500141
IWAMOTO Toshihiro4d835e32018-02-05 16:57:41 +0900142 # Fix httplib2 0.8 permissions
143 # Don't specify --upgrade so we use the existing package if present
144 pip_install httplib2
145 PACKAGE_DIR=$(get_package_path httplib2)
146 # Only fix version 0.8
147 dir=$(echo $PACKAGE_DIR-0.8*)
148 if [[ -d $dir ]]; then
149 sudo chmod +r $dir/*
150 fi
151}
Dean Troyer49ba2242013-08-09 19:51:20 -0500152
IWAMOTO Toshihiro4d835e32018-02-05 16:57:41 +0900153function fixup_fedora {
154 if ! is_fedora; then
155 return
156 fi
Dean Troyer49ba2242013-08-09 19:51:20 -0500157 # Disable selinux to avoid configuring to allow Apache access
Gonéri Le Bouder394c11c2013-11-05 10:35:55 +0100158 # to Horizon files (LP#1175444)
Dean Troyer49ba2242013-08-09 19:51:20 -0500159 if selinuxenabled; then
160 sudo setenforce 0
161 fi
Dean Troyer85ebb3a2014-08-19 10:54:59 -0500162
Ian Wienande82bac02015-08-25 14:29:08 +1000163 FORCE_FIREWALLD=$(trueorfalse False FORCE_FIREWALLD)
Ian Wienand3380a162015-05-15 13:12:02 +1000164 if [[ $FORCE_FIREWALLD == "False" ]]; then
Kashyap Chamarthy7c9df102015-01-02 18:39:29 +0100165 # On Fedora 20 firewalld interacts badly with libvirt and
Ian Wienand3380a162015-05-15 13:12:02 +1000166 # slows things down significantly (this issue was fixed in
167 # later fedoras). There was also an additional issue with
168 # firewalld hanging after install of libvirt with polkit [1].
169 # firewalld also causes problems with neturon+ipv6 [2]
170 #
171 # Note we do the same as the RDO packages and stop & disable,
172 # rather than remove. This is because other packages might
173 # have the dependency [3][4].
174 #
175 # [1] https://bugzilla.redhat.com/show_bug.cgi?id=1099031
176 # [2] https://bugs.launchpad.net/neutron/+bug/1455303
177 # [3] https://github.com/redhat-openstack/openstack-puppet-modules/blob/master/firewall/manifests/linux/redhat.pp
Takashi NATSUMEfa007772017-07-22 08:59:43 +0900178 # [4] https://docs.openstack.org/devstack/latest/guides/neutron.html
Dean Troyer85ebb3a2014-08-19 10:54:59 -0500179 if is_package_installed firewalld; then
Ian Wienand3380a162015-05-15 13:12:02 +1000180 sudo systemctl disable firewalld
Ben Nemec64b2ebc2015-06-05 12:22:36 -0500181 # The iptables service files are no longer included by default,
182 # at least on a baremetal Fedora 21 Server install.
183 install_package iptables-services
Ian Wienand3380a162015-05-15 13:12:02 +1000184 sudo systemctl enable iptables
185 sudo systemctl stop firewalld
186 sudo systemctl start iptables
Dean Troyer85ebb3a2014-08-19 10:54:59 -0500187 fi
188 fi
Attila Fazekasc7e772c2015-09-01 15:18:57 +0200189
Kashyap Chamarthy90bc5862015-12-01 18:04:40 +0100190 if [[ "$os_VENDOR" == "Fedora" ]] && [[ "$os_RELEASE" -ge "22" ]]; then
Attila Fazekasc7e772c2015-09-01 15:18:57 +0200191 # requests ships vendored version of chardet/urllib3, but on
192 # fedora these are symlinked back to the primary versions to
193 # avoid duplication of code on disk. This is fine when
194 # maintainers keep things in sync, but since devstack takes
195 # over and installs later versions via pip we can end up with
196 # incompatible versions.
197 #
198 # The rpm package is not removed to preserve the dependent
199 # packages like cloud-init; rather we remove the symlinks and
200 # force a re-install of requests so the vendored versions it
201 # wants are present.
202 #
203 # Realted issues:
204 # https://bugs.launchpad.net/glance/+bug/1476770
205 # https://bugzilla.redhat.com/show_bug.cgi?id=1253823
206
Mark Hamzy746e72d2015-10-14 13:42:18 -0500207 base_path=$(get_package_path requests)/packages
Attila Fazekasc7e772c2015-09-01 15:18:57 +0200208 if [ -L $base_path/chardet -o -L $base_path/urllib3 ]; then
Mark Hamzy746e72d2015-10-14 13:42:18 -0500209 sudo rm -f $base_path/{chardet,urllib3}
Attila Fazekasc7e772c2015-09-01 15:18:57 +0200210 # install requests with the bundled urllib3 to avoid conflicts
211 pip_install --upgrade --force-reinstall requests
212 fi
Ian Wienandf0dc93d2018-04-20 10:42:07 +1000213
Attila Fazekasc7e772c2015-09-01 15:18:57 +0200214 fi
Ian Wienandf0dc93d2018-04-20 10:42:07 +1000215
216 # Since pip10, pip will refuse to uninstall files from packages
217 # that were created with distutils (rather than more modern
218 # setuptools). This is because it technically doesn't have a
219 # manifest of what to remove. However, in most cases, simply
220 # overwriting works. So this hacks around those packages that
221 # have been dragged in by some other system dependency
222 sudo rm -rf /usr/lib/python2.7/site-packages/enum34*.egg-info
223 sudo rm -rf /usr/lib/python2.7/site-packages/ipaddress*.egg-info
224 sudo rm -rf /usr/lib/python2.7/site-packages/ply-*.egg-info
225 sudo rm -rf /usr/lib/python2.7/site-packages/typing-*.egg-info
IWAMOTO Toshihiro4d835e32018-02-05 16:57:41 +0900226}
Vigneshvar.A.S834b8042015-02-14 01:05:55 +0530227
aojeagarciaeb7d1ad2018-09-24 10:17:16 +0200228function fixup_suse {
229 if ! is_suse; then
230 return
231 fi
232
Adam Spiers6c7337e2019-08-07 14:34:56 +0100233 # Deactivate and disable apparmor profiles in openSUSE and SLE
234 # distros to avoid issues with haproxy and dnsmasq. In newer
235 # releases, systemctl stop apparmor is actually a no-op, so we
236 # have to use aa-teardown to make sure we've deactivated the
237 # profiles:
238 #
239 # https://www.suse.com/releasenotes/x86_64/SUSE-SLES/15/#fate-325343
240 # https://gitlab.com/apparmor/apparmor/merge_requests/81
241 # https://build.opensuse.org/package/view_file/openSUSE:Leap:15.2/apparmor/apparmor.service?expand=1
242 if sudo systemctl is-active -q apparmor; then
243 sudo systemctl stop apparmor
244 fi
245 if [ -x /usr/sbin/aa-teardown ]; then
aojeagarciaeb7d1ad2018-09-24 10:17:16 +0200246 sudo /usr/sbin/aa-teardown
247 fi
Adam Spiers6c7337e2019-08-07 14:34:56 +0100248 if sudo systemctl is-enabled -q apparmor; then
249 sudo systemctl disable apparmor
250 fi
Colleen Murphy10f44092019-02-28 23:44:14 +0100251
252 # Since pip10, pip will refuse to uninstall files from packages
253 # that were created with distutils (rather than more modern
254 # setuptools). This is because it technically doesn't have a
255 # manifest of what to remove. However, in most cases, simply
256 # overwriting works. So this hacks around those packages that
257 # have been dragged in by some other system dependency
258 sudo rm -rf /usr/lib/python3.6/site-packages/ply-*.egg-info
Colleen Murphy6eb2c592019-09-25 12:51:23 -0700259 sudo rm -rf /usr/lib/python3.6/site-packages/six-*.egg-info
aojeagarciaeb7d1ad2018-09-24 10:17:16 +0200260}
261
Vigneshvar.A.S834b8042015-02-14 01:05:55 +0530262# The version of pip(1.5.4) supported by python-virtualenv(1.11.4) has
Kenneth Giustidf6c1ff2016-07-07 09:28:58 -0400263# connection issues under proxy so re-install the latest version using
264# pip. To avoid having pip's virtualenv overwritten by the distro's
265# package (e.g. due to installing a distro package with a dependency
266# on python-virtualenv), first install the distro python-virtualenv
267# to satisfy any dependencies then use pip to overwrite it.
268
Ian Wienand2d57f932017-08-03 14:35:37 +1000269# ... but, for infra builds, the pip-and-virtualenv [1] element has
270# already done this to ensure the latest pip, virtualenv and
271# setuptools on the base image for all platforms. It has also added
272# the packages to the yum/dnf ignore list to prevent them being
273# overwritten with old versions. F26 and dnf 2.0 has changed
274# behaviour that means re-installing python-virtualenv fails [2].
275# Thus we do a quick check if we're in the infra environment by
276# looking for the mirror config script before doing this, and just
277# skip it if so.
278
Matt Riedemann9b6d2f22019-06-18 10:43:16 -0400279# [1] https://opendev.org/openstack/diskimage-builder/src/branch/master/ \
Ian Wienand2d57f932017-08-03 14:35:37 +1000280# diskimage_builder/elements/pip-and-virtualenv/ \
281# install.d/pip-and-virtualenv-source-install/04-install-pip
282# [2] https://bugzilla.redhat.com/show_bug.cgi?id=1477823
283
IWAMOTO Toshihiro4d835e32018-02-05 16:57:41 +0900284function fixup_virtualenv {
285 if [[ ! -f /etc/ci/mirror_info.sh ]]; then
286 install_package python-virtualenv
287 pip_install -U --force-reinstall virtualenv
288 fi
289}
290
291function fixup_all {
292 fixup_keystone
Jens Harbott8d1b20b2018-11-22 13:17:01 +0000293 fixup_ubuntu
IWAMOTO Toshihiro4d835e32018-02-05 16:57:41 +0900294 fixup_python_packages
295 fixup_fedora
aojeagarciaeb7d1ad2018-09-24 10:17:16 +0200296 fixup_suse
IWAMOTO Toshihiro4d835e32018-02-05 16:57:41 +0900297 fixup_virtualenv
298}