Skip to content

Commit b6e1d11

Browse files
NO-ISSUE: Code restructure (#1744)
- Moved utility functions ( to be reused for iso-builder) into agent/e2e/agent-tui/utils.sh - No need to pass CLUSTER_NAME to test-fix-wrong-dns.sh as its a global var
1 parent 09c7854 commit b6e1d11

File tree

3 files changed

+83
-81
lines changed

3 files changed

+83
-81
lines changed

agent/06_agent_create_cluster.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ function run_agent_test_cases() {
298298
echo "Fixing DNS through agent-tui"
299299
# call script to fix DNS IP address on master-0
300300
local version="$(openshift_version ${OCP_DIR})"
301-
./agent/e2e/agent-tui/test-fix-wrong-dns.sh $CLUSTER_NAME $PROVISIONING_HOST_EXTERNAL_IP $version
301+
./agent/e2e/agent-tui/test-fix-wrong-dns.sh $PROVISIONING_HOST_EXTERNAL_IP $version
302302

303303
# Take screenshot of the console after fixing DNS to see if the agent_tui
304304
# has exited.

agent/e2e/agent-tui/test-fix-wrong-dns.sh

+6-80
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,13 @@
11
#!/bin/bash
22

3-
source common.sh
4-
set +x
5-
6-
CLUSTER_NAME=$1
7-
GOOD_DNS_IP=$2
8-
OCP_VERSION=$3
9-
10-
### utils function for sending various keys and/or text to the console
11-
12-
function _pressKey() {
13-
local keyCode=$@
14-
15-
name=${CLUSTER_NAME}_master_0
16-
sudo virsh send-key $name $keyCode
17-
18-
# On some CI instances, the sequence of events appears to be too fast
19-
# for the console refresh, leading the test in the wrong state.
20-
# Let's add a small pause between one keypress event and the subsequent
21-
sleep 1
22-
}
23-
24-
function pressKey() {
25-
local msg=$1
26-
local keyCode=$2
27-
local numReps=1
28-
29-
if [ ! -z "$3" ]; then
30-
numReps=$3
31-
echo "$msg ($numReps)"
32-
else
33-
echo $msg
34-
fi
35-
36-
for i in $(seq 1 $numReps); do
37-
_pressKey $keyCode
38-
done
39-
}
40-
41-
function pressEnter() {
42-
pressKey "$1" KEY_ENTER "$2"
43-
}
3+
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../../.." && pwd )"
444

45-
function pressTab() {
46-
pressKey "$1" KEY_TAB "$2"
47-
}
48-
49-
function pressDown() {
50-
pressKey "$1" KEY_DOWN "$2"
51-
}
52-
53-
function pressBackspace() {
54-
pressKey "$1" KEY_BACKSPACE "$2"
55-
}
56-
57-
58-
function pressEsc() {
59-
pressKey "$1" KEY_ESC "$2"
60-
}
61-
62-
function pressKeys(){
63-
local msg=$1
64-
local text=$2
65-
66-
echo $msg
67-
68-
local reNumber='[0-9]'
69-
local reUpperText='[A-Z]'
70-
for (( i=0; i<${#text}; i++ )); do
71-
local c=${text:$i:1}
72-
73-
if [[ $c =~ ['a-z'] ]]; then
74-
c=$(echo $c | tr '[:lower:]' '[:upper:]')
75-
elif [[ $c =~ ['\.'] ]]; then
76-
c="DOT"
77-
elif [[ $c =~ [':'] ]]; then
78-
c="LEFTSHIFT KEY_SEMICOLON"
79-
fi
5+
source $SCRIPTDIR/common.sh
6+
source $SCRIPTDIR/agent/e2e/agent-tui/utils.sh
7+
set +x
808

81-
local keyCode="KEY_"$c
82-
_pressKey $keyCode
83-
done
84-
}
9+
GOOD_DNS_IP=$1
10+
OCP_VERSION=$2
8511

8612
### Prereq: create an agent ISO using an incorrect DNS address in the agent-config.yaml
8713
### This can be done by setting AGENT_E2E_TEST_TUI_BAD_DNS to true in config_<user>.sh

agent/e2e/agent-tui/utils.sh

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
2+
### utils function for sending various keys and/or text to the console
3+
4+
function _pressKey() {
5+
local keyCode=$@
6+
7+
name=${CLUSTER_NAME}_master_0
8+
sudo virsh send-key $name $keyCode
9+
10+
# On some CI instances, the sequence of events appears to be too fast
11+
# for the console refresh, leading the test in the wrong state.
12+
# Let's add a small pause between one keypress event and the subsequent
13+
sleep 1
14+
}
15+
16+
function pressKey() {
17+
local msg=$1
18+
local keyCode=$2
19+
local numReps=1
20+
21+
if [ ! -z "$3" ]; then
22+
numReps=$3
23+
echo "$msg ($numReps)"
24+
else
25+
echo $msg
26+
fi
27+
28+
for i in $(seq 1 $numReps); do
29+
_pressKey $keyCode
30+
done
31+
}
32+
33+
function pressEnter() {
34+
pressKey "$1" KEY_ENTER "$2"
35+
}
36+
37+
function pressTab() {
38+
pressKey "$1" KEY_TAB "$2"
39+
}
40+
41+
function pressDown() {
42+
pressKey "$1" KEY_DOWN "$2"
43+
}
44+
45+
function pressBackspace() {
46+
pressKey "$1" KEY_BACKSPACE "$2"
47+
}
48+
49+
50+
function pressEsc() {
51+
pressKey "$1" KEY_ESC "$2"
52+
}
53+
54+
function pressKeys(){
55+
local msg=$1
56+
local text=$2
57+
58+
echo $msg
59+
60+
local reNumber='[0-9]'
61+
local reUpperText='[A-Z]'
62+
for (( i=0; i<${#text}; i++ )); do
63+
local c=${text:$i:1}
64+
65+
if [[ $c =~ ['a-z'] ]]; then
66+
c=$(echo $c | tr '[:lower:]' '[:upper:]')
67+
elif [[ $c =~ ['\.'] ]]; then
68+
c="DOT"
69+
elif [[ $c =~ [':'] ]]; then
70+
c="LEFTSHIFT KEY_SEMICOLON"
71+
fi
72+
73+
local keyCode="KEY_"$c
74+
_pressKey $keyCode
75+
done
76+
}

0 commit comments

Comments
 (0)