Add support to run as sudo user on BMC

Change-Id: I81ee5536fc1b59e70a8e7f5987babdfe412b445a
Signed-off-by: George Keishing <gkeishin@in.ibm.com>
diff --git a/lib/bmc_ssh_utils.py b/lib/bmc_ssh_utils.py
index 3aa90fa..7f7c23f 100755
--- a/lib/bmc_ssh_utils.py
+++ b/lib/bmc_ssh_utils.py
@@ -4,6 +4,7 @@
 This module provides many valuable bmc ssh functions such as bmc_execute_command.
 """
 
+import os
 import gen_valid as gv
 import gen_robot_ssh as grs
 from robot.libraries.BuiltIn import BuiltIn
@@ -62,6 +63,10 @@
                             'timeout': '25.0', 'prompt': '# ', 'port': ssh_port}
     login_args = {'username': openbmc_username, 'password': openbmc_password}
 
+    openbmc_user_type = os.environ.get('USER_TYPE', "") or \
+        BuiltIn().get_variable_value("${USER_TYPE}", default="")
+    if openbmc_user_type == 'sudo':
+        cmd_buf = 'sudo ' + cmd_buf
     return grs.execute_ssh_command(cmd_buf, open_connection_args, login_args,
                                    print_out, print_err, ignore_err, fork,
                                    quiet, test_mode, time_out)
@@ -78,7 +83,6 @@
                        os_host="",
                        os_username="",
                        os_password=""):
-
     r"""
     Run the given command in an OS SSH session and return the stdout, stderr and the return code.