2c9d3eec8759b29003568413b8b1a0fab95cb76a
[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.15.1
40 &{E2E}              path=akraino
41 ...                 name=validation:kube-conformance-v1.15
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
55 *** Test Cases ***
56 Run Sonobuoy Conformance Test
57         # Start the test
58         Run                     kubectl apply -f ${CURDIR}${/}sonobuoy.yaml
59         Sleep                   20s
60         ${rc}  ${output}=       Run And Return Rc And Output
61                                 ...  kubectl describe pod/sonobuoy -n heptio-sonobuoy
62         Append To File          ${LOG}  ${output}${\n}
63
64         # Wait until the test finishes execution
65         Run                     while sonobuoy status | grep "Sonobuoy is still running"; do sleep 180; done
66         Append To File          ${LOG}  "Sonobuoy has completed"${\n}
67
68         # Get the result and store the sonobuoy logs
69         ${rc}  ${output}=       Run And Return Rc And Output
70                                 ...  results=$(sonobuoy retrieve ${LOG_PATH}) && sonobuoy e2e $results
71         Append To File          ${LOG}  ${output}${\n}
72         Should Contain          ${output}       failed tests: 0
73
74 *** Keywords ***
75 Check that k8s cluster is reachable
76         # Check that the config file is mounted in the container
77         File Should Not Be Empty  /root/.kube/config
78
79         # Make sure the pod is reachable with the local k8s client
80         ${rc}  ${output}=       Run And Return Rc And Output
81                                 ...  kubectl get pods --all-namespaces
82         Append To File          ${LOG}  ${output}${\n}
83         Should Contain          ${output}      kube-system
84
85 Cleanup Sonobuoy
86         ${rc}  ${output}=       Run And Return Rc And Output
87                                 ...  kubectl delete -f ${CURDIR}${/}sonobuoy.yaml
88         Append To File          ${LOG}  ${output}${\n}
89         Sleep                   3s
90         Should Contain          ${output}      service "sonobuoy-master" deleted
91
92 Open Connection And Log In
93         Open Connection         ${HOST}
94         Login With Public Key   ${USERNAME}  ${SSH_KEYFILE}
95
96 Upload To Internal Registry
97          [Arguments]            ${path}  ${name}
98          ${rc}=  Execute Command
99          ...     docker pull ${path}/${name}
100          ...       return_stdout=False  return_rc=True
101          Should Be Equal As Integers  ${rc}  0
102          ${rc}=  Execute Command
103          ...     docker tag ${path}/${name} ${INT_REG}/bluval/${name}
104          ...       return_stdout=False  return_rc=True
105          Should Be Equal As Integers  ${rc}  0
106          ${rc}=  Execute Command
107          ...     docker push ${INT_REG}/bluval/${name}
108          ...       return_stdout=False  return_rc=True
109          Should Be Equal As Integers  ${rc}  0
110
111 Onboard Sonobuoy Images
112         FOR  ${img}  IN  @{SONOBUOY_IMGS}
113             ${path}=            Get From Dictionary  ${SONOBUOY_IMGS['${img}']}  path
114             ${name}=            Get From Dictionary  ${SONOBUOY_IMGS['${img}']}  name
115             Upload To Internal Registry  ${path}  ${name}
116             Set To Dictionary  ${SONOBUOY_IMGS['${img}']}  path=${INT_REG}/bluval
117         END
118
119 Onboard Kubernetes e2e Test Images
120         ${result}=              Run Process  sonobuoy  images
121         Should Be Equal As Integers  ${result.rc}  0
122         @{images}=              Split String  ${result.stdout}
123         FOR  ${img}  IN  @{images}
124             ${path}  ${name}  Split String From Right  ${img}  /  1
125             Upload To Internal Registry  ${path}  ${name}
126         END
127
128 Onboard Images
129         ${INT_REG}=             Get Variable Value  ${INTERNAL_REGISTRY}  ${EMPTY}
130         Set Test Variable       ${INT_REG}
131         Return From Keyword If  $INT_REG == '${EMPTY}'
132         Open Connection And Log In
133         Onboard Sonobuoy Images
134         Onboard Kubernetes e2e Test Images
135
136 Get Tests To Skip
137         ${flag}=                Set Variable  Aggregator|Alpha|\\[(Disruptive|Feature:[^\\]]+|Flaky)\\]
138         ${flag}=                Run Keyword If  '${DNS_DOMAIN}' != 'cluster.local'
139         ...                         Catenate  SEPARATOR=|  ${flag}  ${DNS_DOMAIN_TESTS}
140         ...                     ELSE
141         ...                         Set Variable  ${flag}
142         [Return]                ${flag}
143
144 Create Manifest File
145         ${skip}=                Get Tests To Skip
146         @{flags}=               Set Variable
147         ...                         --e2e-focus  \\[Conformance\\\]
148         ...                         --e2e-skip  ${skip}
149         ...                         --kube-conformance-image  ${SONOBUOY_IMGS.e2e.path}/${SONOBUOY_IMGS.e2e.name}
150         ...                         --sonobuoy-image  ${SONOBUOY_IMGS.sonobuoy.path}/${SONOBUOY_IMGS.sonobuoy.name}
151         ...                         --image-pull-policy  Always
152         ...                         --timeout  14400
153         Run Keyword If          $INT_REG != '${EMPTY}'  Run Keywords
154         ...                     Append To List  ${flags}
155         ...                         --e2e-repo-config  ${CURDIR}${/}custom_repos.yaml
156         ...                     AND
157         ...                     Run Process  sed  -i  s|{{ registry }}|${INT_REG}/bluval|g
158         ...                         ${CURDIR}${/}custom_repos.yaml
159         ${result}=              Run Process  sonobuoy  gen  @{flags}
160         Should Be Equal As Integers  ${result.rc}  0
161         ${manifest}=            Replace String  ${result.stdout}
162         ...                         image: gcr.io/heptio-images/sonobuoy-plugin-systemd-logs:latest
163         ...                         image: ${SONOBUOY_IMGS.systemd_logs.path}/${SONOBUOY_IMGS.systemd_logs.name}
164         Create File             ${CURDIR}${/}sonobuoy.yaml  ${manifest}