/
instance_sonobouy.go
56 lines (46 loc) · 1.14 KB
/
instance_sonobouy.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package handlers
import (
"bufio"
"bytes"
"io/ioutil"
"net/http"
"strings"
"github.com/gorilla/mux"
"github.com/replicatedhq/kurl/testgrid/tgapi/pkg/logger"
"github.com/replicatedhq/kurl/testgrid/tgapi/pkg/testinstance"
"go.uber.org/zap"
)
func InstanceSonobuoyResults(w http.ResponseWriter, r *http.Request) {
body, err := ioutil.ReadAll(r.Body)
if err != nil {
logger.Error(err)
JSON(w, 500, nil)
return
}
instanceID := mux.Vars(r)["instanceId"]
logger.Debug("instanceSonobuoyResults",
zap.String("instanceId", instanceID))
if err := testinstance.SetInstanceSonobuoyResults(instanceID, body); err != nil {
logger.Error(err)
JSON(w, 500, nil)
return
}
isSuccess := false
scanner := bufio.NewScanner(bytes.NewReader(body))
for scanner.Scan() {
line := scanner.Text()
if strings.HasPrefix(line, "Status:") {
isSuccess = strings.HasSuffix(line, "passed")
}
}
failureReason := ""
if !isSuccess {
failureReason = "sonobuoy_results"
}
if err := testinstance.SetInstanceFinishedAndSuccess(instanceID, isSuccess, failureReason); err != nil {
logger.Error(err)
JSON(w, 500, nil)
return
}
JSON(w, 200, nil)
}