worker: log failures in ostree resolve job

This commit is contained in:
Sanne Raymaekers 2022-11-16 16:43:52 +01:00 committed by Achilleas Koutsou
parent 422281698a
commit 28319f50d8
4 changed files with 8 additions and 6 deletions

View file

@ -60,6 +60,7 @@ func (impl *OSTreeResolveJobImpl) Run(job worker.Job) error {
ref, checksum, err := ostree.ResolveParams(reqParams)
if err != nil {
logWithId.Infof("Resolving ostree params failed: %v", err)
setError(err, &result)
break
}

View file

@ -4,6 +4,7 @@ import (
"crypto/tls"
"crypto/x509"
"encoding/hex"
"fmt"
"io/ioutil"
"net/http"
"net/url"
@ -61,7 +62,7 @@ func VerifyRef(ref string) bool {
func ResolveRef(location, ref string, consumerCerts bool, subs *rhsm.Subscriptions) (string, error) {
u, err := url.Parse(location)
if err != nil {
return "", NewResolveRefError(err.Error())
return "", NewResolveRefError(fmt.Sprintf("error parsing ostree repository location: %v", err))
}
u.Path = path.Join(u.Path, "refs/heads/", ref)
@ -109,14 +110,14 @@ func ResolveRef(location, ref string, consumerCerts bool, subs *rhsm.Subscriptio
resp, err := client.Do(req)
if err != nil {
return "", NewResolveRefError(err.Error())
return "", NewResolveRefError(fmt.Sprintf("error sending request to ostree repository %q: %v", u.String(), err))
}
if resp.StatusCode != http.StatusOK {
return "", NewResolveRefError("ostree repository %q returned status: %s", u.String(), resp.Status)
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return "", NewResolveRefError(err.Error())
return "", NewResolveRefError(fmt.Sprintf("error reading response from ostree repository %q: %v", u.String(), err))
}
parent := strings.TrimSpace(string(body))
// Check that this is at least a hex string.

View file

@ -85,8 +85,8 @@ func TestOstreeResolveRef(t *testing.T) {
}
errCases := map[input]string{
{"not-a-url", "a-bad-ref"}: "Get \"not-a-url/refs/heads/a-bad-ref\": unsupported protocol scheme \"\"",
{"http://0.0.0.0:10/repo", "whatever"}: "Get \"http://0.0.0.0:10/repo/refs/heads/whatever\": dial tcp 0.0.0.0:10: connect: connection refused",
{"not-a-url", "a-bad-ref"}: "error sending request to ostree repository \"not-a-url/refs/heads/a-bad-ref\": Get \"not-a-url/refs/heads/a-bad-ref\": unsupported protocol scheme \"\"",
{"http://0.0.0.0:10/repo", "whatever"}: "error sending request to ostree repository \"http://0.0.0.0:10/repo/refs/heads/whatever\": Get \"http://0.0.0.0:10/repo/refs/heads/whatever\": dial tcp 0.0.0.0:10: connect: connection refused",
{srvConf.Srv.URL, "rhel/8/x86_64/edge"}: fmt.Sprintf("ostree repository \"%s/refs/heads/rhel/8/x86_64/edge\" returned status: 404 Not Found", srvConf.Srv.URL),
{srvConf.Srv.URL, "test_forbidden"}: fmt.Sprintf("ostree repository \"%s/refs/heads/test_forbidden\" returned status: 403 Forbidden", srvConf.Srv.URL),
{srvConf.Srv.URL, "get_bad_ref"}: fmt.Sprintf("ostree repository \"%s/refs/heads/get_bad_ref\" returned invalid reference", srvConf.Srv.URL),

View file

@ -1141,7 +1141,7 @@ func TestCompose(t *testing.T) {
"/api/v1/compose",
fmt.Sprintf(`{"blueprint_name": "test","compose_type":"%s","branch":"master","ostree":{"ref":"whatever","parent":"","url":"invalid-url"}}`, test_distro.TestImageTypeOSTree),
http.StatusBadRequest,
`{"status":false,"errors":[{"id":"OSTreeOptionsError","msg":"Get \"invalid-url/refs/heads/whatever\": unsupported protocol scheme \"\""}]}`,
`{"status":false,"errors":[{"id":"OSTreeOptionsError","msg":"error sending request to ostree repository \"invalid-url/refs/heads/whatever\": Get \"invalid-url/refs/heads/whatever\": unsupported protocol scheme \"\""}]}`,
nil,
[]string{"build_id"},
},