Auto send email to remind user to login with port/domain_name and send port to sched
Signed-off-by: Luan Shengde luanshengde2@huawei.com Signed-off-by: Zhang Yale ylzhangah@qq.com --- daemon/sshd | 68 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 47 insertions(+), 21 deletions(-)
diff --git a/daemon/sshd b/daemon/sshd index 98f31d77..d1fcae52 100755 --- a/daemon/sshd +++ b/daemon/sshd @@ -1,6 +1,12 @@ #!/bin/sh # pub_key # email +# uuid + +. $LKP_SRC/lib/http.sh + +sshr_ip=$LKP_SERVER +sshr_port=5050
run_ssh() { @@ -14,37 +20,57 @@ run_ssh() compose_email() { deadline=$(date -d "+$runtime seconds" +"%Y-%m-%d %H:%M:%S") - data="To: $email -Subject: [NOTIFY compass-ci] $testbox ready to ssh - -Dear $email: - Thanks for your participation in Kunpeng and software ecosystem! - According to your application, $testbox has been provisioned. - The datails are as follows: - - Login: - ssh root@$PUB_IP - Due time: - $deadline - - HW: - nr_cpu: $nr_cpu - memory: $memory - testbox: $testbox - OS: - $os $os_version $os_arch + if [ -n $port ]; then + data="To: $email +Subject: [NOTIFY compass-ci] $testbox ready to use + +Dear $user_name: + Thanks for your participation in software ecosystem! + According to your application, $testbox has been provisioned. + Please use the following command to login: + + ssh root@api.compass-ci.openeuler.org -p $port + +Regards +compassi-ci +" + else + data="To: $email +Subject: [NOTIFY compass-ci] Applying $testbox failed + +Dear $user_name: + Sorry to inform you than your application failed. + + You may need to wait sometime and then have a second try.
Regards compass-ci " + fi +} + +get_port() +{ + [ -n "$uuid" ] || return + for i in $(seq 1 10) + do + port=$(($(date +%s%N)%10+11333)) + ssh -o StrictHostKeyChecking=no -o ExitOnForwardFailure=yes -Nf -R $port:$PUB_IP:22 sshr@"$sshr_ip" -p "$sshr_port" > out 2>&1 + [ -z "`grep -i "error" out`" ] || continue + return "$port" + break + done }
run_email() { - [ -n "$email" ] || return 0 + [ -n "$email" ] && [ -n "$uuid" ] || return 0 + user_name=$(echo "$email" | awk -F '@' '{print $1}') compose_email - curl -XPOST "$MAIL_HOST:$MAIL_PORT/send_mail_text" -d "$data" + curl -XPOST "${MAIL_HOST:-$LKP_SERVER}:${MAIL_PORT:-11312}/send_mail_text" -d "$data" }
run_ssh +get_port +report_ssh_port $port run_email