Move errors from import to connect (#50034) (#50036)

* Move errors from import to connect (#50034)

(cherry picked from commit bf4ad56479)

* Add changelog fragment.
This commit is contained in:
Nathaniel Case 2019-01-14 15:32:16 -05:00 committed by Toshio Kuratomi
parent ffd1590a63
commit 41c98d208b
2 changed files with 11 additions and 2 deletions

View file

@ -0,0 +1,3 @@
---
bugfixes:
- Moved error in netconf connection plugin from at import to on connection.

View file

@ -187,8 +187,9 @@ try:
from ncclient.operations import RPCError
from ncclient.transport.errors import SSHUnknownHostError
from ncclient.xml_ import to_ele, to_xml
HAS_NCCLIENT = True
except ImportError:
raise AnsibleError("ncclient is not installed")
HAS_NCCLIENT = False
try:
from __main__ import display
@ -245,8 +246,13 @@ class Connection(NetworkConnectionBase):
return super(Connection, self).exec_command(cmd, in_data, sudoable)
def _connect(self):
super(Connection, self)._connect()
if not HAS_NCCLIENT:
raise AnsibleError(
'ncclient is required to use the netconf connection type.\n'
'Please run pip install ncclient'
)
super(Connection, self)._connect()
display.display('ssh connection done, starting ncclient', log_only=True)
allow_agent = True