1 ##############################################################################
2 # Copyright (c) 2019 AT&T Intellectual Property. #
3 # Copyright (c) 2019 Nokia. #
4 # Copyright (c) 2019 Enea AB
6 # Licensed under the Apache License, Version 2.0 (the "License"); #
7 # you maynot use this file except in compliance with the License. #
9 # You may obtain a copy of the License at #
10 # http://www.apache.org/licenses/LICENSE-2.0 #
12 # Unless required by applicable law or agreed to in writing, software #
13 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT #
14 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
15 # See the License for the specific language governing permissions and #
16 # limitations under the License. #
17 ##############################################################################
20 Documentation Run k8s conformance test using sonobuoy
21 Library OperatingSystem
28 Test Setup Run Keywords
29 ... Check that k8s cluster is reachable
32 ... Create Manifest File
33 Test Teardown Run Keywords
35 ... Close All Connections
38 ${LOG} ${LOG_PATH}${/}${SUITE_NAME.replace(' ','_')}.log
40 &{SONOBUOY} path=sonobuoy
41 ... name=sonobuoy:v0.18.2
42 &{E2E} path=k8s.gcr.io
43 ... name=Actual value set dynamically
44 &{SONOBUOY_IMGS} sonobuoy=&{SONOBUOY}
47 # Following tests assume DNS domain is "cluster.local"
48 ${DNS_DOMAIN_TESTS} SEPARATOR=
49 ... DNS should provide /etc/hosts entries for the cluster|
50 ... DNS should provide DNS for services|
51 ... DNS should provide DNS for ExternalName services|
52 ... DNS should provide DNS for the cluster|
53 ... DNS should provide DNS for pods for Subdomain|
54 ... DNS should provide DNS for pods for Hostname
56 # Images listed by Sonobuoy but not available for downloading
57 @{SKIP_IMGS} gcr.io/kubernetes-e2e-test-images/windows-nanoserver:v1
58 ... gcr.io/authenticated-image-pulling/windows-nanoserver:v1
59 ... gcr.io/authenticated-image-pulling/alpine:3.7
60 ... k8s.gcr.io/invalid-image:invalid-tag
61 ... invalid.com/invalid/alpine:3.1
64 Run Sonobuoy Conformance Test
66 Run kubectl apply -f ${CURDIR}${/}sonobuoy.yaml
68 ${rc} ${output}= Run And Return Rc And Output
69 ... kubectl describe pod/sonobuoy -n sonobuoy
70 Append To File ${LOG} ${output}${\n}
72 # Wait until the test finishes execution
73 Wait Until Keyword Succeeds 3x 20 sec Check that sonobuoy is running
74 Run while sonobuoy status | grep "Sonobuoy is still running"; do sleep 180; done
75 Append To File ${LOG} "Sonobuoy has completed"${\n}
77 # Get the result and store the sonobuoy logs
78 ${rc} ${output}= Run And Return Rc And Output
79 ... results=$(sonobuoy retrieve ${LOG_PATH}) && sonobuoy e2e $results
80 Append To File ${LOG} ${output}${\n}
81 Should Contain ${output} failed tests: 0
84 Check that k8s cluster is reachable
85 # Check that the config file is mounted in the container
86 File Should Not Be Empty /root/.kube/config
88 # Make sure the pod is reachable with the local k8s client
89 ${rc} ${output}= Run And Return Rc And Output
91 Append To File ${LOG} ${output}${\n}
92 Should Contain ${output} Server Version: version.Info
94 Check that sonobuoy is running
95 ${output}= Run kubectl get pod sonobuoy --namespace sonobuoy
96 Should Contain ${output} Running
99 ${rc} ${output}= Run And Return Rc And Output
100 ... kubectl delete -f ${CURDIR}${/}sonobuoy.yaml
101 Append To File ${LOG} ${output}${\n}
103 Should Contain ${output} service "sonobuoy-master" deleted
105 Open Connection And Log In
106 Open Connection ${HOST}
107 Login With Public Key ${USERNAME} ${SSH_KEYFILE}
109 Upload To Internal Registry
110 [Arguments] ${path} ${name}
111 ${rc}= Execute Command
112 ... docker pull ${path}/${name}
113 ... return_stdout=False return_rc=True
114 Should Be Equal As Integers ${rc} 0
115 ${rc}= Execute Command
116 ... docker tag ${path}/${name} ${INT_REG}/bluval/${name}
117 ... return_stdout=False return_rc=True
118 Should Be Equal As Integers ${rc} 0
119 ${rc}= Execute Command
120 ... docker push ${INT_REG}/bluval/${name}
121 ... return_stdout=False return_rc=True
122 Should Be Equal As Integers ${rc} 0
124 Onboard Sonobuoy Images
125 FOR ${img} IN @{SONOBUOY_IMGS}
126 ${path}= Get From Dictionary ${SONOBUOY_IMGS['${img}']} path
127 ${name}= Get From Dictionary ${SONOBUOY_IMGS['${img}']} name
128 Upload To Internal Registry ${path} ${name}
129 Set To Dictionary ${SONOBUOY_IMGS['${img}']} path=${INT_REG}/bluval
132 Onboard Kubernetes e2e Test Images
133 ${result}= Run Process sonobuoy images
134 Should Be Equal As Integers ${result.rc} 0
135 @{images}= Split String ${result.stdout}
136 FOR ${img} IN @{images}
137 Continue For Loop If $img in $SKIP_IMGS
138 ${path} ${name} Split String From Right ${img} / 1
139 Upload To Internal Registry ${path} ${name}
143 ${result}= Run Process kubectl version -o json
144 Should Be Equal As Integers ${result.rc} 0
145 ${versions}= Convert String To JSON ${result.stdout}
146 ${gitVersion}= Get Value From Json ${versions} $.serverVersion.gitVersion
147 Set To Dictionary ${SONOBUOY_IMGS['e2e']} name=conformance:${gitVersion[0]}
150 ${INT_REG}= Get Variable Value ${INTERNAL_REGISTRY} ${EMPTY}
151 Set Test Variable ${INT_REG}
152 Return From Keyword If $INT_REG == '${EMPTY}'
153 Open Connection And Log In
154 Onboard Sonobuoy Images
155 Onboard Kubernetes e2e Test Images
158 ${flag}= Set Variable Aggregator|Alpha|\\[(Disruptive|Feature:[^\\]]+|Flaky)\\]
159 ${flag}= Run Keyword If '${DNS_DOMAIN}' != 'cluster.local'
160 ... Catenate SEPARATOR=| ${flag} ${DNS_DOMAIN_TESTS}
162 ... Set Variable ${flag}
166 ${skip}= Get Tests To Skip
167 @{flags}= Set Variable
168 ... --e2e-focus \\[Conformance\\\]
169 ... --e2e-skip ${skip}
170 ... --kube-conformance-image ${SONOBUOY_IMGS.e2e.path}/${SONOBUOY_IMGS.e2e.name}
171 ... --sonobuoy-image ${SONOBUOY_IMGS.sonobuoy.path}/${SONOBUOY_IMGS.sonobuoy.name}
172 ... --image-pull-policy Always
174 Run Keyword If $INT_REG != '${EMPTY}' Run Keywords
175 ... Append To List ${flags}
176 ... --e2e-repo-config ${CURDIR}${/}custom_repos.yaml
178 ... Run Process sed -i s|{{ registry }}|${INT_REG}/bluval|g
179 ... ${CURDIR}${/}custom_repos.yaml
180 ${result}= Run Process sonobuoy gen @{flags}
181 Should Be Equal As Integers ${result.rc} 0
182 Create File ${CURDIR}${/}sonobuoy.yaml ${result.stdout}