Fixed 'Initiate OS Host Reboot' to work with non root username.
When usering OS_USERNAME that is not root (e.g. "ubuntu"),
'Initiate OS Host Reboot' failed because the user did not have the
authority to do 'reboot'. Added code to do reboot with "sudo".
Change-Id: I7cd0e5bcce78e1dba9207cbc7be557e69b501347
Signed-off-by: Michael Walsh <micwalsh@us.ibm.com>
diff --git a/lib/utils.robot b/lib/utils.robot
index 3593633..e453db5 100755
--- a/lib/utils.robot
+++ b/lib/utils.robot
@@ -226,16 +226,18 @@
[Arguments] ${os_host}=${OS_HOST} ${os_username}=${OS_USERNAME}
... ${os_password}=${OS_PASSWORD}
- # Description of arguments:
- # os_host The DNS name or IP of the OS.
+ # Description of argument(s):
+ # os_host The host name or IP address of the OS.
# os_username The username to be used to sign in to the OS.
# os_password The password to be used to sign in to the OS.
- SSHLibrary.Open connection ${os_host}
- Login ${os_username} ${os_password}
- ${cmd_buf} Catenate reboot
- Start Command ${cmd_buf}
- SSHLibrary.Close Connection
+ ${cmd_buf}= Run Keyword If '${os_username}' == 'root'
+ ... Set Variable reboot
+ ... ELSE
+ ... Set Variable echo ${os_password} | sudo -S reboot
+
+ ${output} ${stderr} ${rc}= OS Execute Command
+ ... ${cmd_buf} fork=${1}
Initiate Auto Reboot
[Documentation] Initiate an auto reboot.