Move instantiation of terminal plugin earlier (#61261)

* Move instantiation of terminal plugin earlier

* Move test for invalid network_os to where the failure now lives
pull/61409/head
Nathaniel Case 5 years ago committed by GitHub
parent 36f4af203c
commit e8586114ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -302,6 +302,9 @@ class Connection(NetworkConnectionBase):
logging.getLogger('paramiko').setLevel(logging.DEBUG) logging.getLogger('paramiko').setLevel(logging.DEBUG)
if self._network_os: if self._network_os:
self._terminal = terminal_loader.get(self._network_os, self)
if not self._terminal:
raise AnsibleConnectionFailure('network os %s is not supported' % self._network_os)
self.cliconf = cliconf_loader.get(self._network_os, self) self.cliconf = cliconf_loader.get(self._network_os, self)
if self.cliconf: if self.cliconf:
@ -391,10 +394,6 @@ class Connection(NetworkConnectionBase):
self._ssh_shell = ssh.ssh.invoke_shell() self._ssh_shell = ssh.ssh.invoke_shell()
self._ssh_shell.settimeout(self.get_option('persistent_command_timeout')) self._ssh_shell.settimeout(self.get_option('persistent_command_timeout'))
self._terminal = terminal_loader.get(self._network_os, self)
if not self._terminal:
raise AnsibleConnectionFailure('network os %s is not supported' % self._network_os)
self.queue_message('vvvv', 'loaded terminal plugin for network_os %s' % self._network_os) self.queue_message('vvvv', 'loaded terminal plugin for network_os %s' % self._network_os)
terminal_initial_prompt = self.get_option('terminal_initial_prompt') or self._terminal.terminal_initial_prompt terminal_initial_prompt = self.get_option('terminal_initial_prompt') or self._terminal.terminal_initial_prompt

@ -34,19 +34,13 @@ from ansible.plugins.loader import connection_loader
class TestConnectionClass(unittest.TestCase): class TestConnectionClass(unittest.TestCase):
@patch("ansible.plugins.connection.paramiko_ssh.Connection._connect") def test_network_cli__invalid_os(self):
def test_network_cli__connect_error(self, mocked_super):
pc = PlayContext() pc = PlayContext()
pc.network_os = 'ios' pc.network_os = 'does not exist'
conn = connection_loader.get('network_cli', pc, '/dev/null')
conn.ssh = MagicMock() self.assertRaises(AnsibleConnectionFailure, connection_loader.get, 'network_cli', pc, '/dev/null')
conn.receive = MagicMock()
conn._network_os = 'does not exist'
self.assertRaises(AnsibleConnectionFailure, conn._connect)
def test_network_cli__invalid_os(self): def test_network_cli__no_os(self):
pc = PlayContext() pc = PlayContext()
pc.network_os = None pc.network_os = None

Loading…
Cancel
Save