-
Notifications
You must be signed in to change notification settings - Fork 0
/
researcher.sh
104 lines (86 loc) · 3.18 KB
/
researcher.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
function start_researcher(){
RESEARCH_CONTAINER=$1
RESEARCH_CONTAINER_URL=$2
CONFINE_TESTS_URL=$3
SLEEP=5
# fetch/copy the latest research container
if [[ ! -f dl/$RESEARCH_CONTAINER ]]; then
echo "Downloading $RESEARCH_CONTAINER"
wget -q --no-check-certificate $RESEARCH_CONTAINER_URL -O dl/$RESEARCH_CONTAINER
fi
if [[ ! -f dl/$RESEARCH_CONTAINER ]]; then
echo "Could not download $RESEARCH_CONTAINER"
exit 1
fi
echo "Unpacking..."
tear_down_researcher
rm -rf researcher/researcher_lxc
tar -C researcher --numeric-owner -xJf dl/$RESEARCH_CONTAINER
cd researcher
echo "Patching..."
rm -rf .pc # remove old quilt information, if any
quilt push -a -v
echo "chmod files..."
chmod 600 ../sshkey/id_rsa #avoid private ssh key permission problems
chmod 755 researcher_lxc/rootfs/etc/tinc/confine/tinc-{up,down}
echo "Adding tests..."
git clone http://git.confine-project.eu/confine/confine-utils.git researcher_lxc/rootfs/home/vct/confine-utils
git clone $CONFINE_TESTS_URL researcher_lxc/rootfs/home/vct/confine-tests
if [[ $? != 0 ]]; then
echo "Could not fetch the tests."
fi
echo "Starting LXC..."
lxc-start --name $RESEARCHER_LXC -f researcher_lxc/config -s lxc.rootfs=$(pwd)/researcher_lxc/rootfs -d
echo "Sleeping $SLEEP seconds until booted..."
sleep $SLEEP
echo "Pinging..."
ping6 -c 1 $RESEARCHER_IP && echo "ok"
cd ..
echo "Fixing permissions..."
ssh -i ./sshkey/id_rsa -o StrictHostKeyChecking=no root@$RESEARCHER_IP "chown -R vct /home/vct/"
}
function configure_researcher_inet() {
echo "Providing researcher with inet..."
ssh -i ./sshkey/id_rsa -o StrictHostKeyChecking=no root@$RESEARCHER_IP "ip addr add ${IPV4PREFIX}3/24 dev eth0 && ip route add default via ${IPV4PREFIX}1 && sleep 5 && ping -c 5 8.8.8.8";
}
function run_tests(){
echo "SSHing..."
ssh -i ./sshkey/id_rsa -o StrictHostKeyChecking=no vct@$RESEARCHER_IP 'whoami'
if [[ $? != 0 ]]; then
echo "unable to ssh to researcher."
fi
sleep 20
echo "Starting tests..."
# ssh -i ./sshkey/id_rsa -o StrictHostKeyChecking=no vct@$RESEARCHER_IP \
# "env CONFINE_SERVER_API='http://vctserver/api' CONFINE_USER='vct' CONFINE_PASSWORD='vct' PYTHONPATH=confine-utils:confine-tests python -m unittest discover -s ./confine-tests/ -v"
ssh -i ./sshkey/id_rsa -o StrictHostKeyChecking=no vct@$RESEARCHER_IP \
"env \
TEST_API=$TEST_API \
TEST_VCT=$TEST_VCT \
TEST_INTEGRATION=$TEST_INTEGRATION \
CONFINE_SERVER_API='http://vctserver/api' \
CONFINE_USER='vct' \
CONFINE_PASSWORD='vct' \
PYTHONPATH=confine-utils:confine-tests \
./confine-tests/discover.py discover -s ./confine-tests/ -v"
return $?
}
function archive_researcher() {
lxc-stop -n $RESEARCHER_LXC;
id=$(date +%Y%m%d_%H%M%S);
if [[ $# > 0 ]]; then
id=$1;
fi
cd researcher
tar -c --xz -f ../archive/researcher,$id.tar.xz researcher_lxc
cd ..
}
function tear_down_researcher(){
if lxc-info -n $RESEARCHER_LXC | grep -q RUNNING; then
echo "Stopping researcher..."
lxc-stop -n $RESEARCHER_LXC;
fi
}
RESEARCHER_LXC=${RESEARCHER_LXC:-researcher_$(date -u +"%s")}
IPPREFIX=${IPPREFIX:-"fdf6:1e51:5f7b:b50c::"};
RESEARCHER_IP=${IPPREFIX}3