Select kube-conformance version dynamically
[validation.git] / tests / k8s / conformance / conformance.robot
1 ##############################################################################
2 # Copyright (c) 2019 AT&T Intellectual Property.                             #
3 # Copyright (c) 2019 Nokia.                                                  #
4 # Copyright (c) 2019 Enea AB
5 #                                                                            #
6 # Licensed under the Apache License, Version 2.0 (the "License");            #
7 # you maynot use this file except in compliance with the License.            #
8 #                                                                            #
9 # You may obtain a copy of the License at                                    #
10 #       http://www.apache.org/licenses/LICENSE-2.0                           #
11 #                                                                            #
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 ##############################################################################
18
19 *** Settings ***
20 Documentation     Run k8s conformance test using sonobuoy
21 Library           OperatingSystem
22 Library           BuiltIn
23 Library           Collections
24 Library           String
25 Library           SSHLibrary
26 Library           Process
27 Library           JSONLibrary
28 Test Setup        Run Keywords
29 ...               Check that k8s cluster is reachable
30 ...               Define Images
31 ...               Onboard Images
32 ...               Create Manifest File
33 Test Teardown     Run Keywords
34 ...               Cleanup Sonobuoy
35 ...               Close All Connections
36
37 *** Variables ***
38 ${LOG}            ${LOG_PATH}${/}${SUITE_NAME.replace(' ','_')}.log
39
40 &{SONOBUOY}         path=gcr.io/heptio-images
41 ...                 name=sonobuoy:v0.16.1
42 &{E2E}              path=akraino
43 ...                 name=Actual value set dynamically
44 &{SYSTEMD_LOGS}     path=akraino
45 ...                 name=validation:sonobuoy-plugin-systemd-logs-latest
46 &{SONOBUOY_IMGS}    sonobuoy=&{SONOBUOY}
47 ...                 e2e=&{E2E}
48 ...                 systemd_logs=&{SYSTEMD_LOGS}
49
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
58
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
65
66 *** Test Cases ***
67 Run Sonobuoy Conformance Test
68         # Start the test
69         Run                     kubectl apply -f ${CURDIR}${/}sonobuoy.yaml
70         Sleep                   20s
71         ${rc}  ${output}=       Run And Return Rc And Output
72                                 ...  kubectl describe pod/sonobuoy -n sonobuoy
73         Append To File          ${LOG}  ${output}${\n}
74
75         # Wait until the test finishes execution
76         Run                     while sonobuoy status | grep "Sonobuoy is still running"; do sleep 180; done
77         Append To File          ${LOG}  "Sonobuoy has completed"${\n}
78
79         # Get the result and store the sonobuoy logs
80         ${rc}  ${output}=       Run And Return Rc And Output
81                                 ...  results=$(sonobuoy retrieve ${LOG_PATH}) && sonobuoy e2e $results
82         Append To File          ${LOG}  ${output}${\n}
83         Should Contain          ${output}       failed tests: 0
84
85 *** Keywords ***
86 Check that k8s cluster is reachable
87         # Check that the config file is mounted in the container
88         File Should Not Be Empty  /root/.kube/config
89
90         # Make sure the pod is reachable with the local k8s client
91         ${rc}  ${output}=       Run And Return Rc And Output
92                                 ...  kubectl version
93         Append To File          ${LOG}  ${output}${\n}
94         Should Contain          ${output}      Server Version: version.Info
95
96 Cleanup Sonobuoy
97         ${rc}  ${output}=       Run And Return Rc And Output
98                                 ...  kubectl delete -f ${CURDIR}${/}sonobuoy.yaml
99         Append To File          ${LOG}  ${output}${\n}
100         Sleep                   3s
101         Should Contain          ${output}      service "sonobuoy-master" deleted
102
103 Open Connection And Log In
104         Open Connection         ${HOST}
105         Login With Public Key   ${USERNAME}  ${SSH_KEYFILE}
106
107 Upload To Internal Registry
108          [Arguments]            ${path}  ${name}
109          ${rc}=  Execute Command
110          ...     docker pull ${path}/${name}
111          ...       return_stdout=False  return_rc=True
112          Should Be Equal As Integers  ${rc}  0
113          ${rc}=  Execute Command
114          ...     docker tag ${path}/${name} ${INT_REG}/bluval/${name}
115          ...       return_stdout=False  return_rc=True
116          Should Be Equal As Integers  ${rc}  0
117          ${rc}=  Execute Command
118          ...     docker push ${INT_REG}/bluval/${name}
119          ...       return_stdout=False  return_rc=True
120          Should Be Equal As Integers  ${rc}  0
121
122 Onboard Sonobuoy Images
123         FOR  ${img}  IN  @{SONOBUOY_IMGS}
124             ${path}=            Get From Dictionary  ${SONOBUOY_IMGS['${img}']}  path
125             ${name}=            Get From Dictionary  ${SONOBUOY_IMGS['${img}']}  name
126             Upload To Internal Registry  ${path}  ${name}
127             Set To Dictionary  ${SONOBUOY_IMGS['${img}']}  path=${INT_REG}/bluval
128         END
129
130 Onboard Kubernetes e2e Test Images
131         ${result}=              Run Process  sonobuoy  images
132         Should Be Equal As Integers  ${result.rc}  0
133         @{images}=              Split String  ${result.stdout}
134         FOR  ${img}  IN  @{images}
135             Continue For Loop If  $img in $SKIP_IMGS
136             ${path}  ${name}  Split String From Right  ${img}  /  1
137             Upload To Internal Registry  ${path}  ${name}
138         END
139
140 Define Images
141         ${result}=              Run Process  kubectl  version  -o  json
142         Should Be Equal As Integers  ${result.rc}  0
143         ${versions}=            Convert String To JSON  ${result.stdout}
144         ${major}=               Get Value From Json  ${versions}  $.serverVersion.major
145         ${minor}=               Get Value From Json  ${versions}  $.serverVersion.minor
146         Set To Dictionary       ${SONOBUOY_IMGS['e2e']}  name=validation:kube-conformance-v${major[0]}.${minor[0]}
147
148 Onboard Images
149         ${INT_REG}=             Get Variable Value  ${INTERNAL_REGISTRY}  ${EMPTY}
150         Set Test Variable       ${INT_REG}
151         Return From Keyword If  $INT_REG == '${EMPTY}'
152         Open Connection And Log In
153         Onboard Sonobuoy Images
154         Onboard Kubernetes e2e Test Images
155
156 Get Tests To Skip
157         ${flag}=                Set Variable  Aggregator|Alpha|\\[(Disruptive|Feature:[^\\]]+|Flaky)\\]
158         ${flag}=                Run Keyword If  '${DNS_DOMAIN}' != 'cluster.local'
159         ...                         Catenate  SEPARATOR=|  ${flag}  ${DNS_DOMAIN_TESTS}
160         ...                     ELSE
161         ...                         Set Variable  ${flag}
162         [Return]                ${flag}
163
164 Create Manifest File
165         ${skip}=                Get Tests To Skip
166         @{flags}=               Set Variable
167         ...                         --e2e-focus  \\[Conformance\\\]
168         ...                         --e2e-skip  ${skip}
169         ...                         --kube-conformance-image  ${SONOBUOY_IMGS.e2e.path}/${SONOBUOY_IMGS.e2e.name}
170         ...                         --sonobuoy-image  ${SONOBUOY_IMGS.sonobuoy.path}/${SONOBUOY_IMGS.sonobuoy.name}
171         ...                         --image-pull-policy  Always
172         ...                         --timeout  14400
173         Run Keyword If          $INT_REG != '${EMPTY}'  Run Keywords
174         ...                     Append To List  ${flags}
175         ...                         --e2e-repo-config  ${CURDIR}${/}custom_repos.yaml
176         ...                     AND
177         ...                     Run Process  sed  -i  s|{{ registry }}|${INT_REG}/bluval|g
178         ...                         ${CURDIR}${/}custom_repos.yaml
179         ${result}=              Run Process  sonobuoy  gen  @{flags}
180         Should Be Equal As Integers  ${result.rc}  0
181         ${manifest}=            Replace String  ${result.stdout}
182         ...                         image: gcr.io/heptio-images/sonobuoy-plugin-systemd-logs:latest
183         ...                         image: ${SONOBUOY_IMGS.systemd_logs.path}/${SONOBUOY_IMGS.systemd_logs.name}
184         Create File             ${CURDIR}${/}sonobuoy.yaml  ${manifest}