Step 1: Move vm scripts to the right place
[integration/test.git] / test / tools / tools_vm / scripts / connect.sh
1 #!/usr/bin/env sh
2 # Connect to ODL Karaf shell. Mostly used for testing.
3
4 # Output verbose debug info (true) or not (anything else)
5 VERBOSE=true
6 # Port that the Karaf shell listens on
7 KARAF_SHELL_PORT=8101
8
9 # This could be done with public key crypto, but sshpass is easier
10 if ! command -v sshpass &> /dev/null; then
11     echo "Installing sshpass. It's used connecting non-interactively"
12     if "$VERBOSE" = true; then
13         sudo yum install -y sshpass
14     else
15         sudo yum install -y sshpass &> /dev/null
16     fi
17 fi
18
19 echo "Will repeatedly attempt connecting to Karaf shell until it's ready"
20 # Loop until exit status 0 (success) given by Karaf shell
21 # Exit status 255 means Karaf shell isn't open for SSH connections yet
22 # Exit status 1 means `dropAllPacketsRpc on` isn't runnable yet
23 until sshpass -p karaf ssh -p $KARAF_SHELL_PORT -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o PreferredAuthentications=password karaf@localhost
24 do
25     echo "Karaf shell isn't ready yet, sleeping 5 seconds..."
26     sleep 5
27 done