Build and test rpm-snap using docker 61/68861/14
authorManuel Buil <mbuil@suse.com>
Wed, 28 Feb 2018 09:10:06 +0000 (10:10 +0100)
committerManuel Buil <mbuil@suse.com>
Mon, 5 Mar 2018 11:54:59 +0000 (12:54 +0100)
As agreed with Daniel, it will be easier if we move epel-7 to docker
too before merging:

https://git.opendaylight.org/gerrit/#/c/68201/

Change-Id: I81453fcd23e19bf0dfdbc3199d149ebf2dbbb0cb
Signed-off-by: Manuel Buil <mbuil@suse.com>
Signed-off-by: Daniel Farrell <dfarrell@redhat.com>
jjb/packaging/build-rpm-snap-docker.sh [new file with mode: 0644]
jjb/packaging/build-rpm-snap.sh
jjb/packaging/install-rpm.sh
jjb/packaging/packaging-macros.yaml
jjb/packaging/packaging.yaml
jjb/packaging/start-odl.sh
jjb/packaging/test-karaf-oxygensafe.expect [new file with mode: 0644]
jjb/packaging/test-karaf.expect
jjb/packaging/test-rpm-deps.sh
jjb/packaging/test-rpm-docker.sh [new file with mode: 0644]

diff --git a/jjb/packaging/build-rpm-snap-docker.sh b/jjb/packaging/build-rpm-snap-docker.sh
new file mode 100644 (file)
index 0000000..0da5178
--- /dev/null
@@ -0,0 +1,21 @@
+#!/bin/bash
+
+# Options:
+#   -x: Echo commands
+#   -e: Fail on errors
+#   -o pipefail: Fail on errors in scripts this calls, give stacktrace
+set -ex -o pipefail
+
+env | grep STREAM > env-file
+
+scripts_path=/builder/jjb/packaging
+
+docker_id=$(sudo docker run --env-file env-file --name build_rpm_epel -di --privileged -v /sys/fs/cgroup:/sys/fs/cgroup:ro centos /usr/lib/systemd/systemd)
+
+sudo docker cp "$(pwd)"/packaging/ $docker_id:/packaging
+
+sudo docker exec $docker_id /usr/bin/yum -y install sudo rpmdevtools rpmbuild git python-virtualenv python
+
+sudo docker exec $docker_id git clone https://git.opendaylight.org/gerrit/releng/builder
+
+sudo docker exec $docker_id /bin/bash $scripts_path/build-rpm-snap.sh
index 64c8ff1f08db2eaead6dd80e5e7c7b4f068d244b..4e9c2cb05e29888151eb30382bb9b21ef783c586 100644 (file)
@@ -33,17 +33,3 @@ fi
                                          latest_snap \
                                          --major "$VERSION_MAJOR"
 
-# Publish RPMs to Nexus if in production Jenkins, else host on sandbox Jenkins
-if [ "$SILO" == "sandbox" ]; then
-  # TODO: Host RPMs on Jenkins temporarily
-  echo "Not uploading RPMs to Nexus because running in sandbox"
-elif  [ "$SILO" == "releng" ]; then
-  # Move RPMs (SRPM and noarch) to dir of files that will be uploaded to Nexus
-  UPLOAD_FILES_PATH="$WORKSPACE/upload_files"
-  mkdir -p "$UPLOAD_FILES_PATH"
-  cp "/home/$USER/rpmbuild/RPMS/noarch/"*.rpm "$_"
-  cp "/home/$USER/rpmbuild/SRPMS/"*.rpm "$_"
-else
-  echo "Unknown Jenkins silo: $SILO"
-  exit 1
-fi
index 2816c4a7865ba11949c1de41aca7c33938eca5ca..2e08872e0a9600429a8d8531d6e8207a40d4ddab 100644 (file)
@@ -9,6 +9,9 @@ set -ex -o pipefail
 # Update mirror list to avoid slow/hung one
 sudo yum update -y yum-plugin-fastestmirror
 
+# Use local RPM in build-out dir if URL not passed
+URL=${URL:-"$HOME/rpmbuild/RPMS/noarch/*.rpm"}
+
 # Install ODL from RPM path, RPM URL or .repo file url
 # NB: Paths must be anchored at root
 if [[ $URL == /*  ]]; then
index ea8df73b66d082084200f72ac4a52ba686777fbe..754219b9b6811f5ab2b8cb64740168c961029062 100644 (file)
           # Install nmap to check status of ODL's SSH port
           sudo yum install -y expect nmap
       - shell: !include-raw: test-rpm-deps.sh
-      - shell: !include-raw-escape: install-rpm.sh
+      - shell: !include-raw: install-rpm.sh
       - shell: !include-raw: start-odl.sh
       - shell: !include-raw: test-ports-nofeature.sh
-      - shell: !include-raw: test-karaf.expect
+      - shell: !include-raw: test-karaf-oxygensafe.expect
       # Disable this test until ODLPARENT-139 is fixed
       # - shell: !include-raw: test-rest-ok.sh
       - shell: !include-raw: stop-odl.sh
index 341138af62316c57b502b5af984c12eb5a39c163..c2614cfab3d9db66ed788800655c4a0bd8d04031 100644 (file)
 - job-template:
     name: 'packaging-build-rpm-snap-{stream}'
 
-    node: centos7-builder-2c-8g
+    node: centos7-docker-2c-8g
 
     project-type: freestyle
 
     builders:
       - inject:
           properties-content: 'STREAM={stream}'
-      - shell: !include-raw: build-rpm-snap.sh
-      - install-test-uninstall-rpm
+      - shell: !include-raw: build-rpm-snap-docker.sh
+      - shell: !include-raw: test-rpm-docker.sh
       - lf-infra-deploy-maven-file:
           global-settings-file: 'global-settings'
           settings-file: 'packaging-settings'
       - shell: !include-raw-escape: install-rpm.sh
       - shell: !include-raw: start-odl.sh
       - shell: !include-raw-escape: test-ports-nofeature.sh
-      - shell: !include-raw: test-karaf.expect
+      - shell: !include-raw: test-karaf-oxygensafe.expect
       # Disable this test until ODLPARENT-139 is fixed
       # - shell: !include-raw-escape: test-rest-ok.sh
       - shell: !include-raw: stop-odl.sh
           sudo yum install -y expect
           # Install nmap to check status of ODL's SSH port
           sudo yum install -y nmap
-      - shell: !include-raw: test-karaf.expect
+      - shell: !include-raw: test-karaf-oxygensafe.expect
       - shell: !include-raw: stop-odl.sh
       - shell: !include-raw: test-rpm-upgrade.sh
       - shell: !include-raw: start-odl.sh
-      - shell: !include-raw: test-karaf.expect
+      - shell: !include-raw: test-karaf-oxygensafe.expect
       - shell: !include-raw: stop-odl.sh
       - shell: !include-raw: uninstall-rpm.sh
 
           sudo apt-get install -y expect
           # Install nmap to check status of ODL's SSH port
           sudo apt-get install -y nmap
-      - shell: !include-raw: test-karaf.expect
+      - shell: !include-raw: test-karaf-oxygensafe.expect
       - shell: !include-raw: stop-odl.sh
 
     publishers:
index 1e09b8f18e61f1082b49867c207924b2ad705361..ada5622d4fc0c2f76d016ae16c688dd89158c085 100644 (file)
@@ -12,5 +12,11 @@ sudo systemctl start opendaylight
 # Check systemd status of OpenDaylight, will fail if rc is nonzero
 sudo systemctl status opendaylight
 
+# Wait up to 60 seconds for ODL's Java process to start
+for i in $(seq 20); do
+  pgrep java && break || sleep 3
+  echo "Waited $((i * 3)) seconds for ODL Java process to start"
+done
+
 # Verify Java process is running, will fail if rc is nonzero
 pgrep java
diff --git a/jjb/packaging/test-karaf-oxygensafe.expect b/jjb/packaging/test-karaf-oxygensafe.expect
new file mode 100644 (file)
index 0000000..8b5fbcd
--- /dev/null
@@ -0,0 +1,68 @@
+#!/usr/bin/expect
+# This script starts the Karaf shell and sends the password for SSH auth.
+# Further tests in Karaf shell can be done here
+
+# Echo commands
+log_user 1
+
+# Time expect will wait for output
+set timeout 30
+
+# Default password
+set password "karaf"
+# Default prompt
+set prompt "opendaylight-user@root>"
+
+# Wait for Karaf SSH server to come online
+send_user "Waiting on OpenDaylight to start listening for SSH on port 8101\n"
+exec bash -c "while ! nmap -Pn -p8101 localhost | grep -q open; do sleep 0.1; done"
+
+# SSH into Karaf shell
+spawn ssh -p 8101 -o StrictHostKeyChecking=no karaf@127.0.0.1
+
+# Auth to Karaf shell
+expect "Password authentication"
+expect "Password: "
+send "$password\r"
+
+# Show features to make debugging easier
+expect "$prompt"
+send "feature:list\r"
+
+# Verify that a major feature is present
+expect "$prompt"
+send "feature:list | grep odl-netvirt-openstack\r"
+expect {{
+  timeout {{
+    send_user "\nTest feature not found\n"
+    exit 1
+  }}
+  "OpenDaylight :: NetVirt :: OpenStack" {{
+    send_user "\nTest feature available\n"
+  }}
+}}
+
+# Disable this test until ODLPARENT-139 is fixed
+# Install feature
+# expect "$prompt"
+# send "feature:install odl-netvirt-openstack\r"
+# expect {{
+#   "Error executing command: Can't install feature" {{
+#     send_user "\nFailed to install test feature\n"
+#     exit 1
+#   }}
+# }}
+
+# Verify installed feature is actually installed
+# expect "$prompt"
+# The -i flag will only show installed features
+# send "feature:list -i | grep odl-netvirt-openstack\r"
+# expect {{
+#   timeout {{
+#     send_user "\nTest feature not installed\n"
+#     exit 1
+#   }}
+#   "OpenDaylight :: NetVirt :: OpenStack" {{
+#     send_user "\nTest feature installed successfully\n"
+#   }}
+# }}
index 8b5fbcd67e1651992b74c6aa27f6e9c39e2caebe..fcbfaf64794971485ba70b4dd9f621cfa321738e 100644 (file)
@@ -42,27 +42,26 @@ expect {{
   }}
 }}
 
-# Disable this test until ODLPARENT-139 is fixed
 # Install feature
-expect "$prompt"
-send "feature:install odl-netvirt-openstack\r"
-expect {{
-  "Error executing command: Can't install feature" {{
-    send_user "\nFailed to install test feature\n"
-    exit 1
-  }}
-}}
+expect "$prompt"
+send "feature:install odl-netvirt-openstack\r"
+expect {{
+  "Error executing command: Can't install feature" {{
+    send_user "\nFailed to install test feature\n"
+    exit 1
+  }}
+}}
 
 # Verify installed feature is actually installed
-expect "$prompt"
-# The -i flag will only show installed features
-send "feature:list -i | grep odl-netvirt-openstack\r"
-expect {{
-  timeout {{
-    send_user "\nTest feature not installed\n"
-    exit 1
-  }}
-  "OpenDaylight :: NetVirt :: OpenStack" {{
-    send_user "\nTest feature installed successfully\n"
-  }}
-}}
+expect "$prompt"
+# The -i flag will show only installed features
+send "feature:list -i | grep odl-netvirt-openstack\r"
+expect {{
+  timeout {{
+    send_user "\nTest feature not installed\n"
+    exit 1
+  }}
+  "OpenDaylight :: NetVirt :: OpenStack" {{
+    send_user "\nTest feature installed successfully\n"
+  }}
+}}
index 2bb0db6dbda972cc7368a4dfee44ae40dd9e008d..028fc02b1c4428e42a127e21beea56c71b0fd4c3 100644 (file)
@@ -7,7 +7,7 @@
 set -ex -o pipefail
 
 # Verify exactly 1 RPM is in the path we expect
-set -- /home/$USER/rpmbuild/RPMS/noarch/*.rpm
+set -- $HOME/rpmbuild/RPMS/noarch/*.rpm
 if [ $# -eq 1 ]; then
     echo "Found one RPM in build out dir, as expected"
 else
@@ -16,7 +16,7 @@ else
 fi
 
 # If path is globbed (/path/to/*.rpm), expand it
-path=$(sudo find / -wholename /home/$USER/rpmbuild/RPMS/noarch/*.rpm)
+path=$(sudo find / -wholename $HOME/rpmbuild/RPMS/noarch/*.rpm)
 
 # If no RPM found, fail clearly
 if [ -z $path ]; then
@@ -43,7 +43,7 @@ if [[ ! $path == *opendaylight-6*  ]]; then
 fi
 
 # shellcheck disable=SC2034
-mapfile -t actual_deps < <( rpm -qp /home/$USER/rpmbuild/RPMS/noarch/*.rpm --requires )
+mapfile -t actual_deps < <( rpm -qp $HOME/rpmbuild/RPMS/noarch/*.rpm --requires )
 # shellcheck disable=SC2154 disable=SC2145
 printf 'Dependency found: %s\n' "${actual_deps[@]}"
 
diff --git a/jjb/packaging/test-rpm-docker.sh b/jjb/packaging/test-rpm-docker.sh
new file mode 100644 (file)
index 0000000..5f4fa30
--- /dev/null
@@ -0,0 +1,48 @@
+#!/bin/bash
+
+# Options:
+#   -x: Echo commands
+#   -e: Fail on errors
+#   -o pipefail: Fail on errors in scripts this calls, give stacktrace
+set -ex -o pipefail
+
+scripts_path=/builder/jjb/packaging
+
+# A docker container must have been created by the build script
+docker_id=$(sudo docker ps -qf name=build_rpm_epel)
+
+sudo docker exec $docker_id /usr/bin/yum -y install curl expect nmap openssh
+
+sudo docker exec $docker_id /bin/bash $scripts_path/test-rpm-deps.sh
+
+sudo docker exec $docker_id /bin/bash $scripts_path/install-rpm.sh
+
+sudo docker exec $docker_id /bin/bash $scripts_path/start-odl.sh
+
+sudo docker exec $docker_id /bin/bash $scripts_path/test-ports-nofeature.sh
+
+# Don't install test feature and check REST for Oxygen, ODLPARENT-139 breaks it
+if [ "$STREAM" == "oxygen" ]; then
+  sudo docker exec $docker_id /usr/bin/expect $scripts_path/test-karaf-oxygensafe.expect
+else
+  sudo docker exec $docker_id /usr/bin/expect $scripts_path/test-karaf.expect
+  sudo docker exec $docker_id /bin/bash $scripts_path/test-rest-ok.sh
+fi
+
+sudo docker exec $docker_id /bin/bash $scripts_path/stop-odl.sh
+
+sudo docker exec $docker_id /bin/bash $scripts_path/uninstall-rpm.sh
+
+if [ "$SILO" == "sandbox" ]; then
+  echo "Not uploading RPMs to Nexus because running in sandbox"
+elif [ "$SILO" == "releng" ]; then
+  RPM_NAME=$(sudo docker exec $docker_id find /root/rpmbuild/RPMS/noarch/ -wholename '*.rpm')
+  SRPM_NAME=$(sudo docker exec $docker_id find /root/rpmbuild/SRPMS/ -wholename '*.rpm')
+  UPLOAD_FILES_PATH="$WORKSPACE/upload_files"
+  mkdir -p "$UPLOAD_FILES_PATH"
+  sudo docker cp $docker_id:$RPM_NAME "$_"
+  sudo docker cp $docker_id:$SRPM_NAME "$_"
+else
+  echo "Unknown Jenkins silo: $SILO"
+  exit 1
+fi