ta: Avoid dpkg/apt race conditions on static slave 82/1882/2
authorAlexandru Avadanii <Alexandru.Avadanii@enea.com>
Wed, 30 Oct 2019 19:00:06 +0000 (20:00 +0100)
committerAlexandru Avadanii <Alexandru.Avadanii@enea.com>
Wed, 30 Oct 2019 20:48:47 +0000 (21:48 +0100)
AArch64 slaves running the TA RPM/ISO build jobs are static and
have two executors, allowing TA build jobs to run into DPKG/APT
race conditions.

Avoid this by skipping all DEB installations if the required
packages are already installed.

Change-Id: I0bb21c6e99dd43e0fbbf9abb5f1a2599255079f9
Signed-off-by: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
jjb/akraino-templates/akraino-ta-common-macros.yaml

index a655fdd..d208aea 100644 (file)
             if [ -n "$(find {project-to-build} -name '*.spec')" ]
             then
                 if apt --version 2>1 >/dev/null; then
-                    sudo groupadd mock || true
-                    sudo usermod -aG mock $USER
-                    sudo apt update
-                    # Explicitly install mock dependencies
-                    sudo apt install -y createrepo alien systemd-container python-pip \
-                                        python-decoratortools yum-utils usermode pigz
                     # We need a specific version of mock (1.4.14) and devtools
                     # not available in Ubuntu/Debian repos, so fetch them from RHEL mirrors
-                    wget http://vault.centos.org/centos/7.6.1810/os/x86_64/Packages/rpmdevtools-8.3-5.el7.noarch.rpm \
-                         https://kojipkgs.fedoraproject.org/packages/mock/1.4.14/2.el7/noarch/mock-1.4.14-2.el7.noarch.rpm
-                    sudo alien -d *.rpm
-                    sudo dpkg -i *.deb
-                    rm -rf *.rpm *.deb
-                    # RHEL tools hardcode the full path for certain distro tools
-                    sudo ln -sf /bin/tar /usr/bin/gtar
-                    sudo ln -sf /bin/machinectl /bin/df /usr/bin/
-                    # Some mock dependencies are only available via pip
-                    sudo pip install distro pyroute2
+                    if [ "$(mock --version 2>/dev/null)" != '1.4.14' ]; then
+                        sudo groupadd mock || true
+                        sudo usermod -aG mock $USER
+                        sudo apt update
+                        # Explicitly install mock dependencies
+                        sudo apt install -y createrepo alien systemd-container python-pip \
+                                            python-decoratortools yum-utils usermode pigz
+                        wget http://vault.centos.org/centos/7.6.1810/os/x86_64/Packages/rpmdevtools-8.3-5.el7.noarch.rpm \
+                             https://kojipkgs.fedoraproject.org/packages/mock/1.4.14/2.el7/noarch/mock-1.4.14-2.el7.noarch.rpm
+                        sudo alien -d *.rpm
+                        sudo dpkg -i *.deb
+                        rm -rf *.rpm *.deb
+                        # RHEL tools hardcode the full path for certain distro tools
+                        sudo ln -sf /bin/tar /usr/bin/gtar
+                        sudo ln -sf /bin/machinectl /bin/df /usr/bin/
+                        # Some mock dependencies are only available via pip
+                        sudo pip install distro pyroute2
+                    fi
                 else
                     sudo yum install -y createrepo
                 fi
       - shell: |2-
           #!/bin/bash -ex
           if apt --version 2>1 >/dev/null; then
-              sudo apt update
-              sudo apt install -y apt-transport-https ca-certificates curl software-properties-common
-              curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
-              sudo add-apt-repository -y "deb http://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
-              sudo apt update
-              sudo apt install -y docker-ce
+              if ! docker --version 2>1 >/dev/null; then
+                  sudo apt update
+                  sudo apt install -y apt-transport-https ca-certificates curl software-properties-common
+                  curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
+                  sudo add-apt-repository -y "deb http://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
+                  sudo apt update
+                  sudo apt install -y docker-ce
+              fi
           else
               sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
               sudo yum -y install docker-ce docker-ce-cli containerd.io
       - shell: |2-
           #!/bin/bash -ex
           if apt --version 2>1 >/dev/null; then
-              sudo apt update
-              sudo apt install -y createrepo libguestfs-tools jq
+              if ! createrepo --version 2>1 >/dev/null; then
+                  sudo apt update
+                  sudo apt install -y createrepo libguestfs-tools jq
+              fi
           else
               sudo yum -y install createrepo libguestfs-tools-c jq
           fi