Repository: osbuild/osbuild-composer
Pull request #1118 (2020-11-30 08:44:01)

{koji,worker}/server: log errors returned from handlers
Previously, we had no clue what errors were caught by the default echo's error handler. Thus, in the case of an error, we were basically blind. Let's log all errors so we can investigate them later.

ondrejbudai: Rebased to add #1122.

Patch:
diff --git a/internal/distro/rhel84/distro.go b/internal/distro/rhel84/distro.go
index b4d759fa9..afd3e1bbf 100644
--- a/internal/distro/rhel84/distro.go
+++ b/internal/distro/rhel84/distro.go
@@ -898,7 +898,7 @@ func New() distro.Distro {
 		},
 		kernelOptions: "ro console=ttyS0 console=ttyS0,115200n8 no_timer_check net.ifnames=0 crashkernel=auto",
 		bootable:      true,
-		defaultSize:   4 * GigaByte,
+		defaultSize:   10 * GigaByte,
 		assembler: func(options distro.ImageOptions, arch distro.Arch) *osbuild.Assembler {
 			return qemuAssembler("qcow2", "disk.qcow2", options, arch)
 		},
diff --git a/internal/kojiapi/server.go b/internal/kojiapi/server.go
index 76b6eb336..ef330fb48 100644
--- a/internal/kojiapi/server.go
+++ b/internal/kojiapi/server.go
@@ -46,6 +46,12 @@ func (s *Server) Handler(path string) http.Handler {
 	e.Binder = binder{}
 	e.StdLogger = s.logger
 
+	// log errors returned from handlers
+	e.HTTPErrorHandler = func(err error, c echo.Context) {
+		log.Println(c.Path(), c.QueryParams().Encode(), err.Error())
+		e.DefaultHTTPErrorHandler(err, c)
+	}
+
 	api.RegisterHandlers(e.Group(path), &apiHandlers{s})
 
 	return e
diff --git a/internal/worker/server.go b/internal/worker/server.go
index c81ac18bc..665d06c1a 100644
--- a/internal/worker/server.go
+++ b/internal/worker/server.go
@@ -62,6 +62,12 @@ func (s *Server) Handler() http.Handler {
 	e.Binder = binder{}
 	e.StdLogger = s.logger
 
+	// log errors returned from handlers
+	e.HTTPErrorHandler = func(err error, c echo.Context) {
+		log.Println(c.Path(), c.QueryParams().Encode(), err.Error())
+		e.DefaultHTTPErrorHandler(err, c)
+	}
+
 	handler := apiHandlers{
 		server: s,
 	}
diff --git a/osbuild-composer.spec b/osbuild-composer.spec
index 22dbc1765..e6dfa53c8 100644
--- a/osbuild-composer.spec
+++ b/osbuild-composer.spec
@@ -174,6 +174,7 @@ install -m 0755 -vp tools/provision.sh                          %{buildroot}%{_l
 install -m 0755 -vp tools/image-info                            %{buildroot}%{_libexecdir}/osbuild-composer-test/
 install -m 0755 -vp tools/run-koji-container.sh                 %{buildroot}%{_libexecdir}/osbuild-composer-test/
 install -m 0755 -vp tools/koji-compose.py                       %{buildroot}%{_libexecdir}/osbuild-composer-test/
+install -m 0755 -vp tools/libvirt_test.sh                       %{buildroot}%{_libexecdir}/osbuild-composer-test/
 install -m 0755 -vd                                             %{buildroot}%{_libexecdir}/tests/osbuild-composer
 install -m 0755 -vp test/cases/*                                %{buildroot}%{_libexecdir}/tests/osbuild-composer/
 
diff --git a/schutzbot/Jenkinsfile b/schutzbot/Jenkinsfile
index 2f960fedc..6ab850079 100644
--- a/schutzbot/Jenkinsfile
+++ b/schutzbot/Jenkinsfile
@@ -118,7 +118,7 @@ pipeline {
                     agent { label "f32cloudbase && x86_64 && aws" }
                     environment { TEST_TYPE = "base" }
                     steps {
-                        run_tests('base', 'bios')
+                        run_tests('base')
                     }
                     post {
                         always {
@@ -138,7 +138,7 @@ pipeline {
                         DISTRO_CODE = "fedora32"
                     }
                     steps {
-                        run_tests('image', 'bios')
+                        run_tests('image')
                     }
                     post {
                         always {
@@ -159,7 +159,7 @@ pipeline {
                         AWS_API_TEST_SHARE_ACCOUNT = credentials('aws-credentials-share-account')
                     }
                     steps {
-                        run_tests('integration', 'bios')
+                        run_tests('integration')
                     }
                     post {
                         always {
@@ -170,7 +170,7 @@ pipeline {
                 stage('F32 OSTree') {
                     agent { label "f32cloudbase && psi && x86_64" }
                     steps {
-                        run_tests('ostree', 'bios')
+                        run_tests('ostree')
                     }
                     post {
                         always {
@@ -193,7 +193,7 @@ pipeline {
                     agent { label "f33cloudbase && x86_64 && aws" }
                     environment { TEST_TYPE = "base" }
                     steps {
-                        run_tests('base', 'bios')
+                        run_tests('base')
                     }
                     post {
                         always {
@@ -213,7 +213,7 @@ pipeline {
                         DISTRO_CODE = "fedora33"
                     }
                     steps {
-                        run_tests('image', 'bios')
+                        run_tests('image')
                     }
                     post {
                         always {
@@ -234,7 +234,7 @@ pipeline {
                         AWS_API_TEST_SHARE_ACCOUNT = credentials('aws-credentials-share-account')
                     }
                     steps {
-                        run_tests('integration', 'bios')
+                        run_tests('integration')
                     }
                     post {
                         always {
@@ -245,7 +245,7 @@ pipeline {
                 stage('F33 OSTree') {
                     agent { label "f33cloudbase && psi && x86_64" }
                     steps {
-                        run_tests('ostree', 'bios')
+                        run_tests('ostree')
                     }
                     post {
                         always {
@@ -257,7 +257,7 @@ pipeline {
                     agent { label "f33cloudbase && aarch64 && aws" }
                     environment { TEST_TYPE = "base" }
                     steps {
-                        run_tests('base', 'bios')
+                        run_tests('base')
                     }
                     post {
                         always {
@@ -276,7 +276,7 @@ pipeline {
                         DISTRO_CODE = "fedora33"
                     }
                     steps {
-                        run_tests('image', 'bios')
+                        run_tests('image')
                     }
                     post {
                         always {
@@ -295,7 +295,7 @@ pipeline {
                         RHN_REGISTRATION_SCRIPT = credentials('rhn-register-script-production')
                     }
                     steps {
-                        run_tests('base', 'bios')
+                        run_tests('base')
                     }
                     post {
                         always {
@@ -316,7 +316,7 @@ pipeline {
                         DISTRO_CODE = "rhel8"
                     }
                     steps {
-                        run_tests('image', 'bios')
+                        run_tests('image')
                     }
                     post {
                         always {
@@ -338,7 +338,7 @@ pipeline {
                         AWS_API_TEST_SHARE_ACCOUNT = credentials('aws-credentials-share-account')
                     }
                     steps {
-                        run_tests('integration', 'bios')
+                        run_tests('integration')
                     }
                     post {
                         always {
@@ -349,7 +349,7 @@ pipeline {
                 stage('EL8 OSTree') {
                     agent { label "rhel8cloudbase && psi && x86_64" }
                     steps {
-                        run_tests('ostree', 'bios')
+                        run_tests('ostree')
                     }
                     post {
                         always {
@@ -374,7 +374,7 @@ pipeline {
                         TEST_TYPE = "base"
                     }
                     steps {
-                        run_tests('base', 'hybrid')
+                        run_tests('base')
                     }
                     post {
                         always {
@@ -394,7 +394,7 @@ pipeline {
                         DISTRO_CODE = "rhel84"
                     }
                     steps {
-                        run_tests('image', 'hybrid')
+                        run_tests('image')
                     }
                     post {
                         always {
@@ -415,7 +415,7 @@ pipeline {
                         AWS_IMAGE_TEST_CREDS = credentials('aws-credentials-osbuild-image-test')
                     }
                     steps {
-                        run_tests('integration', 'hybrid')
+                        run_tests('integration')
                     }
                     post {
                         always {
@@ -426,7 +426,7 @@ pipeline {
                 stage('EL8.4 OSTree') {
                     agent { label "rhel84cloudbase && psi && x86_64" }
                     steps {
-                        run_tests('ostree', 'hybrid')
+                        run_tests('ostree')
                     }
                     post {
                         always {
@@ -463,7 +463,7 @@ pipeline {
 
 // Set up a function to hold the steps needed to run the tests so we don't
 // need to copy/paste the same lines over and over above.
-void run_tests(test_type, boot_type) {
+void run_tests(test_type) {
 
     // Get CI machine details.
     sh (
@@ -506,30 +506,10 @@ void run_tests(test_type, boot_type) {
             script: "/usr/libexec/tests/osbuild-composer/koji.sh"
         )
 
-        // Run the qcow2 BIOS boot test.
+        // Run the libvirt test.
         sh (
-            label: "Integration test: QCOW2, BIOS boot",
-            script: "/usr/libexec/tests/osbuild-composer/qemu.sh qcow2"
-        )
-
-        if (boot_type == 'hybrid') {
-            // Run the qcow2 UEFI boot test.
-            sh (
-                label: "Integration test: QCOW2, UEFI boot",
-                script: "/usr/libexec/tests/osbuild-composer/qemu.sh qcow2 uefi"
-            )
-        }
-
-        // Run the openstack test.
-        sh (
-            label: "Integration test: OpenStack",
-            script: "/usr/libexec/tests/osbuild-composer/qemu.sh openstack"
-        )
-
-        // Run the VHD/Azure test.
-        sh (
-            label: "Integration test: VHD",
-            script: "/usr/libexec/tests/osbuild-composer/qemu.sh vhd"
+            label: "Integration test: libvirt",
+            script: "/usr/libexec/tests/osbuild-composer/libvirt.sh"
         )
 
         // Run the AWS test.


Test patch:
diff --git a/test/cases/libvirt.sh b/test/cases/libvirt.sh
new file mode 100644
index 000000000..080397c06
--- /dev/null
+++ b/test/cases/libvirt.sh
@@ -0,0 +1,18 @@
+#!/bin/bash
+set -euo pipefail
+
+# Get OS data.
+source /etc/os-release
+
+# Provision the software under test.
+/usr/libexec/osbuild-composer-test/provision.sh
+
+# Test the images
+/usr/libexec/osbuild-composer-test/libvirt_test.sh qcow2
+/usr/libexec/osbuild-composer-test/libvirt_test.sh openstack
+/usr/libexec/osbuild-composer-test/libvirt_test.sh vhd
+
+# RHEL 8.4 images also supports uefi, check that
+if [[ "${ID}-${VERSION_ID}" == "rhel-8.4" ]]; then
+  /usr/libexec/osbuild-composer-test/libvirt_test.sh qcow2 uefi
+fi
diff --git a/test/data/manifests/rhel_84-x86_64-qcow2-boot.json b/test/data/manifests/rhel_84-x86_64-qcow2-boot.json
index a7659b5a1..f3730e487 100644
--- a/test/data/manifests/rhel_84-x86_64-qcow2-boot.json
+++ b/test/data/manifests/rhel_84-x86_64-qcow2-boot.json
@@ -3496,7 +3496,7 @@
           },
           "format": "qcow2",
           "filename": "disk.qcow2",
-          "size": 4294967296,
+          "size": 10737418240,
           "ptuuid": "D209C89E-EA5E-4FBD-B161-B461CCE297E0",
           "pttype": "gpt",
           "partitions": [
@@ -10105,7 +10105,7 @@
         "fstype": "xfs",
         "label": "root",
         "partuuid": "6264D520-3FB9-423F-8AB8-7A0A8E3D3562",
-        "size": 4187995648,
+        "size": 10630446592,
         "start": 106954752,
         "type": "0FC63DAF-8483-4772-8E79-3D69D8477DE4",
         "uuid": "efe8afea-c0a8-45dc-8e6e-499279f6fa5d"
@@ -10239,4 +10239,4 @@
     ],
     "timezone": "UTC"
   }
-}
\ No newline at end of file
+}
diff --git a/test/data/manifests/rhel_84-x86_64-qcow2-customize.json b/test/data/manifests/rhel_84-x86_64-qcow2-customize.json
index 73f9e625d..92d812a04 100644
--- a/test/data/manifests/rhel_84-x86_64-qcow2-customize.json
+++ b/test/data/manifests/rhel_84-x86_64-qcow2-customize.json
@@ -3606,7 +3606,7 @@
           },
           "format": "qcow2",
           "filename": "disk.qcow2",
-          "size": 4294967296,
+          "size": 10737418240,
           "ptuuid": "D209C89E-EA5E-4FBD-B161-B461CCE297E0",
           "pttype": "gpt",
           "partitions": [
@@ -10217,7 +10217,7 @@
         "fstype": "xfs",
         "label": "root",
         "partuuid": "6264D520-3FB9-423F-8AB8-7A0A8E3D3562",
-        "size": 4187995648,
+        "size": 10630446592,
         "start": 106954752,
         "type": "0FC63DAF-8483-4772-8E79-3D69D8477DE4",
         "uuid": "efe8afea-c0a8-45dc-8e6e-499279f6fa5d"
@@ -10353,4 +10353,4 @@
     ],
     "timezone": "London"
   }
-}
\ No newline at end of file
+}
diff --git a/test/cases/qemu.sh b/tools/libvirt_test.sh
similarity index 99%
rename from test/cases/qemu.sh
rename to tools/libvirt_test.sh
index 5f9ecc7f1..432cee154 100755
--- a/test/cases/qemu.sh
+++ b/tools/libvirt_test.sh
@@ -7,9 +7,6 @@ OSBUILD_COMPOSER_TEST_DATA=/usr/share/tests/osbuild-composer/
 source /etc/os-release
 ARCH=$(uname -m)
 
-# Provision the software under tet.
-/usr/libexec/osbuild-composer-test/provision.sh
-
 # Take the image type passed to the script or use qcow2 by default if nothing
 # was passed.
 IMAGE_TYPE=${1:-qcow2}