On Mon, Oct 19, 2020 at 09:41:01PM +0800, Zhang Yale wrote:
[Why] 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 | 99 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 74 insertions(+), 25 deletions(-)
diff --git a/daemon/sshd b/daemon/sshd index 98f31d77..cd57be4f 100755 --- a/daemon/sshd +++ b/daemon/sshd @@ -1,6 +1,16 @@ #!/bin/sh # pub_key -# email +# my_email +# my_uuid +# ssh_port_len +# ssh_port_base
+. $LKP_SRC/lib/http.sh
+sshr_ip=$LKP_SERVER +sshr_port=5050 +[ -n "$ssh_port_len" ] || ssh_port_len=2000 +[ -n "$ssh_port_base" ] || ssh_port_base=50000
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")
^^this variable is deleted. Can not be referenced later. Thanks, Baijing
- 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
- data="To: $my_email
+Subject: [NOTIFY Compass-ci] $testbox ready to use
+Dear $my_username:
- Thanks for your participation in 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
+Regards +Compass-ci +" +}
+data_failure() +{
- data="To: $my_email
+Subject: [NOTIFY Compass-ci] Applying $testbox failed
+Dear $my_username:
- 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
+}
+set_port() +{
- [ -n "$my_uuid" ] || return
- for i in $(seq 1 10)
- do
port=$(($(date +%s%N)%"$ssh_port_len"+"$ssh_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 ] && return
- done
- port=""
+}
run_email() {
- [ -n "$email" ] || return 0
- [ -n "$my_email" ] && [ -n "$my_uuid" ] || return 0
- my_username=$(echo "$my_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 +set_port +report_ssh_port $port run_email -- 2.23.0