forked from openshift/openshift-client-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcoverage.py
More file actions
executable file
·159 lines (126 loc) · 4.77 KB
/
coverage.py
File metadata and controls
executable file
·159 lines (126 loc) · 4.77 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/usr/bin/python
from __future__ import print_function
from __future__ import absolute_import
import openshift_client as oc
from openshift_client import null, Missing, OpenShiftPythonException
try:
print("Projects created by users:", oc.selector("projects").narrow(
lambda prj: prj.metadata.annotations["openshift.io/requester"] is not Missing
).qnames())
oc.selector("projects").narrow(
# Eliminate any projects created by the system
lambda prj: prj.metadata.annotations["openshift.io/requester"] is not Missing
).narrow(
# Select from user projects any which violate privileged naming convention
lambda prj:
prj.metadata.qname == "openshift" or
prj.metadata.qname.startswith("openshift-") or
prj.metadata.qname == "kubernetes" or
prj.metadata.qname.startswith("kube-") or
prj.metadata.qname.startswith("kubernetes-")
).for_each(
lambda prj: oc.error("Invalid project: %s" % prj.metadata.qname)
)
with oc.timeout(5):
success, obj = oc.selector("pods").until_any(lambda pod: pod.status.phase == "Succeeded")
if success:
print("Found one pod was successful: " + str(obj))
with oc.timeout(5):
success, obj = oc.selector("pods").narrow("pod").until_any(
lambda pod: pod.status.conditions.can_match({"type": "Ready", "status": False, "reason": "PodCompleted"}))
if success:
print("Found one pod was successful: " + str(obj))
with oc.project("myproject") as project:
project.create_if_absent(
{
"apiVersion": "v1",
"kind": "User",
"fullName": "Jane Doe",
"groups": null,
"identities": [
"github:19783215"
],
"metadata": {
"name": "jane"
}
}
)
project.create_if_absent(
{
"apiVersion": "v1",
"kind": "User",
"fullName": "John Doe",
"groups": null,
"identities": [
"github:19783216"
],
"metadata": {
"name": "john"
}
}
)
pods = oc.selector("pod")
print("Pods: " + str(pods.qnames()))
users = oc.selector("user/john", "user/jane")
print("Describing users:\n")
users.describe()
for user in users:
print(str(user))
john = oc.selector("user/john")
john.label({"mylabel": null}) # remove a label
label_selector = oc.selector("users", labels={"mylabel": "myvalue"})
print("users with label step 1: " + str(label_selector.qnames()))
john.label({"mylabel": "myvalue"}) # add the label back
print("users with label step 2: " + str(label_selector.qnames()))
assert(label_selector.qnames()[0] == u'users/john')
users.label({"another_label": "another_value"})
john.object().patch({
"groups": null,
"identities": [
"github: 19783215"
]
},
)
# Unmarshal json into py objects
user_objs = users.objects()
print("Unmarshalled %d objects" % len(user_objs))
for user in user_objs:
if user.metadata.labels.another_label is not Missing:
print("Value of label: " + user.metadata.labels.another_label)
if user.notthere.dontcare.wontbreak is not Missing:
print("Should see this, but also shouldn't see exception")
project.delete_if_present("user/bark", "user/bite")
bark_obj = {
"apiVersion": "v1",
"kind": "User",
"fullName": "Bark Doe",
"groups": null,
"identities": [
"github:9999"
],
"metadata": {
"name": "bark"
}
}
bite_obj = {
"apiVersion": "v1",
"kind": "User",
"fullName": "Bite Doe",
"groups": null,
"identities": [
"github:10000"
],
"metadata": {
"name": "bite"
}
}
bark_bite_sel = oc.create([bark_obj, bite_obj])
print("How were they created?\n" + str(bark_bite_sel))
try:
oc.create(bark_obj) # Should create an error
assert False
except OpenShiftPythonException as create_err:
print("What went wrong?: " + str(create_err))
bark_bite_sel.until_any(lambda obj: obj.metadata.qname == "bite")
except OpenShiftPythonException as e:
print("An exception occurred: " + str(e))