Repository: juniper/py-junos-eznc
Issue: dev.cli doesn't raise an exception incase of incorrect command

### Question

@vnitinv Is there a reason this doesn't happen in PyEZ ??

### Current behavior

When the user enters an incorrect RPC, an exception is raised:
```
Traceback (most recent call last):
  File "/Users/rsmekala/PycharmProjects/salt/tmp/wrongCLICommand.py", line 4, in <module>
    print(dev.rpc.get_test())
  File "/Users/rsmekala/PycharmProjects/salt/venv/lib/python2.7/site-packages/jnpr/junos/rpcmeta.py", line 345, in _exec_rpc
    return self._junos.execute(rpc, **dec_args)
  File "/Users/rsmekala/PycharmProjects/salt/venv/lib/python2.7/site-packages/jnpr/junos/decorators.py", line 76, in wrapper
    return function(*args, **kwargs)
  File "/Users/rsmekala/PycharmProjects/salt/venv/lib/python2.7/site-packages/jnpr/junos/decorators.py", line 31, in wrapper
    return function(*args, **kwargs)
  File "/Users/rsmekala/PycharmProjects/salt/venv/lib/python2.7/site-packages/jnpr/junos/device.py", line 794, in execute
    errs=ex)
jnpr.junos.exception.RpcError: RpcError(severity: error, bad_element: get-test, message: syntax error)
```

There is no exception raised in case of invalid CLI command. Currently, it just prints the output as though the command has executed successfully.
```
invalid command: show test: RpcError(severity: error, bad_element: test, message: syntax error, expecting <command>)
```



Changed files:
lib/jnpr/junos/device.py, tests/unit/test_device.py

diff --git a/lib/jnpr/junos/device.py b/lib/jnpr/junos/device.py
index e7bd24d1..6799ee8c 100644
--- a/lib/jnpr/junos/device.py
+++ b/lib/jnpr/junos/device.py
@@ -724,12 +724,18 @@ class _Connection(object):
             if rsp.tag == "rpc":
                 return rsp[0]
             return rsp
-        except EzErrors.ConnectClosedError as ex:
+        except (
+            EzErrors.ConnectClosedError,
+            EzErrors.RpcError,
+            EzErrors.RpcTimeoutError,
+        ) as ex:
             raise ex
-        except EzErrors.RpcError as ex:
-            return "invalid command: %s: %s" % (command, ex)
         except Exception as ex:
-            return "invalid command: " + command
+            warnings.warn(
+                "An unknown exception occurred : %s - please report." % ex,
+                RuntimeWarning,
+            )
+            raise ex
 
     # ------------------------------------------------------------------------
     # execute
@@ -828,7 +834,7 @@ class _Connection(object):
         # Something unexpected happened - raise it up
         except Exception as err:
             warnings.warn(
-                "An unknown exception occured - please report.", RuntimeWarning
+                "An unknown exception occurred - please report.", RuntimeWarning
             )
             raise
 
diff --git a/tests/unit/test_device.py b/tests/unit/test_device.py
index a812e2be..ca69b3ab 100644
--- a/tests/unit/test_device.py
+++ b/tests/unit/test_device.py
@@ -710,16 +710,26 @@ class TestDevice(unittest.TestCase):
             "get-system-uptime-information",
         )
 
-    def test_device_cli_exception(self):
-        self.dev.rpc.cli = MagicMock(side_effect=AttributeError)
-        val = self.dev.cli("show version")
-        self.assertEqual(val, "invalid command: show version")
+    def test_device_cli_connection_exception(self):
+        self.dev.connected = False
+        self.assertRaises(EzErrors.ConnectClosedError, self.dev.cli, "foo")
 
     @patch("jnpr.junos.Device.execute")
     def test_device_cli_rpc_exception(self, mock_execute):
         mock_execute.side_effect = self._mock_manager
-        val = self.dev.cli("foo")
-        self.assertEqual(val, "invalid command: foo: RpcError")
+        self.assertRaises(EzErrors.RpcError, self.dev.cli, "foo")
+
+    def test_device_cli_timeout_exception(self):
+        self.dev._conn.rpc = MagicMock(side_effect=TimeoutExpiredError)
+        self.assertRaises(EzErrors.RpcTimeoutError, self.dev.cli, "foo")
+
+    @patch("jnpr.junos.device.warnings")
+    def test_device_cli_unknown_exception(self, mock_warnings):
+        class MyException(Exception):
+            pass
+
+        self.dev._conn.rpc = MagicMock(side_effect=MyException)
+        self.assertRaises(MyException, self.dev.cli, "foo")
 
     @patch("jnpr.junos.Device.execute")
     def test_device_display_xml_rpc(self, mock_execute):