-
Notifications
You must be signed in to change notification settings - Fork 130
Expand file tree
/
Copy pathrunner.go
More file actions
71 lines (60 loc) · 2.2 KB
/
runner.go
File metadata and controls
71 lines (60 loc) · 2.2 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
package helper
import (
"fmt"
"os"
"path/filepath"
. "github.com/onsi/gomega"
"github.com/openshift/osde2e/pkg/common/aws"
viper "github.com/openshift/osde2e/pkg/common/concurrentviper"
"github.com/openshift/osde2e/pkg/common/config"
"github.com/openshift/osde2e/pkg/common/mainjobrunner"
)
// RunnerWithNoCommand creates an extended test suite runner and configure RBAC for it.
func (h *H) RunnerWithNoCommand() *mainjobrunner.MainJobRunner {
r := mainjobrunner.DefaultMainJobRunner.DeepCopy()
// setup clients
r.Kube = h.Kube()
r.Image = h.Image()
// setup tests
r.Namespace = h.CurrentProject()
r.PodSpec.ServiceAccountName = h.GetNamespacedServiceAccount()
return r
}
// SetRunnerProject sets namespace for runner pod
func (h *H) SetRunnerProject(project string, r *mainjobrunner.MainJobRunner) *mainjobrunner.MainJobRunner {
r.Namespace = project
return r
}
// SetRunnerCommand sets given command to a pod runner
func (h *H) SetRunnerCommand(cmd string, r *mainjobrunner.MainJobRunner) *mainjobrunner.MainJobRunner {
r.Cmd = cmd
return r
}
// Runner creates an extended test suite runner and configure RBAC for it and runs cmd in it.
func (h *H) Runner(cmd string) *mainjobrunner.MainJobRunner {
r := h.RunnerWithNoCommand()
r.PodSpec.ServiceAccountName = h.GetNamespacedServiceAccount()
r.Cmd = cmd
return r
}
// WriteResults dumps runner results into the ReportDir.
func (h *H) WriteResults(results map[string][]byte) {
for filename, data := range results {
dst := filepath.Join(viper.GetString(config.ReportDir), viper.GetString(config.Phase), filename)
err := os.MkdirAll(filepath.Dir(dst), os.FileMode(0o755))
Expect(err).NotTo(HaveOccurred())
err = os.WriteFile(dst, data, os.ModePerm)
Expect(err).NotTo(HaveOccurred())
}
}
// UploadResultsToS3 dumps runner results into the s3 bucket in given aws session.
func (h *H) UploadResultsToS3(results map[string][]byte, key string) error {
for filename, data := range results {
session, err := aws.CcsAwsSession.GetSession()
if err != nil {
return fmt.Errorf("error getting aws session: %v", err)
}
aws.WriteToS3Session(session, aws.CreateS3URL(viper.GetString(config.Tests.LogBucket), key, filepath.Base(filename)), data)
}
return nil
}