forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
marketplace_utils.go
65 lines (57 loc) · 1.79 KB
/
marketplace_utils.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
57
58
59
60
61
62
63
64
65
package marketplace
import (
"fmt"
"strings"
o "github.com/onsi/gomega"
exutil "github.com/openshift/origin/test/extended/util"
e2e "k8s.io/kubernetes/test/e2e/framework"
)
//create objects by yaml in the cluster
func createResources(oc *exutil.CLI, yamlfile string) error {
yaml := fmt.Sprint(yamlfile)
e2e.Logf("Start to create Resource: %s", yaml)
err := oc.AsAdmin().WithoutNamespace().Run("create").Args("-f", yaml).Execute()
o.Expect(err).NotTo(o.HaveOccurred())
if err != nil {
e2e.Failf("Unable to create file:%s", yaml)
return err
}
return nil
}
// delete objects in the cluster
func clearResources(oc *exutil.CLI, resourcetype string, name string, ns string) error {
msg, err := oc.AsAdmin().WithoutNamespace().Run("delete").Args("-n", ns, resourcetype, name).Output()
if err != nil {
errstring := fmt.Sprintf("%v", msg)
if strings.Contains(errstring, "NotFound") {
return nil
}
return err
}
return nil
}
//check the resource exist or not
func existResources(oc *exutil.CLI, resourcetype string, name string, ns string) (b bool, e error) {
msg, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("-n", ns, resourcetype, name).Output()
if err != nil {
errstring := fmt.Sprintf("%v", msg)
if strings.Contains(errstring, "NotFound") {
return false, nil
}
e2e.Failf("Can't get resource:%s", name)
return false, err
}
return true, nil
}
func getResourceByPath(oc *exutil.CLI, resourcetype string, name string, path string, ns string) (msg string, e error) {
msg, err := oc.AsAdmin().WithoutNamespace().Run("get").Args("-n", ns, resourcetype, name, path).Output()
if err != nil {
errstring := fmt.Sprintf("%v", msg)
if strings.Contains(errstring, "NotFound") {
return msg, nil
}
e2e.Failf("Can't get resource:%s", name)
return msg, err
}
return msg, nil
}