Skip to content

Commit 1be960c

Browse files
committed
added tests
Signed-off-by: Evgeny Slutsky <[email protected]>
1 parent 3617b91 commit 1be960c

File tree

4 files changed

+164
-23
lines changed

4 files changed

+164
-23
lines changed

test/resources/hosts.resource

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
*** Settings ***
2+
Documentation Keywords for interacting with the hosts file
3+
4+
Library Process
5+
Library String
6+
7+
Resource common.resource
8+
9+
*** Keywords ***
10+
Generate Random HostName
11+
[Documentation] Generate Random Hostname
12+
${rand}= Generate Random String
13+
${rand}= Convert To Lower Case ${rand}
14+
RETURN ${rand}.api.com
15+
16+
Add Entry To Hosts
17+
[Documentation] Add new entry to local /etc/hosts
18+
[Arguments] ${ip} ${host} ${hostsfile}=/etc/hosts
19+
VAR ${ttt}= ${ip}\t${host} # RF test marker\n
20+
${stdout} ${stderr} ${rc}= SSHLibrary.Execute Command
21+
... echo "${ttt}" | sudo tee -a ${hostsfile}
22+
... sudo=True return_rc=True return_stderr=True return_stdout=True
23+
Should Be Equal As Integers ${rc} 0
24+
Remove Entry From Hosts
25+
[Documentation] Removes entry from local /etc/hosts
26+
[Arguments] ${host} ${hostsfile}=/etc/hosts
27+
${stdout} ${stderr} ${rc}= SSHLibrary.Execute Command
28+
... sed -i "/${host} # RF test marker/d" ${hostsfile}
29+
... sudo=True return_rc=True return_stderr=True return_stdout=True
30+
Should Be Equal As Integers ${rc} 0

test/resources/oc.resource

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ Oc Delete
5656
Oc Exec
5757
[Documentation] Run 'oc exec' on a specific pod in the curret test namespace
5858
... Returns the command's combined STDOUT/STDER
59-
[Arguments] ${pod} ${cmd} ${ns}=${NAMESPACE}
60-
${output}= Run With Kubeconfig oc exec -n ${ns} pod/${pod} -- /bin/bash -c '${cmd}'
59+
[Arguments] ${pod} ${cmd} ${ns}=${NAMESPACE} ${shell}=/bin/bash
60+
${output}= Run With Kubeconfig oc exec -n ${ns} pod/${pod} -- ${shell} -c '${cmd}'
6161
RETURN ${output}
6262

6363
Oc Wait

test/suites/standard1/dns.robot

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
*** Settings ***
2+
Documentation Networking smoke tests
3+
4+
Resource ../../resources/common.resource
5+
Resource ../../resources/oc.resource
6+
Resource ../../resources/microshift-network.resource
7+
Resource ../../resources/microshift-config.resource
8+
Resource ../../resources/microshift-process.resource
9+
Resource ../../resources/hosts.resource
10+
11+
Suite Setup Setup Suite With Namespace
12+
Suite Teardown Teardown Suite With Namespace
13+
14+
Test Tags slow
15+
16+
17+
*** Variables ***
18+
${HELLO_USHIFT_INGRESS} ./assets/hello/hello-microshift-ingress.yaml
19+
${HOSTNAME} hello-microshift.cluster.local
20+
${HOSTSCUSTOM} hello-microshift.api.com
21+
${FAKE_LISTEN_IP} 99.99.99.99
22+
${CUSTOM_HOSTS_FILE} /tmp/hosts23
23+
${PODS_HOSTS_FILE} /tmp/hosts/hosts
24+
${HOSTSFILE_ENABLED} SEPARATOR=\n
25+
... ---
26+
... dns:
27+
... \ \ hosts:
28+
... \ \ \ status: Enabled
29+
${HOSTS_CONFIG_CUSTOM} SEPARATOR=\n
30+
... ---
31+
... dns:
32+
... \ \ hosts:
33+
... \ \ \ status: Enabled
34+
... \ \ \ file: ${CUSTOM_HOSTS_FILE}
35+
36+
37+
*** Test Cases ***
38+
Resolve Host from Default Hosts File
39+
[Documentation] Resolve host from default hosts file
40+
[Setup] Setup With Custom Config ${HOSTSFILE_ENABLED} /etc/hosts
41+
Resolve Host From Pod ${hostname}
42+
[Teardown] Teardown Hosts File ${hostname}
43+
44+
Resolve Host from Non-Default Hosts File
45+
[Documentation] Resolve host from default hosts file
46+
[Setup] Setup With Custom Config ${HOSTS_CONFIG_CUSTOM} ${CUSTOM_HOSTS_FILE}
47+
Resolve Host From Pod ${hostname}
48+
[Teardown] Teardown Hosts File ${hostname}
49+
50+
51+
*** Keywords ***
52+
Wait For DNS Updated With Hostname
53+
[Documentation] Wait for the file to be updated
54+
[Arguments] ${hostname}
55+
Wait Until Keyword Succeeds 2m 2s
56+
... DNS Pod Contain Hosts ${hostname}
57+
58+
DNS Pod Contain Hosts
59+
[Documentation] Check if the hosts file contains the given hostname
60+
[Arguments] ${hostname}
61+
62+
# Find the dns-default-.* pod name in openshift-dns namespace, e.g., dns-default-dqp9n
63+
${dns_pod}= Run With Kubeconfig
64+
... oc get pod -n openshift-dns -o jsonpath='{.items[*].metadata.name}' | grep '^dns-default-'
65+
${fuse_device}= Oc Exec ${dns_pod} cat ${PODS_HOSTS_FILE} openshift-dns
66+
Should Contain ${fuse_device} ${hostname}
67+
68+
Resolve Host From Pod
69+
[Documentation] Resolve host from pod
70+
[Arguments] ${hostname}
71+
Create Hello MicroShift Pod
72+
Expose Hello MicroShift
73+
Wait For DNS Updated With Hostname ${hostname}
74+
Sleep 5 seconds
75+
${fuse_device}= Oc Exec hello-microshift nslookup ${hostname} ${NAMESPACE} /bin/sh
76+
Should Contain ${fuse_device} Name: ${hostname}
77+
78+
Setup With Custom Config
79+
[Documentation] Install a custom config and restart MicroShift
80+
[Arguments] ${config_content} ${hostsFile}
81+
${hostname}= Generate Random HostName
82+
Set Global Variable ${hostname}
83+
Add Fake IP To NIC ${FAKE_LISTEN_IP}
84+
Add Entry To Hosts ${FAKE_LISTEN_IP} ${hostname} ${hostsFile}
85+
Drop In MicroShift Config ${config_content} 20-dns
86+
Restart MicroShift
87+
88+
Teardown Hosts File
89+
[Documentation] Teardown the hosts file
90+
[Arguments] ${hostname}
91+
Run Keywords
92+
... Delete Hello MicroShift Pod And Service
93+
... AND
94+
... Remove Entry From Hosts ${hostname}
95+
... AND
96+
... Remove Fake IP From NIC ${FAKE_LISTEN_IP}
97+
... AND
98+
... Remove Drop In MicroShift Config 20-dns
99+
100+
Add Fake IP To NIC
101+
[Documentation] Add the given IP to the given NIC temporarily.
102+
[Arguments] ${ip_address}=${FAKE_LISTEN_IP} ${nic_name}=br-ex
103+
${stdout} ${stderr} ${rc}= SSHLibrary.Execute Command
104+
... ip address add ${ip_address}/32 dev ${nic_name}
105+
... sudo=True return_rc=True return_stderr=True return_stdout=True
106+
Log Many ${stdout} ${stderr}
107+
Should Be Equal As Integers 0 ${rc}
108+
109+
Remove Fake IP From NIC
110+
[Documentation] Remove the given IP from the given NIC.
111+
[Arguments] ${ip_address}=${FAKE_LISTEN_IP} ${nic_name}=br-ex
112+
${stdout} ${stderr} ${rc}= SSHLibrary.Execute Command
113+
... ip address delete ${ip_address}/32 dev ${nic_name}
114+
... sudo=True return_rc=True return_stderr=True return_stdout=True
115+
Log Many ${stdout} ${stderr}
116+
Should Be Equal As Integers 0 ${rc}

test/suites/standard2/validate-custom-certificates.robot

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Documentation Tests custom certificates functionality
44
Resource ../../resources/microshift-config.resource
55
Resource ../../resources/microshift-process.resource
66
Resource ../../resources/openssl.resource
7+
Resource ../../resources/hosts.resource
78
Library ../../resources/journalctl.py
89

910
Suite Setup Setup
@@ -42,10 +43,10 @@ Test Expired Cert
4243
Upload Certificates
4344
Configure Named Certificates ${TMPDIR}/server.crt ${TMPDIR}/server.key
4445
Restart MicroShift
45-
Add Entry To Hosts ${USHIFT_HOST} ${hostname}
46+
Add Entry To Local Hosts ${USHIFT_HOST} ${hostname}
4647
Setup Custom Kubeconfig ${hostname}
4748
OC Should Fail To Connect With Expired Cert
48-
[Teardown] Remove Entry From Hosts ${hostname}
49+
[Teardown] Remove Entry From Local Hosts ${hostname}
4950

5051
Test Local Cert
5152
[Documentation] localhost certs should be ignored with a warning
@@ -176,25 +177,6 @@ Configure Named Certificates
176177
END
177178
Drop In MicroShift Config ${subject_alt_names} 10-subjectAltNames
178179

179-
Generate Random HostName
180-
[Documentation] Generate Random Hostname
181-
${rand}= Generate Random String
182-
${rand}= Convert To Lower Case ${rand}
183-
RETURN ${rand}.api.com
184-
185-
Add Entry To Hosts
186-
[Documentation] Add new entry to local /etc/hosts
187-
[Arguments] ${ip} ${host}
188-
VAR ${ttt}= ${ip}\t${host} # RF test marker\n
189-
${result}= Run Process sudo tee -a /etc/hosts shell=True stdin=${ttt}
190-
Should Be Equal As Integers ${result.rc} 0
191-
192-
Remove Entry From Hosts
193-
[Documentation] Removes entry from local /etc/hosts
194-
[Arguments] ${host}
195-
${result}= Run Process sudo sed -i "/${host} # RF test marker/d" /etc/hosts shell=True
196-
Should Be Equal As Integers ${result.rc} 0
197-
198180
Replace Server In Kubeconfig
199181
[Documentation] replace the server part of kubeconfig
200182
[Arguments] ${fqdn}
@@ -215,3 +197,16 @@ MicroShift Is Live With Custom CA
215197
[Documentation] Check the /livez endpoint with Custom CA
216198
[Arguments] ${ca_path}
217199
MicroShift Is Live --certificate-authority ${ca_path}
200+
201+
Add Entry To Local Hosts
202+
[Documentation] Add new entry to local /etc/hosts
203+
[Arguments] ${ip} ${host}
204+
VAR ${ttt}= ${ip}\t${host} # RF test marker\n
205+
${result}= Run Process sudo tee -a /etc/hosts shell=True stdin=${ttt}
206+
Should Be Equal As Integers ${result.rc} 0
207+
208+
Remove Entry From Local Hosts
209+
[Documentation] Removes entry from local /etc/hosts
210+
[Arguments] ${host}
211+
${result}= Run Process sudo sed -i "/${host} # RF test marker/d" /etc/hosts shell=True
212+
Should Be Equal As Integers ${result.rc} 0

0 commit comments

Comments
 (0)