Repository: Juniper/py-junos-eznc

Issue:
Shell session does not work for root user.
I'm using the below example program. 

```
#!/usr/bin/env python
import jnpr.junos.utils
from   jnpr.junos import Device
from   jnpr.junos.utils import *
from   jnpr.junos.utils.start_shell import *
from   jnpr.junos.utils.start_shell import StartShell

DUT = Device(host='10.252.191.104', user="root", passwd = "password!")
DUT.open()
print "Device opened!"
DUT_ss = StartShell(DUT)
DUT_ss.open()
print "got thru shell open."
print DUT_ss.run("pwd")
print DUT_ss.run("ls")
```


We never print the line "got thru shell open" because the library hangs while waiting for the "% " shell prompt to appear.  I have a fix i'll be suggesting. 

Discussion:

Patch:
diff --git a/lib/jnpr/junos/device.py b/lib/jnpr/junos/device.py
index 3dcb71df..3438b910 100644
--- a/lib/jnpr/junos/device.py
+++ b/lib/jnpr/junos/device.py
@@ -496,7 +496,7 @@ class Device(object):
         self.connected = True
 
         self._nc_transform = self.transform
-        self._norm_transform = lambda: JXML.normalize_xslt.encode('UTF-8')
+        self._norm_transform = lambda: JXML.normalize_xslt
 
         normalize = kvargs.get('normalize', self._normalize)
         if normalize is True:
diff --git a/lib/jnpr/junos/utils/start_shell.py b/lib/jnpr/junos/utils/start_shell.py
index 61f97df4..5d735ad5 100644
--- a/lib/jnpr/junos/utils/start_shell.py
+++ b/lib/jnpr/junos/utils/start_shell.py
@@ -3,7 +3,7 @@ from select import select
 import re
 
 _JUNOS_PROMPT = '> '
-_SHELL_PROMPT = '% '
+_SHELL_PROMPT = '(%|#) '
 _SELECT_WAIT = 0.1
 _RECVSZ = 1024
 
@@ -35,8 +35,8 @@ class StartShell(object):
 
         :param str this: expected string/pattern.
 
-        :returns: resulting string of data
-        :rtype: str
+        :returns: resulting string of data in a list
+        :rtype: list
 
         .. warning:: need to add a timeout safeguard
         """
@@ -82,8 +82,8 @@ class StartShell(object):
         self._client = client
         self._chan = chan
 
-        got = self.wait_for('(%|>)')
-        if not got[-1].endswith(_SHELL_PROMPT):
+        got = self.wait_for(r'(%|>|#)')
+        if got[-1].endswith(_JUNOS_PROMPT):
             self.send('start shell')
             self.wait_for(_SHELL_PROMPT)
 
@@ -116,7 +116,7 @@ class StartShell(object):
         rc = ''.join(self.wait_for(this))
         self.last_ok = True if rc.find('0') > 0 else False
 
-        return (self.last_ok,got)
+        return (self.last_ok, got)
 
     # -------------------------------------------------------------------------
     # CONTEXT MANAGER


Test patch:
diff --git a/tests/unit/utils/test_start_shell.py b/tests/unit/utils/test_start_shell.py
index b3812937..ee728b02 100644
--- a/tests/unit/utils/test_start_shell.py
+++ b/tests/unit/utils/test_start_shell.py
@@ -19,9 +19,17 @@ class TestStartShell(unittest.TestCase):
 
     @patch('paramiko.SSHClient')
     @patch('jnpr.junos.utils.start_shell.StartShell.wait_for')
-    def test_startshell_open(self, mock_connect, mock_wait):
+    def test_startshell_open_with_shell_term(self, mock_wait, mock_connect):
+        mock_wait.return_value = ["user # "]
         self.shell.open()
-        mock_connect.assert_called_with('(%|>)')
+        mock_wait.assert_called_with('(%|>|#)')
+
+    @patch('paramiko.SSHClient')
+    @patch('jnpr.junos.utils.start_shell.StartShell.wait_for')
+    def test_startshell_open_with_junos_term(self, mock_wait, mock_connect):
+        mock_wait.return_value = ["user > "]
+        self.shell.open()
+        mock_wait.assert_called_with('(%|#) ')
 
     @patch('paramiko.SSHClient')
     def test_startshell_close(self, mock_connect):