-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprovisiontest.go
More file actions
87 lines (65 loc) · 1.75 KB
/
provisiontest.go
File metadata and controls
87 lines (65 loc) · 1.75 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package provisiontest
import (
"context"
"fmt"
"time"
"github.com/cenkalti/backoff"
"github.com/rs/zerolog/log"
"github.com/threefoldtech/zosbase/pkg/perf"
"github.com/threefoldtech/zosbase/pkg/stubs"
)
const (
id = "provisiontest"
schedule = "0 0 0 * * *"
description = "daily provision test that deploys a test VM to verify the node can run virtual machines and sets flags for the power daemon"
)
type provisionTestTask struct{}
var _ perf.Task = (*provisionTestTask)(nil)
func NewTask() perf.Task {
return &provisionTestTask{}
}
func (t *provisionTestTask) ID() string {
return id
}
func (t *provisionTestTask) Cron() string {
return schedule
}
func (t *provisionTestTask) Description() string {
return description
}
func (t *provisionTestTask) Jitter() uint32 {
return 30 * 60
}
func (t *provisionTestTask) Run(ctx context.Context) (interface{}, error) {
log.Debug().Msg("starting provision test task")
cl := perf.MustGetZbusClient(ctx)
zui := stubs.NewZUIStub(cl)
var result []string
op := func() error {
errs := vmCheck(ctx)
result = errorsToStrings(errs)
if err := zui.PushErrors(ctx, "vm", result); err != nil {
return err
}
if len(errs) != 0 {
return fmt.Errorf("provision test failed: %s", result)
}
return nil
}
notify := func(err error, t time.Duration) {
log.Error().Err(err).Dur("retry-in", t).Msg("failed provision test. retrying")
}
bo := backoff.NewExponentialBackOff()
bo.InitialInterval = 3 * time.Minute
bo.MaxInterval = 30 * time.Second
bo.MaxElapsedTime = 10 * time.Minute
_ = backoff.RetryNotify(op, bo, notify)
return result, nil
}
func errorsToStrings(errs []error) []string {
s := make([]string, 0, len(errs))
for _, err := range errs {
s = append(s, err.Error())
}
return s
}