[k8s][conformance] Check sonobuoy container runs
[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 Test Setup        Run Keywords
28 ...               Check that k8s cluster is reachable
29 ...               Onboard Images
30 ...               Create Manifest File
31 Test Teardown     Run Keywords
32 ...               Cleanup Sonobuoy
33 ...               Close All Connections
34
35 *** Variables ***
36 ${LOG}            ${LOG_PATH}${/}${SUITE_NAME.replace(' ','_')}.log
37
38 &{SONOBUOY}         path=gcr.io/heptio-images
39 ...                 name=sonobuoy:v0.16.1
40 &{E2E}              path=akraino
41 ...                 name=validation:kube-conformance-v1.16
42 &{SYSTEMD_LOGS}     path=akraino
43 ...                 name=validation:sonobuoy-plugin-systemd-logs-latest
44 &{SONOBUOY_IMGS}    sonobuoy=&{SONOBUOY}
45 ...                 e2e=&{E2E}
46 ...                 systemd_logs=&{SYSTEMD_LOGS}
47
48 # Following tests assume DNS domain is "cluster.local"
49 ${DNS_DOMAIN_TESTS}  SEPARATOR=
50 ...                 DNS should provide /etc/hosts entries for the cluster|
51 ...                 DNS should provide DNS for services|
52 ...                 DNS should provide DNS for ExternalName services|
53 ...                 DNS should provide DNS for the cluster|
54 ...                 DNS should provide DNS for pods for Subdomain|
55 ...                 DNS should provide DNS for pods for Hostname
56
57 # Images listed by Sonobuoy but not available for downloading
58 @{SKIP_IMGS}        gcr.io/kubernetes-e2e-test-images/windows-nanoserver:v1
59 ...                 gcr.io/authenticated-image-pulling/windows-nanoserver:v1
60 ...                 gcr.io/authenticated-image-pulling/alpine:3.7
61 ...                 k8s.gcr.io/invalid-image:invalid-tag
62 ...                 invalid.com/invalid/alpine:3.1
63
64 *** Test Cases ***
65 Run Sonobuoy Conformance Test
66         # Start the test
67         Run                     kubectl apply -f ${CURDIR}${/}sonobuoy.yaml
68         Sleep                   20s
69         ${rc}  ${output}=       Run And Return Rc And Output
70                                 ...  kubectl describe pod/sonobuoy -n sonobuoy
71         Append To File          ${LOG}  ${output}${\n}
72
73         # Wait until the test finishes execution
74         Wait Until Keyword Succeeds    3x    20 sec    Check that sonobuoy is running
75         Run                     while sonobuoy status | grep "Sonobuoy is still running"; do sleep 180; done
76         Append To File          ${LOG}  "Sonobuoy has completed"${\n}
77
78         # Get the result and store the sonobuoy logs
79         ${rc}  ${output}=       Run And Return Rc And Output
80                                 ...  results=$(sonobuoy retrieve ${LOG_PATH}) && sonobuoy e2e $results
81         Append To File          ${LOG}  ${output}${\n}
82         Should Contain          ${output}       failed tests: 0
83
84 *** Keywords ***
85 Check that k8s cluster is reachable
86         # Check that the config file is mounted in the container
87         File Should Not Be Empty  /root/.kube/config
88
89         # Make sure the pod is reachable with the local k8s client
90         ${rc}  ${output}=       Run And Return Rc And Output
91                                 ...  kubectl version
92         Append To File          ${LOG}  ${output}${\n}
93         Should Contain          ${output}      Server Version: version.Info
94
95 Check that sonobuoy is running
96        ${output}=              Run    kubectl get pod sonobuoy --namespace sonobuoy
97        Should Contain          ${output}     Running
98
99 Cleanup Sonobuoy
100         ${rc}  ${output}=       Run And Return Rc And Output
101                                 ...  kubectl delete -f ${CURDIR}${/}sonobuoy.yaml
102         Append To File          ${LOG}  ${output}${\n}
103         Sleep                   3s
104         Should Contain          ${output}      service "sonobuoy-master" deleted
105
106 Open Connection And Log In
107         Open Connection         ${HOST}
108         Login With Public Key   ${USERNAME}  ${SSH_KEYFILE}
109
110 Upload To Internal Registry
111          [Arguments]            ${path}  ${name}
112          ${rc}=  Execute Command
113          ...     docker pull ${path}/${name}
114          ...       return_stdout=False  return_rc=True
115          Should Be Equal As Integers  ${rc}  0
116          ${rc}=  Execute Command
117          ...     docker tag ${path}/${name} ${INT_REG}/bluval/${name}
118          ...       return_stdout=False  return_rc=True
119          Should Be Equal As Integers  ${rc}  0
120          ${rc}=  Execute Command
121          ...     docker push ${INT_REG}/bluval/${name}
122          ...       return_stdout=False  return_rc=True
123          Should Be Equal As Integers  ${rc}  0
124
125 Onboard Sonobuoy Images
126         FOR  ${img}  IN  @{SONOBUOY_IMGS}
127             ${path}=            Get From Dictionary  ${SONOBUOY_IMGS['${img}']}  path
128             ${name}=            Get From Dictionary  ${SONOBUOY_IMGS['${img}']}  name
129             Upload To Internal Registry  ${path}  ${name}
130             Set To Dictionary  ${SONOBUOY_IMGS['${img}']}  path=${INT_REG}/bluval
131         END
132
133 Onboard Kubernetes e2e Test Images
134         ${result}=              Run Process  sonobuoy  images
135         Should Be Equal As Integers  ${result.rc}  0
136         @{images}=              Split String  ${result.stdout}
137         FOR  ${img}  IN  @{images}
138             Continue For Loop If  $img in $SKIP_IMGS
139             ${path}  ${name}  Split String From Right  ${img}  /  1
140             Upload To Internal Registry  ${path}  ${name}
141         END
142
143 Onboard Images
144         ${INT_REG}=             Get Variable Value  ${INTERNAL_REGISTRY}  ${EMPTY}
145         Set Test Variable       ${INT_REG}
146         Return From Keyword If  $INT_REG == '${EMPTY}'
147         Open Connection And Log In
148         Onboard Sonobuoy Images
149         Onboard Kubernetes e2e Test Images
150
151 Get Tests To Skip
152         ${flag}=                Set Variable  Aggregator|Alpha|\\[(Disruptive|Feature:[^\\]]+|Flaky)\\]
153         ${flag}=                Run Keyword If  '${DNS_DOMAIN}' != 'cluster.local'
154         ...                         Catenate  SEPARATOR=|  ${flag}  ${DNS_DOMAIN_TESTS}
155         ...                     ELSE
156         ...                         Set Variable  ${flag}
157         [Return]                ${flag}
158
159 Create Manifest File
160         ${skip}=                Get Tests To Skip
161         @{flags}=               Set Variable
162         ...                         --e2e-focus  \\[Conformance\\\]
163         ...                         --e2e-skip  ${skip}
164         ...                         --kube-conformance-image  ${SONOBUOY_IMGS.e2e.path}/${SONOBUOY_IMGS.e2e.name}
165         ...                         --sonobuoy-image  ${SONOBUOY_IMGS.sonobuoy.path}/${SONOBUOY_IMGS.sonobuoy.name}
166         ...                         --image-pull-policy  Always
167         ...                         --timeout  14400
168         Run Keyword If          $INT_REG != '${EMPTY}'  Run Keywords
169         ...                     Append To List  ${flags}
170         ...                         --e2e-repo-config  ${CURDIR}${/}custom_repos.yaml
171         ...                     AND
172         ...                     Run Process  sed  -i  s|{{ registry }}|${INT_REG}/bluval|g
173         ...                         ${CURDIR}${/}custom_repos.yaml
174         ${result}=              Run Process  sonobuoy  gen  @{flags}
175         Should Be Equal As Integers  ${result.rc}  0
176         ${manifest}=            Replace String  ${result.stdout}
177         ...                         image: gcr.io/heptio-images/sonobuoy-plugin-systemd-logs:latest
178         ...                         image: ${SONOBUOY_IMGS.systemd_logs.path}/${SONOBUOY_IMGS.systemd_logs.name}
179         Create File             ${CURDIR}${/}sonobuoy.yaml  ${manifest}