summaryrefslogtreecommitdiff
path: root/invoke_session_debian
blob: 90d8cbaaa229df60752a6aef3ebe9d845db8622d (plain)
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/bin/bash
# Usage ./invoke_session <gateway>
set -u
set -o pipefail

error=1

trap "rm -rf ~/*; exit \${error}" EXIT

# Hack for now until lava-test-shell is smart enough to know it's dispatcher ip
gateway=$1
abe_branch="$2"

#these parameters used by Benchmark.job
export benchmark="$3"
export toolchain="$4"
if test x"$5" = xNone; then
  export run_flags=
else
  export run_flags="$5"
fi
if test x"$6" = xNone; then
  export compiler_flags=
else
  export compiler_flags="$6"
fi
echo "Target's Gateway: $gateway"

if ! grep 'invoke_session' /etc/rc.local
then
	sed -i '/bin/a invoke_session &' /etc/rc.local
fi

# Obtain target IP and Hostname
ip_addr=$(ifconfig `ip route get $gateway | cut -d ' ' -f3` | grep 'inet addr' |awk -F: '{split($2,a," "); print a[1] }')
hostname=$(cat /etc/hostname)
echo ${ip_addr}

# Set the PATH to use the LAVA api
echo "export PATH=/lava/bin/:$PATH" > ~/.bashrc

#Create directory to store src
if ! (mkdir ~/benchsrc && chmod 700 ~/benchsrc); then
  echo "Failed to create directory for source" >&2
  exit 1
fi

#Initialize git-new-workdir - sadly not just an apt-get call
ln /usr/share/doc/git/contrib/workdir/git-new-workdir /usr/local/bin
chmod 755 /usr/local/bin/git-new-workdir

#Get abe
export ABE_DIR=~/src/abe
mkdir -p "${ABE_DIR}" || exit 1
if ! git clone ${abe_branch:+-b ${abe_branch}} http://git.linaro.org/toolchain/abe "${ABE_DIR}"; then
  rm -rf "${ABE_DIR}"
  exit 1
fi

#Generate one-time key
mkdir ~/data || exit 1
if ! ssh-keygen -P '' -f ~/data/onetime > /dev/null < /dev/null; then
  rm -rf ~/data
  exit 1
fi
eval `ssh-agent`
ssh-add ~/data/onetime

#Need to be able to ssh to self to get local sources
#Can reuse the onetime key for this
cat ~/data/onetime.pub >> ~/.ssh/authorized_keys
if ! ssh -o NoHostAuthenticationForLocalhost=yes localhost true; then
  echo "Failed to ssh to self" >&2
  exit 1
fi

echo ""
mkdir -p /run
mkdir -p /run/hacking
echo $$ > /run/hacking/hacking.pid

#Generate config file for each target in multinode job
lava-network broadcast eth0
lava-network collect eth0

#Request agent just before we need it
#This would be two keys in one agent if we wanted one for source, one for job
echo "*** WAITING FOR AGENT: ${ip_addr}"
echo "ssh -A ${ip_addr}.lab 'ln -sf \$SSH_AUTH_SOCK /root/data/socket && while test -e ~/data/socket; do inotifywait -e delete ~/data; done'"
while ! test -e ~/data/socket; do
  inotifywait -e create ~/data
done
#Best practice would be to use abe to do this, but I hope this is temporary
SSH_AUTH_SOCK=~/data/socket git clone "`grep ${benchmark} ${ABE_DIR}/config/sources.conf | awk '{print $2}'`" ~/benchsrc/${benchmark} || exit 1
#An alternative to the following would be to pass ${benchmark}=ssh://... to abe.sh
sed -i "s#^\\(${benchmark}[[:blank:]]\\+\\).*#\\1 ssh://localhost/~/benchsrc/#" "${ABE_DIR}"/config/sources.conf || exit 1

target_names=()
for lava_name in `lava-group | grep -v '[[:blank:]]*host$' | awk '{print $1}'`; do
  target_ip="$(lava-network query ${lava_name} ipv4)"
  if test $? -ne 0; then echo "Failed to find IP for ${lava_name}"; exit 1; fi
  if test -z "${target_ip}"; then echo "Failed to find IP for ${lava_name}"; exit 1; fi

  #Check that target is accessible, add it to our known_hosts,
  #add our one-time key to it's authorized_keys
  if ! cat ~/data/onetime.pub | SSH_AUTH_SOCK=~/data/socket ssh -o StrictHostKeyChecking=no "${target_ip}" "cat - >> ~/.ssh/authorized_keys"; then
    echo "Could not access target ${target_ip} (${lava_name})" >&2
    exit 1
  fi

  target_base="$(echo ${lava_name} | sed 's/[[:digit:]]*$//')" #TODO: HACK
  if test $? -ne 0; then echo "Failed to find target type from ${lava_name}"; exit 1; fi
  sed "s/^ip=.*/ip=${target_ip}/" "${ABE_DIR}/config/boards/bench/${target_base}.conf" > "${ABE_DIR}/config/boards/bench/${lava_name}.conf"
  if test $? -ne 0; then echo "Failed to generate config file for target ${lava_name}"; exit 1; fi
  cp "${ABE_DIR}/config/boards/bench/${target_base}.services" "${ABE_DIR}/config/boards/bench/${lava_name}.services"
  if test $? -ne 0; then echo "Failed to generate services file for target ${lava_name}"; exit 1; fi
  if test "${#target_names[@]}" -eq 0; then
    target_names=("${lava_name}")
  else
    target_names=("${target_names[@]}" "${lava_name}")
  fi
done

#Don't need the agent any more, kill the socket
rm ~/data/socket

export targets="${target_names[@]}"
export maindir="/${HOME}/bench"
mkdir "${maindir}"
chmod 700 "${maindir}"

echo "Running benchmark... I may be some time"
export LAVA_IN_LAB=1
"${ABE_DIR}"/scripts/Benchmark.job

echo "All done, waiting user"
sleep infinity

echo "Benchmarking session ended..."
echo "<LAVA_TEST_RUNNER>: exiting"
error=0