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=gcr.io/heptio-images
41 ... name=sonobuoy:v0.16.1
43 ... name=Actual value set dynamically
44 &{SYSTEMD_LOGS} path=akraino
45 ... name=validation:sonobuoy-plugin-systemd-logs-latest
46 &{SONOBUOY_IMGS} sonobuoy=&{SONOBUOY}
48 ... systemd_logs=&{SYSTEMD_LOGS}
50 # Following tests assume DNS domain is "cluster.local"
51 ${DNS_DOMAIN_TESTS} SEPARATOR=
52 ... DNS should provide /etc/hosts entries for the cluster|
53 ... DNS should provide DNS for services|
54 ... DNS should provide DNS for ExternalName services|
55 ... DNS should provide DNS for the cluster|
56 ... DNS should provide DNS for pods for Subdomain|
57 ... DNS should provide DNS for pods for Hostname
59 # Images listed by Sonobuoy but not available for downloading
60 @{SKIP_IMGS} gcr.io/kubernetes-e2e-test-images/windows-nanoserver:v1
61 ... gcr.io/authenticated-image-pulling/windows-nanoserver:v1
62 ... gcr.io/authenticated-image-pulling/alpine:3.7
63 ... k8s.gcr.io/invalid-image:invalid-tag
64 ... invalid.com/invalid/alpine:3.1
67 Run Sonobuoy Conformance Test
69 Run kubectl apply -f ${CURDIR}${/}sonobuoy.yaml
71 ${rc} ${output}= Run And Return Rc And Output
72 ... kubectl describe pod/sonobuoy -n sonobuoy
73 Append To File ${LOG} ${output}${\n}
75 # Wait until the test finishes execution
76 Wait Until Keyword Succeeds 3x 20 sec Check that sonobuoy is running
77 Run while sonobuoy status | grep "Sonobuoy is still running"; do sleep 180; done
78 Append To File ${LOG} "Sonobuoy has completed"${\n}
80 # Get the result and store the sonobuoy logs
81 ${rc} ${output}= Run And Return Rc And Output
82 ... results=$(sonobuoy retrieve ${LOG_PATH}) && sonobuoy e2e $results
83 Append To File ${LOG} ${output}${\n}
84 Should Contain ${output} failed tests: 0
87 Check that k8s cluster is reachable
88 # Check that the config file is mounted in the container
89 File Should Not Be Empty /root/.kube/config
91 # Make sure the pod is reachable with the local k8s client
92 ${rc} ${output}= Run And Return Rc And Output
94 Append To File ${LOG} ${output}${\n}
95 Should Contain ${output} Server Version: version.Info
97 Check that sonobuoy is running
98 ${output}= Run kubectl get pod sonobuoy --namespace sonobuoy
99 Should Contain ${output} Running
102 ${rc} ${output}= Run And Return Rc And Output
103 ... kubectl delete -f ${CURDIR}${/}sonobuoy.yaml
104 Append To File ${LOG} ${output}${\n}
106 Should Contain ${output} service "sonobuoy-master" deleted
108 Open Connection And Log In
109 Open Connection ${HOST}
110 Login With Public Key ${USERNAME} ${SSH_KEYFILE}
112 Upload To Internal Registry
113 [Arguments] ${path} ${name}
114 ${rc}= Execute Command
115 ... docker pull ${path}/${name}
116 ... return_stdout=False return_rc=True
117 Should Be Equal As Integers ${rc} 0
118 ${rc}= Execute Command
119 ... docker tag ${path}/${name} ${INT_REG}/bluval/${name}
120 ... return_stdout=False return_rc=True
121 Should Be Equal As Integers ${rc} 0
122 ${rc}= Execute Command
123 ... docker push ${INT_REG}/bluval/${name}
124 ... return_stdout=False return_rc=True
125 Should Be Equal As Integers ${rc} 0
127 Onboard Sonobuoy Images
128 FOR ${img} IN @{SONOBUOY_IMGS}
129 ${path}= Get From Dictionary ${SONOBUOY_IMGS['${img}']} path
130 ${name}= Get From Dictionary ${SONOBUOY_IMGS['${img}']} name
131 Upload To Internal Registry ${path} ${name}
132 Set To Dictionary ${SONOBUOY_IMGS['${img}']} path=${INT_REG}/bluval
135 Onboard Kubernetes e2e Test Images
136 ${result}= Run Process sonobuoy images
137 Should Be Equal As Integers ${result.rc} 0
138 @{images}= Split String ${result.stdout}
139 FOR ${img} IN @{images}
140 Continue For Loop If $img in $SKIP_IMGS
141 ${path} ${name} Split String From Right ${img} / 1
142 Upload To Internal Registry ${path} ${name}
146 ${result}= Run Process kubectl version -o json
147 Should Be Equal As Integers ${result.rc} 0
148 ${versions}= Convert String To JSON ${result.stdout}
149 ${major}= Get Value From Json ${versions} $.serverVersion.major
150 ${minor}= Get Value From Json ${versions} $.serverVersion.minor
151 ${major}= Get Regexp Matches ${major[0]} \\d+
152 ${minor}= Get Regexp Matches ${minor[0]} \\d+
153 Set To Dictionary ${SONOBUOY_IMGS['e2e']} name=validation:kube-conformance-v${major[0]}.${minor[0]}
156 ${INT_REG}= Get Variable Value ${INTERNAL_REGISTRY} ${EMPTY}
157 Set Test Variable ${INT_REG}
158 Return From Keyword If $INT_REG == '${EMPTY}'
159 Open Connection And Log In
160 Onboard Sonobuoy Images
161 Onboard Kubernetes e2e Test Images
164 ${flag}= Set Variable Aggregator|Alpha|\\[(Disruptive|Feature:[^\\]]+|Flaky)\\]
165 ${flag}= Run Keyword If '${DNS_DOMAIN}' != 'cluster.local'
166 ... Catenate SEPARATOR=| ${flag} ${DNS_DOMAIN_TESTS}
168 ... Set Variable ${flag}
172 ${skip}= Get Tests To Skip
173 @{flags}= Set Variable
174 ... --e2e-focus \\[Conformance\\\]
175 ... --e2e-skip ${skip}
176 ... --kube-conformance-image ${SONOBUOY_IMGS.e2e.path}/${SONOBUOY_IMGS.e2e.name}
177 ... --sonobuoy-image ${SONOBUOY_IMGS.sonobuoy.path}/${SONOBUOY_IMGS.sonobuoy.name}
178 ... --image-pull-policy Always
180 Run Keyword If $INT_REG != '${EMPTY}' Run Keywords
181 ... Append To List ${flags}
182 ... --e2e-repo-config ${CURDIR}${/}custom_repos.yaml
184 ... Run Process sed -i s|{{ registry }}|${INT_REG}/bluval|g
185 ... ${CURDIR}${/}custom_repos.yaml
186 ${result}= Run Process sonobuoy gen @{flags}
187 Should Be Equal As Integers ${result.rc} 0
188 ${manifest}= Replace String ${result.stdout}
189 ... image: gcr.io/heptio-images/sonobuoy-plugin-systemd-logs:latest
190 ... image: ${SONOBUOY_IMGS.systemd_logs.path}/${SONOBUOY_IMGS.systemd_logs.name}
191 Create File ${CURDIR}${/}sonobuoy.yaml ${manifest}