Skip to content

Commit

Permalink
Merge pull request #32 from giggsoff/master
Browse files Browse the repository at this point in the history
Telnet for eve access
  • Loading branch information
giggsoff authored Feb 20, 2020
2 parents 83316f6 + 20536d2 commit 2da24b1
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 51 deletions.
8 changes: 6 additions & 2 deletions tests/run_local_eve.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ shift
done
tmp_dir=$(mktemp -d -t eveadam-"$(date +%Y-%m-%d-%H-%M-%S)"-XXXXXXXXXX)
ssh_port=`comm -23 <(seq 49252 49352 | sort) <(ss -Htan | awk '{print $4}' | cut -d':' -f2 | sort -u) | shuf | head -n 1`
telnet_port=$(comm -23 <(seq 49452 49552 | sort) <(ss -Htan | awk '{print $4}' | cut -d':' -f2 | sort -u) | shuf | head -n 1)
echo ========================================
echo "Temp directory for test: $tmp_dir"
echo ========================================
eve_dir="$tmp_dir"/eve
apt update
apt upgrade -y
snap install --classic go
apt-get install -y git make docker.io qemu-system-x86 qemu-utils openssl jq
apt-get install -y git make docker.io qemu-system-x86 qemu-utils openssl jq telnet
touch ~/.rnd
cd "$tmp_dir" || exit
git clone $eve_repo
Expand All @@ -49,7 +50,8 @@ cd $eve_dir||exit
sed -i "s/SandyBridge/host/g" Makefile
sed -i "s/31415926/$sn/g" Makefile
sed -i "s/-m 4096/-m $memory_to_use/g" Makefile
make live
sed -i "s/mon:stdio/telnet:localhost:$telnet_port,server,nowait/g" Makefile
make live || { echo "Failed to build EVE" ; exit 1; }
nohup make ACCEL=true SSH_PORT=$ssh_port run >$tmp_dir/eve.log 2>&1 &
echo $! >../eve.pid
echo ========================================
Expand All @@ -65,6 +67,8 @@ echo "$sn"
echo "in zedcloud.zededa.net"
echo "You can connect to node via ssh"
echo "sudo ssh -p $ssh_port 127.0.0.1"
echo "Or via telnet:"
echo "telnet localhost $telnet_port"
while true; do
read -p "Do you want to cleanup? (y/n)" yn
case $yn in
Expand Down
152 changes: 103 additions & 49 deletions tests/run_local_eve_adam.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,28 @@ DIRECTORY=$(cd "$(dirname "$0")" && pwd)
eve_repo=https://github.com/itmo-eve/eve.git
adam_repo=https://github.com/itmo-eve/adam.git
memory_to_use=4096
config_files=( cfg.json cfg_run_rkt.json cfg_run_xen.json cfg_stop_rkt.json cfg_stop_xen.json )
while [ -n "$1" ]
do
case "$1" in
-m) memory_to_use="$2"
echo "Use with memory $memory_to_use"
shift ;;
--) shift
break ;;
*) echo "$1 is not an option";;
esac
shift
config_files=(cfg.json cfg_run_rkt.json cfg_run_xen.json cfg_stop_rkt.json cfg_stop_xen.json)
while [ -n "$1" ]; do
case "$1" in
-m)
memory_to_use="$2"
echo "Use with memory $memory_to_use"
shift
;;
--)
shift
break
;;
*) echo "$1 is not an option" ;;
esac
shift
done
tmp_dir=$(mktemp -d -t eveadam-"$(date +%Y-%m-%d-%H-%M-%S)"-XXXXXXXXXX)
unused_port=$(comm -23 <(seq 49152 49252 | sort) <(ss -Htan | awk '{print $4}' | cut -d':' -f2 | sort -u) | shuf | head -n 1)
ssh_port=$(comm -23 <(seq 49252 49352 | sort) <(ss -Htan | awk '{print $4}' | cut -d':' -f2 | sort -u) | shuf | head -n 1)
for i in "${config_files[@]}"
do
if [ ! -f "$DIRECTORY"/"$i" ]; then
telnet_port=$(comm -23 <(seq 49452 49552 | sort) <(ss -Htan | awk '{print $4}' | cut -d':' -f2 | sort -u) | shuf | head -n 1)
for i in "${config_files[@]}"; do
if [ ! -f "$DIRECTORY"/"$i" ]; then
echo "Cannot find $i"
exit 1
fi
Expand Down Expand Up @@ -55,15 +58,15 @@ eve_dir="$tmp_dir"/eve
apt update
apt upgrade -y
snap install --classic go
apt-get install -y git make docker.io qemu-system-x86 qemu-utils openssl jq
apt-get install -y git make docker.io qemu-system-x86 qemu-utils openssl jq telnet
touch ~/.rnd
cd "$tmp_dir" || exit 1
git clone $eve_repo
git clone $adam_repo
echo ========================================
echo "Generate keypair for ssh (no overwrite if exists)"
echo ========================================
ssh-keygen -t rsa -f /root/.ssh/id_rsa -q -N "" <<< n
ssh-keygen -t rsa -f /root/.ssh/id_rsa -q -N "" <<<n
echo
echo ========================================
echo "Prepare and run ADAM"
Expand All @@ -73,8 +76,7 @@ cd $adam_dir || exit 1
make build-docker
mkdir -p run/adam
mkdir -p run/config
for i in "${config_files[@]}"
do
for i in "${config_files[@]}"; do
cp "$DIRECTORY"/"$i" run/
done
cd run/adam || exit 1
Expand Down Expand Up @@ -117,34 +119,60 @@ sed -i "s/eth0,net=192\.168\.1\.0\/24,dhcpstart=192\.168\.1\.10/eth0,net=$subnet
sed -i "s/eth1,net=192\.168\.2\.0\/24,dhcpstart=192\.168\.2\.10/eth1,net=$subnet2_prefix\.0\/24,dhcpstart=$subnet2_prefix\.10/g" Makefile
sed -i "s/SandyBridge/host/g" Makefile
sed -i "s/-m 4096/-m $memory_to_use/g" Makefile
make CONF_DIR=../adam/run/config/ live
nohup make ACCEL=true SSH_PORT=$ssh_port CONF_DIR=../adam/run/config/ run >$tmp_dir/eve.log 2>&1 &
sed -i "s/mon:stdio/telnet:localhost:$telnet_port,server,nowait/g" Makefile
make CONF_DIR=../adam/run/config/ live || { echo "Failed to build EVE" ; exit 1; }
nohup make ACCEL=true SSH_PORT="$ssh_port" CONF_DIR=../adam/run/config/ run >"$tmp_dir"/eve.log 2>&1 &
echo $! >../eve.pid
echo ========================================
echo "EVE pid:"
cat ../eve.pid
echo ========================================
echo "Try to modify EVE config"
echo ========================================
echo "You can connect to eve via telnet:"
echo "telnet localhost $telnet_port"
echo ========================================
cd $adam_dir || exit 1
UUID="$(docker run -v "$adam_dir"/run:/adam/run lfedge/adam admin --server https://"$IP":"$unused_port" device list)"
max_retry=30
counter=0
until [ "$UUID" ]; do
[[ counter -eq $max_retry ]] && echo "Failed to list devices!" && exit 1
echo "Trying again. Try #$counter"
sleep 30
UUID="$(docker run -v "$adam_dir"/run:/adam/run lfedge/adam admin --server https://"$IP":"$unused_port" device list)"
((counter++))
to_exit=0
while [ "$to_exit" -eq 0 ]; do
counter=0
until [ "$UUID" ]; do
[[ counter -eq $max_retry ]] && to_exit=1 && break
echo "Trying again. Try #$counter"
sleep 35
UUID="$(docker run -v "$adam_dir"/run:/adam/run lfedge/adam admin --server https://"$IP":"$unused_port" device list)"
((counter++))
done
if [ "$to_exit" -eq "1" ]; then
echo "Failed to list devices!"
echo ========================================
echo "You can connect to eve via telnet:"
echo "telnet localhost $telnet_port"
echo ========================================
while true; do
read -p "Do you want to try again? (y/n)" yn
case $yn in
[Yy]*)
to_exit=0
break
;;
[Nn]*) exit 1 ;;
*) echo "Please answer y or n." ;;
esac
done
else
break
fi
done
UUID=$(echo "$UUID" | xargs)
echo ========================================
echo "EVE device UUID:"
echo $UUID
echo ========================================

for i in "${config_files[@]}"
do
for i in "${config_files[@]}"; do
sed -i "s/DEVICE_UUID/$UUID/g" "$adam_dir"/run/"$i"
sed -i -e "s/SSH_KEY/$(sed 's:/:\\/:g' /root/.ssh/id_rsa.pub)/" "$adam_dir"/run/"$i"
done
Expand All @@ -153,35 +181,61 @@ echo ========================================
echo "Wait for ssh"
echo ========================================
max_retry=10
counter=0
until ssh -o StrictHostKeyChecking=no -o ConnectTimeout=2 -p $ssh_port localhost 'sleep 1'; do
[[ counter -eq $max_retry ]] && echo "Failed to ssh!" && exit 1
echo "Trying again. Try #$counter"
sleep 15
((counter++))
to_exit=0
while [ "$to_exit" -eq 0 ]; do
counter=0
until ssh -o StrictHostKeyChecking=no -o ConnectTimeout=2 -p "$ssh_port" localhost 'sleep 1'; do
[[ counter -eq $max_retry ]] && to_exit=1 && break
echo "Trying again. Try #$counter"
sleep 15
((counter++))
done
if [ "$to_exit" -eq "1" ]; then
echo "Failed to ssh!"
echo ========================================
echo "You can connect to eve via telnet:"
echo "telnet localhost $telnet_port"
echo ========================================
while true; do
read -p "Do you want to try again? (y/n)" yn
case $yn in
[Yy]*)
to_exit=0
break
;;
[Nn]*) exit 1 ;;
*) echo "Please answer y or n." ;;
esac
done
else
break
fi
done
echo ========================================
echo "EVE config successfull"
echo "You can connect to node via ssh"
echo "sudo ssh -p $ssh_port localhost"
echo "Or via telnet:"
echo "telnet localhost $telnet_port"
echo "You can edit config in file:"
echo "$adam_dir"/run/cfg.json
echo "And send it to eve by running:"
echo docker run -v "$adam_dir"/run:/adam/run lfedge/adam admin --server https://"$IP":$unused_port device config set --uuid "$UUID" --config-path ./run/cfg.json
echo "Or you can run above command with files:"
for i in "${config_files[@]}"
do
echo "... ./run/$i"
for i in "${config_files[@]}"; do
echo -e "\t./run/$i"
done
while true; do
read -p "Do you want to cleanup? (y/n)" yn
case $yn in
[Yy]* )
kill $(cat $tmp_dir/eve.pid)
kill $(cat $tmp_dir/adam.pid)
sleep 5
rm -rf $tmp_dir ; break;;
[Nn]* ) exit;;
* ) echo "Please answer y or n.";;
esac
read -p "Do you want to cleanup? (y/n)" yn
case $yn in
[Yy]*)
kill $(cat $tmp_dir/eve.pid)
kill $(cat $tmp_dir/adam.pid)
sleep 5
rm -rf $tmp_dir
break
;;
[Nn]*) exit ;;
*) echo "Please answer y or n." ;;
esac
done

0 comments on commit 2da24b1

Please sign in to comment.