Dean Troyer | 9acc12a | 2013-08-09 15:09:31 -0500 | [diff] [blame] | 1 | #!/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 Spiers | cb96159 | 2013-10-05 12:11:07 +0100 | [diff] [blame] | 8 | # |
Dean Troyer | 9acc12a | 2013-08-09 15:09:31 -0500 | [diff] [blame] | 9 | # - prettytable 0.7.2 permissions are 600 in the package and |
| 10 | # pip 1.4 doesn't fix it (1.3 did) |
Adam Spiers | cb96159 | 2013-10-05 12:11:07 +0100 | [diff] [blame] | 11 | # |
Dean Troyer | 9acc12a | 2013-08-09 15:09:31 -0500 | [diff] [blame] | 12 | # - httplib2 0.8 permissions are 600 in the package and |
| 13 | # pip 1.4 doesn't fix it (1.3 did) |
Adam Spiers | cb96159 | 2013-10-05 12:11:07 +0100 | [diff] [blame] | 14 | # |
Attila Fazekas | 1f316be | 2015-01-26 16:39:57 +0100 | [diff] [blame] | 15 | # - Fedora: |
Dean Troyer | 49ba224 | 2013-08-09 19:51:20 -0500 | [diff] [blame] | 16 | # - set selinux not enforcing |
Attila Fazekas | 1f316be | 2015-01-26 16:39:57 +0100 | [diff] [blame] | 17 | # - uninstall firewalld (f20 only) |
| 18 | |
Dean Troyer | 49ba224 | 2013-08-09 19:51:20 -0500 | [diff] [blame] | 19 | |
Dean Troyer | dc97cb7 | 2015-03-28 08:20:50 -0500 | [diff] [blame] | 20 | # If ``TOP_DIR`` is set we're being sourced rather than running stand-alone |
Dean Troyer | 04a3511 | 2014-08-15 14:03:52 -0500 | [diff] [blame] | 21 | # or in a sub-shell |
| 22 | if [[ -z "$TOP_DIR" ]]; then |
| 23 | set -o errexit |
| 24 | set -o xtrace |
Dean Troyer | 9acc12a | 2013-08-09 15:09:31 -0500 | [diff] [blame] | 25 | |
Dean Troyer | 04a3511 | 2014-08-15 14:03:52 -0500 | [diff] [blame] | 26 | # Keep track of the current directory |
| 27 | TOOLS_DIR=$(cd $(dirname "$0") && pwd) |
| 28 | TOP_DIR=$(cd $TOOLS_DIR/..; pwd) |
Dean Troyer | 9acc12a | 2013-08-09 15:09:31 -0500 | [diff] [blame] | 29 | |
Dean Troyer | dc97cb7 | 2015-03-28 08:20:50 -0500 | [diff] [blame] | 30 | # Change dir to top of DevStack |
Dean Troyer | 04a3511 | 2014-08-15 14:03:52 -0500 | [diff] [blame] | 31 | cd $TOP_DIR |
Dean Troyer | 9acc12a | 2013-08-09 15:09:31 -0500 | [diff] [blame] | 32 | |
Dean Troyer | 04a3511 | 2014-08-15 14:03:52 -0500 | [diff] [blame] | 33 | # Import common functions |
| 34 | source $TOP_DIR/functions |
Dean Troyer | 9acc12a | 2013-08-09 15:09:31 -0500 | [diff] [blame] | 35 | |
Dean Troyer | 04a3511 | 2014-08-15 14:03:52 -0500 | [diff] [blame] | 36 | FILES=$TOP_DIR/files |
| 37 | fi |
Dean Troyer | 9acc12a | 2013-08-09 15:09:31 -0500 | [diff] [blame] | 38 | |
Morgan Fainberg | 6cae83e | 2014-06-12 15:08:48 -0700 | [diff] [blame] | 39 | # Keystone Port Reservation |
| 40 | # ------------------------- |
Dean Troyer | dc97cb7 | 2015-03-28 08:20:50 -0500 | [diff] [blame] | 41 | # Reserve and prevent ``KEYSTONE_AUTH_PORT`` and ``KEYSTONE_AUTH_PORT_INT`` from |
Morgan Fainberg | 6cae83e | 2014-06-12 15:08:48 -0700 | [diff] [blame] | 42 | # 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 Toshihiro | 4d835e3 | 2018-02-05 16:57:41 +0900 | [diff] [blame] | 48 | function fixup_keystone { |
| 49 | keystone_ports=${KEYSTONE_AUTH_PORT:-35357},${KEYSTONE_AUTH_PORT_INT:-35358} |
Morgan Fainberg | 6cae83e | 2014-06-12 15:08:48 -0700 | [diff] [blame] | 50 | |
IWAMOTO Toshihiro | 4d835e3 | 2018-02-05 16:57:41 +0900 | [diff] [blame] | 51 | # 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 Fainberg | 6cae83e | 2014-06-12 15:08:48 -0700 | [diff] [blame] | 57 | |
IWAMOTO Toshihiro | 4d835e3 | 2018-02-05 16:57:41 +0900 | [diff] [blame] | 58 | 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 Boudjnah | 8fceb49 | 2014-10-02 20:58:20 +0200 | [diff] [blame] | 67 | else |
IWAMOTO Toshihiro | 4d835e3 | 2018-02-05 16:57:41 +0900 | [diff] [blame] | 68 | echo_summary "WARNING: unable to reserve keystone ports" |
Chmouel Boudjnah | 8fceb49 | 2014-10-02 20:58:20 +0200 | [diff] [blame] | 69 | fi |
IWAMOTO Toshihiro | 4d835e3 | 2018-02-05 16:57:41 +0900 | [diff] [blame] | 70 | } |
Morgan Fainberg | 6cae83e | 2014-06-12 15:08:48 -0700 | [diff] [blame] | 71 | |
Jens Harbott | 8d1b20b | 2018-11-22 13:17:01 +0000 | [diff] [blame] | 72 | # Ubuntu Repositories |
| 73 | #-------------------- |
Ian Wienand | 2e66778 | 2019-11-20 10:41:34 +1100 | [diff] [blame^] | 74 | # Enable universe for bionic since it is missing when installing from ISO. |
Jens Harbott | 8d1b20b | 2018-11-22 13:17:01 +0000 | [diff] [blame] | 75 | function fixup_ubuntu { |
Ian Wienand | 2e66778 | 2019-11-20 10:41:34 +1100 | [diff] [blame^] | 76 | if [[ "$DISTRO" != "bionic" ]]; then |
IWAMOTO Toshihiro | 4d835e3 | 2018-02-05 16:57:41 +0900 | [diff] [blame] | 77 | return |
| 78 | fi |
| 79 | |
Clark Boylan | c9a9e41 | 2017-03-29 10:28:55 -0700 | [diff] [blame] | 80 | # This pulls in apt-add-repository |
| 81 | install_package "software-properties-common" |
Jens Harbott | 8d1b20b | 2018-11-22 13:17:01 +0000 | [diff] [blame] | 82 | |
| 83 | # Enable universe |
| 84 | sudo add-apt-repository -y universe |
IWAMOTO Toshihiro | 4d835e3 | 2018-02-05 16:57:41 +0900 | [diff] [blame] | 85 | } |
Dean Troyer | 49ba224 | 2013-08-09 19:51:20 -0500 | [diff] [blame] | 86 | |
| 87 | # Python Packages |
| 88 | # --------------- |
| 89 | |
Dean Troyer | 65f1af6 | 2013-10-16 12:10:13 -0500 | [diff] [blame] | 90 | # get_package_path python-package # in import notation |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 91 | function get_package_path { |
Dean Troyer | 65f1af6 | 2013-10-16 12:10:13 -0500 | [diff] [blame] | 92 | local package=$1 |
| 93 | echo $(python -c "import os; import $package; print(os.path.split(os.path.realpath($package.__file__))[0])") |
| 94 | } |
| 95 | |
| 96 | |
Dean Troyer | 9acc12a | 2013-08-09 15:09:31 -0500 | [diff] [blame] | 97 | # Pre-install affected packages so we can fix the permissions |
Dean Troyer | 65f1af6 | 2013-10-16 12:10:13 -0500 | [diff] [blame] | 98 | # These can go away once we are confident that pip 1.4.1+ is available everywhere |
| 99 | |
IWAMOTO Toshihiro | 4d835e3 | 2018-02-05 16:57:41 +0900 | [diff] [blame] | 100 | function fixup_python_packages { |
| 101 | # Fix prettytable 0.7.2 permissions |
| 102 | # Don't specify --upgrade so we use the existing package if present |
| 103 | pip_install 'prettytable>=0.7' |
| 104 | PACKAGE_DIR=$(get_package_path prettytable) |
| 105 | # Only fix version 0.7.2 |
| 106 | dir=$(echo $PACKAGE_DIR/prettytable-0.7.2*) |
| 107 | if [[ -d $dir ]]; then |
| 108 | sudo chmod +r $dir/* |
| 109 | fi |
Dean Troyer | 65f1af6 | 2013-10-16 12:10:13 -0500 | [diff] [blame] | 110 | |
IWAMOTO Toshihiro | 4d835e3 | 2018-02-05 16:57:41 +0900 | [diff] [blame] | 111 | # Fix httplib2 0.8 permissions |
| 112 | # Don't specify --upgrade so we use the existing package if present |
| 113 | pip_install httplib2 |
| 114 | PACKAGE_DIR=$(get_package_path httplib2) |
| 115 | # Only fix version 0.8 |
| 116 | dir=$(echo $PACKAGE_DIR-0.8*) |
| 117 | if [[ -d $dir ]]; then |
| 118 | sudo chmod +r $dir/* |
| 119 | fi |
| 120 | } |
Dean Troyer | 49ba224 | 2013-08-09 19:51:20 -0500 | [diff] [blame] | 121 | |
IWAMOTO Toshihiro | 4d835e3 | 2018-02-05 16:57:41 +0900 | [diff] [blame] | 122 | function fixup_fedora { |
| 123 | if ! is_fedora; then |
| 124 | return |
| 125 | fi |
Dean Troyer | 49ba224 | 2013-08-09 19:51:20 -0500 | [diff] [blame] | 126 | # Disable selinux to avoid configuring to allow Apache access |
Gonéri Le Bouder | 394c11c | 2013-11-05 10:35:55 +0100 | [diff] [blame] | 127 | # to Horizon files (LP#1175444) |
Dean Troyer | 49ba224 | 2013-08-09 19:51:20 -0500 | [diff] [blame] | 128 | if selinuxenabled; then |
| 129 | sudo setenforce 0 |
| 130 | fi |
Dean Troyer | 85ebb3a | 2014-08-19 10:54:59 -0500 | [diff] [blame] | 131 | |
Ian Wienand | e82bac0 | 2015-08-25 14:29:08 +1000 | [diff] [blame] | 132 | FORCE_FIREWALLD=$(trueorfalse False FORCE_FIREWALLD) |
Ian Wienand | 3380a16 | 2015-05-15 13:12:02 +1000 | [diff] [blame] | 133 | if [[ $FORCE_FIREWALLD == "False" ]]; then |
Kashyap Chamarthy | 7c9df10 | 2015-01-02 18:39:29 +0100 | [diff] [blame] | 134 | # On Fedora 20 firewalld interacts badly with libvirt and |
Ian Wienand | 3380a16 | 2015-05-15 13:12:02 +1000 | [diff] [blame] | 135 | # slows things down significantly (this issue was fixed in |
| 136 | # later fedoras). There was also an additional issue with |
| 137 | # firewalld hanging after install of libvirt with polkit [1]. |
| 138 | # firewalld also causes problems with neturon+ipv6 [2] |
| 139 | # |
| 140 | # Note we do the same as the RDO packages and stop & disable, |
| 141 | # rather than remove. This is because other packages might |
| 142 | # have the dependency [3][4]. |
| 143 | # |
| 144 | # [1] https://bugzilla.redhat.com/show_bug.cgi?id=1099031 |
| 145 | # [2] https://bugs.launchpad.net/neutron/+bug/1455303 |
| 146 | # [3] https://github.com/redhat-openstack/openstack-puppet-modules/blob/master/firewall/manifests/linux/redhat.pp |
Takashi NATSUME | fa00777 | 2017-07-22 08:59:43 +0900 | [diff] [blame] | 147 | # [4] https://docs.openstack.org/devstack/latest/guides/neutron.html |
Dean Troyer | 85ebb3a | 2014-08-19 10:54:59 -0500 | [diff] [blame] | 148 | if is_package_installed firewalld; then |
Ian Wienand | 3380a16 | 2015-05-15 13:12:02 +1000 | [diff] [blame] | 149 | sudo systemctl disable firewalld |
Ben Nemec | 64b2ebc | 2015-06-05 12:22:36 -0500 | [diff] [blame] | 150 | # The iptables service files are no longer included by default, |
| 151 | # at least on a baremetal Fedora 21 Server install. |
| 152 | install_package iptables-services |
Ian Wienand | 3380a16 | 2015-05-15 13:12:02 +1000 | [diff] [blame] | 153 | sudo systemctl enable iptables |
| 154 | sudo systemctl stop firewalld |
| 155 | sudo systemctl start iptables |
Dean Troyer | 85ebb3a | 2014-08-19 10:54:59 -0500 | [diff] [blame] | 156 | fi |
| 157 | fi |
Attila Fazekas | c7e772c | 2015-09-01 15:18:57 +0200 | [diff] [blame] | 158 | |
Kashyap Chamarthy | 90bc586 | 2015-12-01 18:04:40 +0100 | [diff] [blame] | 159 | if [[ "$os_VENDOR" == "Fedora" ]] && [[ "$os_RELEASE" -ge "22" ]]; then |
Attila Fazekas | c7e772c | 2015-09-01 15:18:57 +0200 | [diff] [blame] | 160 | # requests ships vendored version of chardet/urllib3, but on |
| 161 | # fedora these are symlinked back to the primary versions to |
| 162 | # avoid duplication of code on disk. This is fine when |
| 163 | # maintainers keep things in sync, but since devstack takes |
| 164 | # over and installs later versions via pip we can end up with |
| 165 | # incompatible versions. |
| 166 | # |
| 167 | # The rpm package is not removed to preserve the dependent |
| 168 | # packages like cloud-init; rather we remove the symlinks and |
| 169 | # force a re-install of requests so the vendored versions it |
| 170 | # wants are present. |
| 171 | # |
| 172 | # Realted issues: |
| 173 | # https://bugs.launchpad.net/glance/+bug/1476770 |
| 174 | # https://bugzilla.redhat.com/show_bug.cgi?id=1253823 |
| 175 | |
Mark Hamzy | 746e72d | 2015-10-14 13:42:18 -0500 | [diff] [blame] | 176 | base_path=$(get_package_path requests)/packages |
Attila Fazekas | c7e772c | 2015-09-01 15:18:57 +0200 | [diff] [blame] | 177 | if [ -L $base_path/chardet -o -L $base_path/urllib3 ]; then |
Mark Hamzy | 746e72d | 2015-10-14 13:42:18 -0500 | [diff] [blame] | 178 | sudo rm -f $base_path/{chardet,urllib3} |
Attila Fazekas | c7e772c | 2015-09-01 15:18:57 +0200 | [diff] [blame] | 179 | # install requests with the bundled urllib3 to avoid conflicts |
| 180 | pip_install --upgrade --force-reinstall requests |
| 181 | fi |
Ian Wienand | f0dc93d | 2018-04-20 10:42:07 +1000 | [diff] [blame] | 182 | |
Attila Fazekas | c7e772c | 2015-09-01 15:18:57 +0200 | [diff] [blame] | 183 | fi |
Ian Wienand | f0dc93d | 2018-04-20 10:42:07 +1000 | [diff] [blame] | 184 | |
| 185 | # Since pip10, pip will refuse to uninstall files from packages |
| 186 | # that were created with distutils (rather than more modern |
| 187 | # setuptools). This is because it technically doesn't have a |
| 188 | # manifest of what to remove. However, in most cases, simply |
| 189 | # overwriting works. So this hacks around those packages that |
| 190 | # have been dragged in by some other system dependency |
| 191 | sudo rm -rf /usr/lib/python2.7/site-packages/enum34*.egg-info |
| 192 | sudo rm -rf /usr/lib/python2.7/site-packages/ipaddress*.egg-info |
| 193 | sudo rm -rf /usr/lib/python2.7/site-packages/ply-*.egg-info |
| 194 | sudo rm -rf /usr/lib/python2.7/site-packages/typing-*.egg-info |
IWAMOTO Toshihiro | 4d835e3 | 2018-02-05 16:57:41 +0900 | [diff] [blame] | 195 | } |
Vigneshvar.A.S | 834b804 | 2015-02-14 01:05:55 +0530 | [diff] [blame] | 196 | |
aojeagarcia | eb7d1ad | 2018-09-24 10:17:16 +0200 | [diff] [blame] | 197 | function fixup_suse { |
| 198 | if ! is_suse; then |
| 199 | return |
| 200 | fi |
| 201 | |
Adam Spiers | 6c7337e | 2019-08-07 14:34:56 +0100 | [diff] [blame] | 202 | # Deactivate and disable apparmor profiles in openSUSE and SLE |
| 203 | # distros to avoid issues with haproxy and dnsmasq. In newer |
| 204 | # releases, systemctl stop apparmor is actually a no-op, so we |
| 205 | # have to use aa-teardown to make sure we've deactivated the |
| 206 | # profiles: |
| 207 | # |
| 208 | # https://www.suse.com/releasenotes/x86_64/SUSE-SLES/15/#fate-325343 |
| 209 | # https://gitlab.com/apparmor/apparmor/merge_requests/81 |
| 210 | # https://build.opensuse.org/package/view_file/openSUSE:Leap:15.2/apparmor/apparmor.service?expand=1 |
| 211 | if sudo systemctl is-active -q apparmor; then |
| 212 | sudo systemctl stop apparmor |
| 213 | fi |
| 214 | if [ -x /usr/sbin/aa-teardown ]; then |
aojeagarcia | eb7d1ad | 2018-09-24 10:17:16 +0200 | [diff] [blame] | 215 | sudo /usr/sbin/aa-teardown |
| 216 | fi |
Adam Spiers | 6c7337e | 2019-08-07 14:34:56 +0100 | [diff] [blame] | 217 | if sudo systemctl is-enabled -q apparmor; then |
| 218 | sudo systemctl disable apparmor |
| 219 | fi |
Colleen Murphy | 10f4409 | 2019-02-28 23:44:14 +0100 | [diff] [blame] | 220 | |
| 221 | # Since pip10, pip will refuse to uninstall files from packages |
| 222 | # that were created with distutils (rather than more modern |
| 223 | # setuptools). This is because it technically doesn't have a |
| 224 | # manifest of what to remove. However, in most cases, simply |
| 225 | # overwriting works. So this hacks around those packages that |
| 226 | # have been dragged in by some other system dependency |
| 227 | sudo rm -rf /usr/lib/python3.6/site-packages/ply-*.egg-info |
Colleen Murphy | 6eb2c59 | 2019-09-25 12:51:23 -0700 | [diff] [blame] | 228 | sudo rm -rf /usr/lib/python3.6/site-packages/six-*.egg-info |
aojeagarcia | eb7d1ad | 2018-09-24 10:17:16 +0200 | [diff] [blame] | 229 | } |
| 230 | |
Vigneshvar.A.S | 834b804 | 2015-02-14 01:05:55 +0530 | [diff] [blame] | 231 | # The version of pip(1.5.4) supported by python-virtualenv(1.11.4) has |
Kenneth Giusti | df6c1ff | 2016-07-07 09:28:58 -0400 | [diff] [blame] | 232 | # connection issues under proxy so re-install the latest version using |
| 233 | # pip. To avoid having pip's virtualenv overwritten by the distro's |
| 234 | # package (e.g. due to installing a distro package with a dependency |
| 235 | # on python-virtualenv), first install the distro python-virtualenv |
| 236 | # to satisfy any dependencies then use pip to overwrite it. |
| 237 | |
Ian Wienand | 2d57f93 | 2017-08-03 14:35:37 +1000 | [diff] [blame] | 238 | # ... but, for infra builds, the pip-and-virtualenv [1] element has |
| 239 | # already done this to ensure the latest pip, virtualenv and |
| 240 | # setuptools on the base image for all platforms. It has also added |
| 241 | # the packages to the yum/dnf ignore list to prevent them being |
| 242 | # overwritten with old versions. F26 and dnf 2.0 has changed |
| 243 | # behaviour that means re-installing python-virtualenv fails [2]. |
| 244 | # Thus we do a quick check if we're in the infra environment by |
| 245 | # looking for the mirror config script before doing this, and just |
| 246 | # skip it if so. |
| 247 | |
Matt Riedemann | 9b6d2f2 | 2019-06-18 10:43:16 -0400 | [diff] [blame] | 248 | # [1] https://opendev.org/openstack/diskimage-builder/src/branch/master/ \ |
Ian Wienand | 2d57f93 | 2017-08-03 14:35:37 +1000 | [diff] [blame] | 249 | # diskimage_builder/elements/pip-and-virtualenv/ \ |
| 250 | # install.d/pip-and-virtualenv-source-install/04-install-pip |
| 251 | # [2] https://bugzilla.redhat.com/show_bug.cgi?id=1477823 |
| 252 | |
IWAMOTO Toshihiro | 4d835e3 | 2018-02-05 16:57:41 +0900 | [diff] [blame] | 253 | function fixup_virtualenv { |
| 254 | if [[ ! -f /etc/ci/mirror_info.sh ]]; then |
| 255 | install_package python-virtualenv |
| 256 | pip_install -U --force-reinstall virtualenv |
| 257 | fi |
| 258 | } |
| 259 | |
| 260 | function fixup_all { |
| 261 | fixup_keystone |
Jens Harbott | 8d1b20b | 2018-11-22 13:17:01 +0000 | [diff] [blame] | 262 | fixup_ubuntu |
IWAMOTO Toshihiro | 4d835e3 | 2018-02-05 16:57:41 +0900 | [diff] [blame] | 263 | fixup_python_packages |
| 264 | fixup_fedora |
aojeagarcia | eb7d1ad | 2018-09-24 10:17:16 +0200 | [diff] [blame] | 265 | fixup_suse |
IWAMOTO Toshihiro | 4d835e3 | 2018-02-05 16:57:41 +0900 | [diff] [blame] | 266 | fixup_virtualenv |
| 267 | } |