Provide a login port for user by email, determine whether to send the ssh_port message based on the uuid.
Signed-off-by: Zhang Yale zhangyale3@huawei.com --- daemon/sshd | 89 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 69 insertions(+), 20 deletions(-)
diff --git a/daemon/sshd b/daemon/sshd index 98f31d77..1f7c4126 100755 --- a/daemon/sshd +++ b/daemon/sshd @@ -1,6 +1,16 @@ #!/bin/sh # pub_key # email +# uuid +# ssh_port_len +# ssh_port_base + +. $LKP_SRC/lib/http.sh + +sshr_ip=$LKP_SERVER +sshr_port=5050 +[ -n "$sshr_port_len" ] || sshr_port_len=2000 +[ -n "$sshr_port_base" ] || sshr_port_base=30000
run_ssh() { @@ -11,40 +21,79 @@ run_ssh() systemctl start sshd }
-compose_email() +data_success() { - deadline=$(date -d "+$runtime seconds" +"%Y-%m-%d %H:%M:%S") data="To: $email -Subject: [NOTIFY compass-ci] $testbox ready to ssh +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. + The datails are as follows:
-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@api.compass-ci.openeuler.org -p $port + Due time: + $deadline + HW: + nr_cpu: $nr_cpu + memory: $memory + testbox: $testbox + OS: + $os $os_version $os_arch
- Login: - ssh root@$PUB_IP - Due time: - $deadline +Regards +Compass-ci +" +}
- HW: - nr_cpu: $nr_cpu - memory: $memory - testbox: $testbox - OS: - $os $os_version $os_arch +data_failure() +{ + data="To: $email +Subject: [NOTIFY Compass-ci] Applying $testbox failed + +Dear $user_name: + Sorry to inform you that your application failed. + You may need to wait for a while and then try again.
Regards -compass-ci +Compass-ci " }
+compose_email() +{ + deadline=$(date -d "+$runtime seconds" +"%Y-%m-%d %H:%M:%S") + if [ -n "$port" ]; then + data_success + else + data_failure + fi +} + +get_port() +{ + [ -n "$uuid" ] || return + for i in $(seq 1 10) + do + port=$(($(date +%s%N)%"$sshr_port_len"+"$sshr_port_base")) + ssh -o StrictHostKeyChecking=no -o ExitOnForwardFailure=yes -o TCPKeepAlive=yes \ + -Nf -R $port:localhost:22 sshr@"$sshr_ip" -p "$sshr_port" &>/dev/null + [ $? -eq 0 ] || continue + return + done + port="" +} + 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
+get_port()
=> set_port
+{
- [ -n "$uuid" ] || return
blank line here
Let's convert to new my_xxx variable names for user_name, uuid, etc.
- for i in $(seq 1 10)
- do
port=$(($(date +%s%N)%"$sshr_port_len"+"$sshr_port_base"))
ssh -o StrictHostKeyChecking=no -o ExitOnForwardFailure=yes -o TCPKeepAlive=yes \
-Nf -R $port:localhost:22 sshr@"$sshr_ip" -p "$sshr_port" &>/dev/null
[ $? -eq 0 ] || continue
return
continue/return can be merged to
&& return
- done
- port=""
+}
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 -- 2.23.0
On Fri, Oct 16, 2020 at 10:31:29AM +0800, Wu Fengguang wrote:
+get_port()
=> set_port
Ok
+{
- [ -n "$uuid" ] || return
blank line here
Let's convert to new my_xxx variable names for user_name, uuid, etc.
Ok, I got it.
- for i in $(seq 1 10)
- do
port=$(($(date +%s%N)%"$sshr_port_len"+"$sshr_port_base"))
ssh -o StrictHostKeyChecking=no -o ExitOnForwardFailure=yes -o TCPKeepAlive=yes \
-Nf -R $port:localhost:22 sshr@"$sshr_ip" -p "$sshr_port" &>/dev/null
[ $? -eq 0 ] || continue
return
continue/return can be merged to
&& return
Good idea!!!
Thanks, Yale
- done
- port=""
+}
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 -- 2.23.0