Merge "Move dlux Sonar scan to Sonarcloud"
[releng/builder.git] / jjb / packaging / test-karaf.expect
1 #!/usr/bin/expect
2 # This script starts the Karaf shell and sends the password for SSH auth.
3 # Further tests in Karaf shell can be done here
4
5 # Echo commands
6 log_user 1
7
8 # Time expect will wait for output
9 set timeout 30
10
11 # Default password
12 set password "karaf"
13 # Default prompt
14 set prompt "opendaylight-user@root>"
15
16 # Wait for Karaf SSH server to come online
17 send_user "Waiting on OpenDaylight to start listening for SSH on port 8101\n"
18 exec bash -c "while ! nmap -Pn -p8101 localhost | grep -q open; do sleep 0.1; done"
19
20 # SSH into Karaf shell
21 spawn ssh -p 8101 -o StrictHostKeyChecking=no karaf@127.0.0.1
22
23 # Auth to Karaf shell
24 expect "Password authentication"
25 expect "Password: "
26 send "$password\r"
27
28 # Show features to make debugging easier
29 expect "$prompt"
30 send "feature:list\r"
31
32 # Verify that a major feature is present
33 expect "$prompt"
34 send "feature:list | grep odl-netvirt-openstack\r"
35 expect {{
36   timeout {{
37     send_user "\nTest feature not found\n"
38     exit 1
39   }}
40   "OpenDaylight :: NetVirt :: OpenStack" {{
41     send_user "\nTest feature available\n"
42   }}
43 }}
44
45 # Install feature
46 expect "$prompt"
47 send "feature:install odl-netvirt-openstack\r"
48 expect {{
49   "Error executing command: Can't install feature" {{
50     send_user "\nFailed to install test feature\n"
51     exit 1
52   }}
53 }}
54
55 # Verify installed feature is actually installed
56 expect "$prompt"
57 # The -i flag will show only installed features
58 send "feature:list -i | grep odl-netvirt-openstack\r"
59 expect {{
60   timeout {{
61     send_user "\nTest feature not installed\n"
62     exit 1
63   }}
64   "OpenDaylight :: NetVirt :: OpenStack" {{
65     send_user "\nTest feature installed successfully\n"
66   }}
67 }}