#!/usr/bin/expect
-# This script starts the karaf shell and sends the password for SSH auth.
-# Further tests in karaf shell can be done here
+# This script starts the Karaf shell and sends the password for SSH auth.
+# Further tests in Karaf shell can be done here
# Echo commands
log_user 1
+# Time expect will wait for output
+set timeout 30
+
# Default password
set password "karaf"
# Default prompt
set prompt "opendaylight-user@root>"
-# OpenDaylight service requires some time after it starts for a successful
-# SSH connection
-sleep 10
+# Wait for Karaf SSH server to come online
+send_user "Waiting on OpenDaylight to start listening for SSH on port 8101\n"
+exec bash -c "while ! nmap -Pn -p8101 localhost | grep -q open; do sleep 0.1; done"
# SSH into Karaf shell
spawn ssh -p 8101 -o StrictHostKeyChecking=no karaf@127.0.0.1
+
+# Auth to Karaf shell
expect "Password authentication"
expect "Password: "
send "$password\r"
-# Verify expected features
+# Show features to make debugging easier
+expect "$prompt"
+send "feature:list\r"
+
+# Verify that a major feature is present
expect "$prompt"
send "feature:list | grep odl-netvirt-openstack\r"
expect {{
timeout {{
- send_user "\nTest feature not found"
+ send_user "\nTest feature not found\n"
exit 1
}}
"OpenDaylight :: NetVirt :: OpenStack" {{
- send_user "\nTest feature available"
+ send_user "\nTest feature available\n"
}}
}}
# Install feature
+expect "$prompt"
send "feature:install odl-netvirt-openstack\r"
expect {{
"Error executing command: Can't install feature" {{
- send_user "\nFailed to install test feature"
+ send_user "\nFailed to install test feature\n"
exit 1
}}
}}
# Verify installed feature is actually installed
expect "$prompt"
-send "feature:list | grep odl-netvirt-openstack\r"
+# The -i flag will only show installed features
+send "feature:list -i | grep odl-netvirt-openstack\r"
expect {{
timeout {{
send_user "\nTest feature not installed\n"
exit 1
}}
- " x " {{
+ "OpenDaylight :: NetVirt :: OpenStack" {{
send_user "\nTest feature installed successfully\n"
}}
}}
-
-# TODO Add further tests here