-
Notifications
You must be signed in to change notification settings - Fork 1
/
testlib.sh
110 lines (102 loc) · 3.69 KB
/
testlib.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/env bash
source ./keys.sh
test_not_on_login_nodes(){
echo
echo "=========================================================="
echo "Testing this is not running on the login nodes."
echo "This (and sunpyter) should be running on your machine!"
echo "=========================================================="
HOST=$(hostname)
if [[ $HOST = sl1* ]] || [[ $HOST == sl2* ]]
then
echo "Test failed:"
echo "You're running it on the Sunbird login nodes"
return 1
elif [[ $HOST = scs*.sunbird.supercomputingwales.ac.uk ]]
then
echo "Test failed:"
echo "You're running it on a compute node"
elif [ $HOST == "sa2c-backup2" ]
then
echo "Test failed:"
echo "You're running it on the CDT storage login node"
return 1
else
echo "Test successful:"
echo "On $HOST"
fi
}
test_ssh_agent(){
echo
echo "=========================================================="
echo "Testing ssh agent setup"
echo "=========================================================="
echo "Creating ssh agent:"
eval $(ssh-agent)
keyfile="$(get_keyfile)"
echo "Adding '${keyfile}' to agent. You will be asked your key's passphrase:"
ssh-add "${keyfile}"
echo "We'll now try to connect to sunbird.swansea.ac.uk"
echo "If you are requested your SCW password, this test has failed."
ssh $REMOTE "echo Connected, hopefully without password."
}
test_ssh_socket_creation(){
echo
echo "=========================================================="
echo "Testing ssh socket creation"
echo "(this will take ~15 seconds)"
echo "=========================================================="
source ./find_resources.sh
SSH_SOCKET=$(find_free_ssh_socket)
echo "Trying with socket: ${SSH_SOCKET}"
ssh -S ${SSH_SOCKET} -M $REMOTE "sleep 15; echo Remote process done." &> test_log.txt &
sleep 5
if [ -S ${SSH_SOCKET} ]
then
echo "SSH socket created, wait ~10 seconds..."
wait
cat test_log.txt
echo "Test was successful"
else
echo "SSH Socket creation failed: exiting"
wait
cat test_log.txt
return 1
fi
}
test_ssHtan(){
echo
echo "=========================================================="
echo "Testing whether ss is present on your system"
echo "and accepts the right options"
echo "=========================================================="
ss -Htan > /dev/null && echo "Test was successful, ss command works" || (
echo "ss -Htan does not work on your system"
echo "you may still be ok if lsof or netstat work."
return 1
)
}
test_lsofi(){
echo
echo "=========================================================="
echo "Testing whether lsof is present on your system"
echo "and accepts the right options"
echo "=========================================================="
lsof -i :8888 > /dev/null && echo "Test was successful, lsof command works" || (
echo "lsof -i :<port number> does not work on your system"
echo "you may still be ok if ss or netstat work."
return 1
)
}
test_netstatan(){
echo
echo "=========================================================="
echo "Testing whether netstat is present on your system"
echo "and accepts the right options"
echo "=========================================================="
netstat -an > /dev/null && echo "Test was successful, netstat command works" || (
echo "netstat -an does not work on your system"
echo "you may still be ok if ss or lsof work."
return 1
)
}