aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMilosz Wasilewski <milosz.wasilewski@linaro.org>2015-02-13 03:17:15 +0000
committerMilosz Wasilewski <milosz.wasilewski@linaro.org>2015-02-19 12:33:58 +0000
commit2c58c1e4396555054be7f4859f3e0848d5dec9a3 (patch)
tree2356b3f23b1227fea107cf3a9a56bf2fea55a9c2
parent3b3432653c19b99d81b4c4651907b7ee36a192ca (diff)
hacking-session: close session in case of inactivity
If user doesn't log in to hacking session within 60 minutes, the session is terminated. Also default behavior is changed and the session is terminated upon logging out. When user would like to continue hacking session the 'continue_hacking' command is provided. Android multinode hacking session was fixed and it closes both nodes properly. Signed-off-by: Milosz Wasilewski <milosz.wasilewski@linaro.org> Change-Id: I2936067fcdc17616a2dd85bf8dd58c1d76b6f26c
-rwxr-xr-xcontinue_hacking2
-rw-r--r--hacking-session-android-host.yaml36
-rw-r--r--hacking-session-android-target.yaml26
-rwxr-xr-xinvoke_session_debian50
-rwxr-xr-xinvoke_session_oe44
-rwxr-xr-xsetup_session_debian24
-rwxr-xr-xsetup_session_oe35
7 files changed, 209 insertions, 8 deletions
diff --git a/continue_hacking b/continue_hacking
new file mode 100755
index 0000000..c9488dd
--- /dev/null
+++ b/continue_hacking
@@ -0,0 +1,2 @@
+#!/bin/bash
+rm ~/.bash_logout
diff --git a/hacking-session-android-host.yaml b/hacking-session-android-host.yaml
new file mode 100644
index 0000000..1bfcbca
--- /dev/null
+++ b/hacking-session-android-host.yaml
@@ -0,0 +1,36 @@
+metadata:
+ name: hacking-session-android-host
+ format: "Lava-Test-Shell Test Definition 1.0"
+ description: "Android hacking session over adb - host side"
+ maintainer:
+ - milosz.wasilewski@linaro.org
+ os:
+ - android
+ scope:
+ - functional
+ devices:
+ - kvm
+
+install:
+ deps:
+ - openssh-server
+ - wget
+ - android-tools-adb
+
+params:
+ PUB_KEY: None
+ GATEWAY: 10.0.0.1
+ IRC_SERVER: irc.freenode.net
+
+run:
+ steps:
+ - lava-wait hacking-send-ip
+ - IPADDR=`awk -F '=' '{print $2}' /tmp/lava_multi_node_cache.txt`
+ - adb connect $IPADDR
+ - adb wait-for-device
+ - ./setup_session_debian "$PUB_KEY"
+ - export IRC_SERVER
+ - export IRC_USER
+ - export NOTIFY_URL
+ - ./invoke_session_debian "$GATEWAY"
+ - lava-sync hacking-finished
diff --git a/hacking-session-android-target.yaml b/hacking-session-android-target.yaml
new file mode 100644
index 0000000..966adc6
--- /dev/null
+++ b/hacking-session-android-target.yaml
@@ -0,0 +1,26 @@
+metadata:
+ name: lava-android-test-target
+ format: "Lava-Test-Shell Test Definition 1.0"
+ description: "Android multinode hacking session - target side"
+ maintainer:
+ - milosz.wasilewski@linaro.org
+ os:
+ - android
+ scope:
+ - functional
+ devices:
+ - arndale
+ - panda
+ - panda-es
+ - vexpress-a9
+ - vexpress-tc2
+
+run:
+ steps:
+ - lava-test-case step1-cat-build-info --shell cat /system/build.prop
+ - lava-test-case step2-get-adb --shell getprop service.adb.tcp.port
+ - lava-test-case step3-set-adb --shell setprop service.adb.tcp.port 5555
+ - lava-test-case step4-stop-adbd --shell stop adbd
+ - lava-test-case step5-start-adbd --shell start adbd
+ - lava-test-case step6-send-ip --shell lava-send hacking-send-ip ipaddr=$(getprop dhcp.eth0.ipaddress)
+ - lava-test-case step7-multinode-sync --shell lava-sync hacking-finished
diff --git a/invoke_session_debian b/invoke_session_debian
index 4c78166..0db5805 100755
--- a/invoke_session_debian
+++ b/invoke_session_debian
@@ -3,7 +3,7 @@
# If gateway isn't set we will guess it based on the default route
if [ -z "$1" ]; then
- gateway=`ip route get 8.8.8.8 | cut -d ' ' -f3`
+ gateway=`ip route get 8.8.8.8 | grep via | cut -d ' ' -f3`
else
gateway=$1
fi
@@ -35,10 +35,19 @@ echo "* REAL_USER=${REAL_USER}, USER=${USER}, SUDO_USER=${SUDO_USER}"
echo "Please connect to: ${SSH_COMMAND} for access to (${hostname})"
echo "*******************************************************************************************************"
echo ""
+
+cat <<EOF > ~/.bash_logout
+lava-test-case hacking-stopped-logout --result pass
+stop_hacking
+EOF
+
+IRC_AVAILABLE=false
if [ ! -z "${IRC_USER}" ]; then
if apt-get install -qq python-irc; then
+ IRC_AVAILABLE=true
+ TMP_IRC_USER=hs-${RANDOM}
# make a unique user
- cat <<EOF | python /usr/share/doc/python-irc/examples/irccat2.py ${IRC_SERVER} hs-${RANDOM} ${IRC_USER}
+ cat <<EOF | python /usr/share/doc/python-irc/examples/irccat2.py ${IRC_SERVER} ${TMP_IRC_USER} ${IRC_USER}
Your hacking session is now ready
Please connect to:
${SSH_COMMAND}
@@ -54,10 +63,45 @@ echo ""
mkdir -p /run
mkdir -p /run/hacking
echo $$ > /run/hacking/hacking.pid
+TIMESTAMP=`stat -c %Y /run/hacking/hacking.pid`
+STARTED=false
+TERMINATED=false
echo "Hacking session active..."
+lava-test-case hacking-session-active --result pass
+tail -f /var/log/syslog &
+echo $! > /run/hacking/tail.pid
while [ -f /run/hacking/hacking.pid ]
do
+ date
+ echo "===================="
+ who
+ echo "===================="
+ echo ""
sleep 10
+ LOGGEDIN=`who | grep pts | wc -l`
+ if ! $STARTED && [ $LOGGEDIN -gt 0 ]; then
+ STARTED=true
+ elif ! $STARTED && [ $LOGGEDIN -eq 0 ]; then
+ NOW=`date +%s`
+ ELAPSED=`expr $NOW - $TIMESTAMP`
+ if [ $ELAPSED -gt 3600 ]; then
+ echo "No user logged in. Terminating session..."
+ TERMINATED=true
+ if ${IRC_AVAILABLE}; then
+ # make a unique user
+ cat <<EOF | python /usr/share/doc/python-irc/examples/irccat2.py ${IRC_SERVER} ${TMP_IRC_USER} ${IRC_USER}
+Your hacking session was terminated due to inactivity
+There was no user logged in for ${ELAPSED} seconds.
+EOF
+ fi
+ lava-test-case hacking-session-terminated --result fail --measurement ${ELAPSED} --units seconds
+ stop_hacking
+ fi
+ fi
done
echo "Hacking session ended..."
-echo "<LAVA_TEST_RUNNER>: exiting"
+kill `cat /run/hacking/tail.pid`
+rm /run/hacking/tail.pid
+if ! ${TERMINATED}; then
+ lava-test-case hacking-session-terminated --result pass
+fi
diff --git a/invoke_session_oe b/invoke_session_oe
index 59b7847..8b6fe0c 100755
--- a/invoke_session_oe
+++ b/invoke_session_oe
@@ -1,8 +1,13 @@
#!/bin/sh
# Usage ./invoke_session <gateway>
-# Hack for now until lava-test-shell is smart enough to know it's dispatcher ip
-gateway=$1
+# If gateway isn't set we will guess it based on the default route
+if [ -z "$1" ]; then
+ gateway=`ip route get 8.8.8.8 | grep via | cut -d ' ' -f3`
+else
+ gateway=$1
+fi
+
echo "Target's Gateway: $gateway"
# Copy invoke session
@@ -31,13 +36,46 @@ echo ")"
echo "*********************************************************************************************"
echo ""
echo ""
+
+cat <<EOF > ~/.bash_logout
+stop_hacking
+EOF
+
mkdir -p /run
mkdir -p /run/hacking
echo $$ > /run/hacking/hacking.pid
+TIMESTAMP=`stat -c %Y /run/hacking/hacking.pid`
+STARTED=false
+TERMINATED=false
echo "Hacking session active..."
+lava-test-case hacking-session-active --result pass
+tail -f /var/log/syslog &
+echo $! > /run/hacking/tail.pid
while [ -f /run/hacking/hacking.pid ]
do
+ date
+ echo "===================="
+ who
+ echo "===================="
+ echo ""
sleep 10
+ LOGGEDIN=`who | grep pts | wc -l`
+ if ! $STARTED && [ $LOGGEDIN -gt 0 ]; then
+ STARTED=true
+ elif ! $STARTED && [ $LOGGEDIN -eq 0 ]; then
+ NOW=`date +%s`
+ ELAPSED=`expr $NOW - $TIMESTAMP`
+ if [ $ELAPSED -gt 3600 ]; then
+ TERMINATED=true
+ echo "No user logged in. Terminating session..."
+ lava-test-case hacking-session-terminated --result fail --measurement ${ELAPSED} --units seconds
+ stop_hacking
+ fi
+ fi
done
+kill `cat /run/hacking/tail.pid`
+rm /run/hacking/tail.pid
echo "Hacking session ended..."
-echo "<LAVA_TEST_RUNNER>: exiting"
+if ! ${TERMINATED}; then
+ lava-test-case hacking-session-terminated --result pass
+fi
diff --git a/setup_session_debian b/setup_session_debian
index 2404015..f96553c 100755
--- a/setup_session_debian
+++ b/setup_session_debian
@@ -3,13 +3,24 @@
chmod a+x stop_hacking_debian
cp stop_hacking_debian /bin/stop_hacking
+chmod a+x continue_hacking
+cp continue_hacking /bin/continue_hacking
chmod a+x invoke_session_debian
cp invoke_session_debian /bin/invoke_session
+if [ $# -ne 1 ]; then
+ lava-test-case public-key-installed --result fail
+ exit 1
+fi
+
mkdir -p ~/.ssh/
echo $1 >> ~/.ssh/authorized_keys
+if [ $? -ne 0 ]; then
+ lava-test-case public-key-installed --result fail
+fi
chmod 0600 ~/.ssh/authorized_keys
echo "Public Key Installed: $1"
+lava-test-case public-key-installed --result pass
# Account for running under sudo
if [ ! -z "${SUDO_USER}" ]; then
@@ -17,6 +28,19 @@ if [ ! -z "${SUDO_USER}" ]; then
chown -R ${SUDO_USER}:${SUDO_GID} ${HOME}/.ssh
fi
+grep -P "^LogLevel" /etc/ssh/sshd_config
+if [ $? -eq 0 ]; then
+ sed -i "s/^LogLevel\ [A-Z]\+/LogLevel\ DEBUG/g" /etc/ssh/sshd_config
+else
+ echo "LogLevel DEBUG" >> /etc/ssh/sshd_config
+fi
/etc/init.d/ssh restart
echo "sshd re-started"
+if [ $? -eq 0 ]; then
+ lava-test-case sshd-restart --result pass
+ echo "sshd re-started"
+else
+ lava-test-case sshd-restart --result fail
+ echo "sshd re-start failed"
+fi
diff --git a/setup_session_oe b/setup_session_oe
index a5d9bcc..2620427 100755
--- a/setup_session_oe
+++ b/setup_session_oe
@@ -3,12 +3,43 @@
chmod a+x stop_hacking_oe
cp stop_hacking_oe /bin/stop_hacking
+chmod a+x continue_hacking
+cp continue_hacking /bin/continue_hacking
chmod a+x invoke_session_oe
cp invoke_session_oe /bin/invoke_session
+if [ $# -ne 1 ]; then
+ lava-test-case public-key-installed --result fail
+ exit 1
+fi
+
mkdir -p ~/.ssh/
echo $1 >> ~/.ssh/authorized_keys
+if [ $? -ne 0 ]; then
+ lava-test-case public-key-installed --result fail
+fi
+chmod 0600 ~/.ssh/authorized_keys
echo "Public Key Installed: $1"
+lava-test-case public-key-installed --result pass
+
+# Account for running under sudo
+if [ ! -z "${SUDO_USER}" ]; then
+ echo "Fixing up ${HOME}/.ssh permissions to ${SUDO_USER}:${SUDO_GID}"
+ chown -R ${SUDO_USER}:${SUDO_GID} ${HOME}/.ssh
+fi
-/etc/init.d/sshd restart
-echo "sshd re-started"
+# Change SSHD log level to DEBUG
+grep -P "^LogLevel" /etc/ssh/sshd_config
+if [ $? -eq 0 ]; then
+ sed -i "s/^LogLevel\ [A-Z]\+/LogLevel\ DEBUG/g" /etc/ssh/sshd_config
+else
+ echo "LogLevel DEBUG" >> /etc/ssh/sshd_config
+fi
+/etc/init.d/ssh restart
+if [ $? -eq 0 ]; then
+ lava-test-case sshd-restart --result pass
+ echo "sshd re-started"
+else
+ lava-test-case sshd-restart --result fail
+ echo "sshd re-start failed"
+fi