blob: 15b3ab767d118bd16e3236bd0a32e874fc0a2d00 [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
Attila Fazekas1f316be2015-01-26 16:39:57 +01008
Dean Troyer49ba2242013-08-09 19:51:20 -05009
Dean Troyerdc97cb72015-03-28 08:20:50 -050010# If ``TOP_DIR`` is set we're being sourced rather than running stand-alone
Dean Troyer04a35112014-08-15 14:03:52 -050011# or in a sub-shell
12if [[ -z "$TOP_DIR" ]]; then
13 set -o errexit
14 set -o xtrace
Dean Troyer9acc12a2013-08-09 15:09:31 -050015
Dean Troyer04a35112014-08-15 14:03:52 -050016 # Keep track of the current directory
17 TOOLS_DIR=$(cd $(dirname "$0") && pwd)
18 TOP_DIR=$(cd $TOOLS_DIR/..; pwd)
Dean Troyer9acc12a2013-08-09 15:09:31 -050019
Dean Troyerdc97cb72015-03-28 08:20:50 -050020 # Change dir to top of DevStack
Dean Troyer04a35112014-08-15 14:03:52 -050021 cd $TOP_DIR
Dean Troyer9acc12a2013-08-09 15:09:31 -050022
Dean Troyer04a35112014-08-15 14:03:52 -050023 # Import common functions
24 source $TOP_DIR/functions
Dean Troyer9acc12a2013-08-09 15:09:31 -050025
Dean Troyer04a35112014-08-15 14:03:52 -050026 FILES=$TOP_DIR/files
27fi
Dean Troyer9acc12a2013-08-09 15:09:31 -050028
Morgan Fainberg6cae83e2014-06-12 15:08:48 -070029# Keystone Port Reservation
30# -------------------------
Dean Troyerdc97cb72015-03-28 08:20:50 -050031# Reserve and prevent ``KEYSTONE_AUTH_PORT`` and ``KEYSTONE_AUTH_PORT_INT`` from
Morgan Fainberg6cae83e2014-06-12 15:08:48 -070032# being used as ephemeral ports by the system. The default(s) are 35357 and
33# 35358 which are in the Linux defined ephemeral port range (in disagreement
34# with the IANA ephemeral port range). This is a workaround for bug #1253482
35# where Keystone will try and bind to the port and the port will already be
36# in use as an ephemeral port by another process. This places an explicit
37# exception into the Kernel for the Keystone AUTH ports.
IWAMOTO Toshihiro4d835e32018-02-05 16:57:41 +090038function fixup_keystone {
39 keystone_ports=${KEYSTONE_AUTH_PORT:-35357},${KEYSTONE_AUTH_PORT_INT:-35358}
Morgan Fainberg6cae83e2014-06-12 15:08:48 -070040
IWAMOTO Toshihiro4d835e32018-02-05 16:57:41 +090041 # Only do the reserved ports when available, on some system (like containers)
42 # where it's not exposed we are almost pretty sure these ports would be
43 # exclusive for our DevStack.
44 if sysctl net.ipv4.ip_local_reserved_ports >/dev/null 2>&1; then
45 # Get any currently reserved ports, strip off leading whitespace
46 reserved_ports=$(sysctl net.ipv4.ip_local_reserved_ports | awk -F'=' '{print $2;}' | sed 's/^ //')
Morgan Fainberg6cae83e2014-06-12 15:08:48 -070047
IWAMOTO Toshihiro4d835e32018-02-05 16:57:41 +090048 if [[ -z "${reserved_ports}" ]]; then
49 # If there are no currently reserved ports, reserve the keystone ports
50 sudo sysctl -w net.ipv4.ip_local_reserved_ports=${keystone_ports}
51 else
52 # If there are currently reserved ports, keep those and also reserve the
53 # Keystone specific ports. Duplicate reservations are merged into a single
54 # reservation (or range) automatically by the kernel.
55 sudo sysctl -w net.ipv4.ip_local_reserved_ports=${keystone_ports},${reserved_ports}
56 fi
Chmouel Boudjnah8fceb492014-10-02 20:58:20 +020057 else
IWAMOTO Toshihiro4d835e32018-02-05 16:57:41 +090058 echo_summary "WARNING: unable to reserve keystone ports"
Chmouel Boudjnah8fceb492014-10-02 20:58:20 +020059 fi
IWAMOTO Toshihiro4d835e32018-02-05 16:57:41 +090060}
Morgan Fainberg6cae83e2014-06-12 15:08:48 -070061
Jens Harbott8d1b20b2018-11-22 13:17:01 +000062# Ubuntu Repositories
63#--------------------
Ian Wienand2e667782019-11-20 10:41:34 +110064# Enable universe for bionic since it is missing when installing from ISO.
Jens Harbott8d1b20b2018-11-22 13:17:01 +000065function fixup_ubuntu {
Ian Wienand2e667782019-11-20 10:41:34 +110066 if [[ "$DISTRO" != "bionic" ]]; then
IWAMOTO Toshihiro4d835e32018-02-05 16:57:41 +090067 return
68 fi
69
Clark Boylanc9a9e412017-03-29 10:28:55 -070070 # This pulls in apt-add-repository
71 install_package "software-properties-common"
Jens Harbott8d1b20b2018-11-22 13:17:01 +000072
73 # Enable universe
74 sudo add-apt-repository -y universe
Dr. Jens Harbotte18325c2020-01-22 05:54:06 +000075
76 # Since pip10, pip will refuse to uninstall files from packages
77 # that were created with distutils (rather than more modern
78 # setuptools). This is because it technically doesn't have a
79 # manifest of what to remove. However, in most cases, simply
80 # overwriting works. So this hacks around those packages that
81 # have been dragged in by some other system dependency
Carlos Camacho7611d3d2020-01-30 14:39:51 +010082 sudo rm -rf /usr/lib/python3/dist-packages/httplib2-*.egg-info
83 sudo rm -rf /usr/lib/python3/dist-packages/pyasn1_modules-*.egg-info
84 sudo rm -rf /usr/lib/python3/dist-packages/PyYAML-*.egg-info
IWAMOTO Toshihiro4d835e32018-02-05 16:57:41 +090085}
Dean Troyer49ba2242013-08-09 19:51:20 -050086
87# Python Packages
88# ---------------
89
Dean Troyer65f1af62013-10-16 12:10:13 -050090# get_package_path python-package # in import notation
Ian Wienandaee18c72014-02-21 15:35:08 +110091function get_package_path {
Dean Troyer65f1af62013-10-16 12:10:13 -050092 local package=$1
93 echo $(python -c "import os; import $package; print(os.path.split(os.path.realpath($package.__file__))[0])")
94}
95
IWAMOTO Toshihiro4d835e32018-02-05 16:57:41 +090096function fixup_fedora {
97 if ! is_fedora; then
98 return
99 fi
Dean Troyer49ba2242013-08-09 19:51:20 -0500100 # Disable selinux to avoid configuring to allow Apache access
Gonéri Le Bouder394c11c2013-11-05 10:35:55 +0100101 # to Horizon files (LP#1175444)
Dean Troyer49ba2242013-08-09 19:51:20 -0500102 if selinuxenabled; then
103 sudo setenforce 0
104 fi
Dean Troyer85ebb3a2014-08-19 10:54:59 -0500105
Ian Wienande82bac02015-08-25 14:29:08 +1000106 FORCE_FIREWALLD=$(trueorfalse False FORCE_FIREWALLD)
Ian Wienand3380a162015-05-15 13:12:02 +1000107 if [[ $FORCE_FIREWALLD == "False" ]]; then
Kashyap Chamarthy7c9df102015-01-02 18:39:29 +0100108 # On Fedora 20 firewalld interacts badly with libvirt and
Ian Wienand3380a162015-05-15 13:12:02 +1000109 # slows things down significantly (this issue was fixed in
110 # later fedoras). There was also an additional issue with
111 # firewalld hanging after install of libvirt with polkit [1].
112 # firewalld also causes problems with neturon+ipv6 [2]
113 #
114 # Note we do the same as the RDO packages and stop & disable,
115 # rather than remove. This is because other packages might
116 # have the dependency [3][4].
117 #
118 # [1] https://bugzilla.redhat.com/show_bug.cgi?id=1099031
119 # [2] https://bugs.launchpad.net/neutron/+bug/1455303
120 # [3] https://github.com/redhat-openstack/openstack-puppet-modules/blob/master/firewall/manifests/linux/redhat.pp
Takashi NATSUMEfa007772017-07-22 08:59:43 +0900121 # [4] https://docs.openstack.org/devstack/latest/guides/neutron.html
Dean Troyer85ebb3a2014-08-19 10:54:59 -0500122 if is_package_installed firewalld; then
Ian Wienand3380a162015-05-15 13:12:02 +1000123 sudo systemctl disable firewalld
Ben Nemec64b2ebc2015-06-05 12:22:36 -0500124 # The iptables service files are no longer included by default,
125 # at least on a baremetal Fedora 21 Server install.
126 install_package iptables-services
Ian Wienand3380a162015-05-15 13:12:02 +1000127 sudo systemctl enable iptables
128 sudo systemctl stop firewalld
129 sudo systemctl start iptables
Dean Troyer85ebb3a2014-08-19 10:54:59 -0500130 fi
131 fi
Attila Fazekasc7e772c2015-09-01 15:18:57 +0200132
Kashyap Chamarthy90bc5862015-12-01 18:04:40 +0100133 if [[ "$os_VENDOR" == "Fedora" ]] && [[ "$os_RELEASE" -ge "22" ]]; then
Attila Fazekasc7e772c2015-09-01 15:18:57 +0200134 # requests ships vendored version of chardet/urllib3, but on
135 # fedora these are symlinked back to the primary versions to
136 # avoid duplication of code on disk. This is fine when
137 # maintainers keep things in sync, but since devstack takes
138 # over and installs later versions via pip we can end up with
139 # incompatible versions.
140 #
141 # The rpm package is not removed to preserve the dependent
142 # packages like cloud-init; rather we remove the symlinks and
143 # force a re-install of requests so the vendored versions it
144 # wants are present.
145 #
146 # Realted issues:
147 # https://bugs.launchpad.net/glance/+bug/1476770
148 # https://bugzilla.redhat.com/show_bug.cgi?id=1253823
149
Mark Hamzy746e72d2015-10-14 13:42:18 -0500150 base_path=$(get_package_path requests)/packages
Attila Fazekasc7e772c2015-09-01 15:18:57 +0200151 if [ -L $base_path/chardet -o -L $base_path/urllib3 ]; then
Mark Hamzy746e72d2015-10-14 13:42:18 -0500152 sudo rm -f $base_path/{chardet,urllib3}
Attila Fazekasc7e772c2015-09-01 15:18:57 +0200153 # install requests with the bundled urllib3 to avoid conflicts
154 pip_install --upgrade --force-reinstall requests
155 fi
Ian Wienandf0dc93d2018-04-20 10:42:07 +1000156
Attila Fazekasc7e772c2015-09-01 15:18:57 +0200157 fi
Ian Wienandf0dc93d2018-04-20 10:42:07 +1000158
159 # Since pip10, pip will refuse to uninstall files from packages
160 # that were created with distutils (rather than more modern
161 # setuptools). This is because it technically doesn't have a
162 # manifest of what to remove. However, in most cases, simply
163 # overwriting works. So this hacks around those packages that
164 # have been dragged in by some other system dependency
165 sudo rm -rf /usr/lib/python2.7/site-packages/enum34*.egg-info
166 sudo rm -rf /usr/lib/python2.7/site-packages/ipaddress*.egg-info
167 sudo rm -rf /usr/lib/python2.7/site-packages/ply-*.egg-info
168 sudo rm -rf /usr/lib/python2.7/site-packages/typing-*.egg-info
IWAMOTO Toshihiro4d835e32018-02-05 16:57:41 +0900169}
Vigneshvar.A.S834b8042015-02-14 01:05:55 +0530170
aojeagarciaeb7d1ad2018-09-24 10:17:16 +0200171function fixup_suse {
172 if ! is_suse; then
173 return
174 fi
175
Adam Spiers6c7337e2019-08-07 14:34:56 +0100176 # Deactivate and disable apparmor profiles in openSUSE and SLE
177 # distros to avoid issues with haproxy and dnsmasq. In newer
178 # releases, systemctl stop apparmor is actually a no-op, so we
179 # have to use aa-teardown to make sure we've deactivated the
180 # profiles:
181 #
182 # https://www.suse.com/releasenotes/x86_64/SUSE-SLES/15/#fate-325343
183 # https://gitlab.com/apparmor/apparmor/merge_requests/81
184 # https://build.opensuse.org/package/view_file/openSUSE:Leap:15.2/apparmor/apparmor.service?expand=1
185 if sudo systemctl is-active -q apparmor; then
186 sudo systemctl stop apparmor
187 fi
188 if [ -x /usr/sbin/aa-teardown ]; then
aojeagarciaeb7d1ad2018-09-24 10:17:16 +0200189 sudo /usr/sbin/aa-teardown
190 fi
Adam Spiers6c7337e2019-08-07 14:34:56 +0100191 if sudo systemctl is-enabled -q apparmor; then
192 sudo systemctl disable apparmor
193 fi
Colleen Murphy10f44092019-02-28 23:44:14 +0100194
195 # Since pip10, pip will refuse to uninstall files from packages
196 # that were created with distutils (rather than more modern
197 # setuptools). This is because it technically doesn't have a
198 # manifest of what to remove. However, in most cases, simply
199 # overwriting works. So this hacks around those packages that
200 # have been dragged in by some other system dependency
201 sudo rm -rf /usr/lib/python3.6/site-packages/ply-*.egg-info
Colleen Murphy6eb2c592019-09-25 12:51:23 -0700202 sudo rm -rf /usr/lib/python3.6/site-packages/six-*.egg-info
aojeagarciaeb7d1ad2018-09-24 10:17:16 +0200203}
204
Vigneshvar.A.S834b8042015-02-14 01:05:55 +0530205# The version of pip(1.5.4) supported by python-virtualenv(1.11.4) has
Kenneth Giustidf6c1ff2016-07-07 09:28:58 -0400206# connection issues under proxy so re-install the latest version using
207# pip. To avoid having pip's virtualenv overwritten by the distro's
208# package (e.g. due to installing a distro package with a dependency
209# on python-virtualenv), first install the distro python-virtualenv
210# to satisfy any dependencies then use pip to overwrite it.
211
Ian Wienand2d57f932017-08-03 14:35:37 +1000212# ... but, for infra builds, the pip-and-virtualenv [1] element has
213# already done this to ensure the latest pip, virtualenv and
214# setuptools on the base image for all platforms. It has also added
215# the packages to the yum/dnf ignore list to prevent them being
216# overwritten with old versions. F26 and dnf 2.0 has changed
217# behaviour that means re-installing python-virtualenv fails [2].
218# Thus we do a quick check if we're in the infra environment by
219# looking for the mirror config script before doing this, and just
220# skip it if so.
221
Matt Riedemann9b6d2f22019-06-18 10:43:16 -0400222# [1] https://opendev.org/openstack/diskimage-builder/src/branch/master/ \
Ian Wienand2d57f932017-08-03 14:35:37 +1000223# diskimage_builder/elements/pip-and-virtualenv/ \
224# install.d/pip-and-virtualenv-source-install/04-install-pip
225# [2] https://bugzilla.redhat.com/show_bug.cgi?id=1477823
226
IWAMOTO Toshihiro4d835e32018-02-05 16:57:41 +0900227function fixup_virtualenv {
228 if [[ ! -f /etc/ci/mirror_info.sh ]]; then
229 install_package python-virtualenv
230 pip_install -U --force-reinstall virtualenv
231 fi
232}
233
234function fixup_all {
235 fixup_keystone
Jens Harbott8d1b20b2018-11-22 13:17:01 +0000236 fixup_ubuntu
IWAMOTO Toshihiro4d835e32018-02-05 16:57:41 +0900237 fixup_fedora
aojeagarciaeb7d1ad2018-09-24 10:17:16 +0200238 fixup_suse
IWAMOTO Toshihiro4d835e32018-02-05 16:57:41 +0900239 fixup_virtualenv
240}