@ -30,7 +30,6 @@ from ansible.compat.tests.mock import patch, MagicMock
from ansible . errors import AnsibleConnectionFailure
from ansible . playbook . play_context import PlayContext
from ansible . plugins . connection import network_cli
from ansible . plugins . loader import connection_loader
@ -39,39 +38,30 @@ class TestConnectionClass(unittest.TestCase):
@patch ( " ansible.plugins.connection.paramiko_ssh.Connection._connect " )
def test_network_cli__connect_error ( self , mocked_super ) :
pc = PlayContext ( )
new_stdin = StringIO ( )
pc . network_os = ' ios '
conn = connection_loader . get ( ' network_cli ' , pc , ' /dev/null ' )
conn . ssh = MagicMock ( )
conn . receive = MagicMock ( )
conn . _ terminal = MagicMock ( )
pc . network_os = None
conn . _ network_os = ' does not exist '
self . assertRaises ( AnsibleConnectionFailure , conn . _connect )
@patch ( " ansible.plugins.connection.paramiko_ssh.Connection._connect " )
def test_network_cli__invalid_os ( self , mocked_super ) :
def test_network_cli__invalid_os ( self ) :
pc = PlayContext ( )
new_stdin = StringIO ( )
conn = connection_loader . get ( ' network_cli ' , pc , ' /dev/null ' )
conn . ssh = MagicMock ( )
conn . receive = MagicMock ( )
conn . _terminal = MagicMock ( )
pc . network_os = None
self . assertRaises ( AnsibleConnectionFailure , conn . _connect )
self . assertRaises ( AnsibleConnectionFailure , connection_loader . get , ' network_cli ' , pc , ' /dev/null ' )
@patch ( " ansible.plugins.connection.network_cli.terminal_loader " )
@patch ( " ansible.plugins.connection.paramiko_ssh.Connection._connect " )
def test_network_cli__connect ( self , mocked_super , mocked_terminal_loader ) :
pc = PlayContext ( )
pc . network_os = ' ios '
new_stdin = StringIO ( )
conn = connection_loader . get ( ' network_cli ' , pc , ' /dev/null ' )
conn . ssh = MagicMock ( )
conn . receive = MagicMock ( )
conn . _terminal = MagicMock ( )
conn . _connect ( )
self . assertTrue ( conn . _terminal . on_open_shell . called )
@ -88,8 +78,8 @@ class TestConnectionClass(unittest.TestCase):
@patch ( " ansible.plugins.connection.paramiko_ssh.Connection.close " )
def test_network_cli_close ( self , mocked_super ) :
pc = PlayContext ( )
new_stdin = StringIO ( )
conn = network_cli. Connection ( pc , new_stdin )
pc. network_os = ' ios '
conn = connection_loader. get ( ' network_cli ' , pc , ' /dev/null ' )
terminal = MagicMock ( supports_multiplexing = False )
conn . _terminal = terminal
@ -105,8 +95,8 @@ class TestConnectionClass(unittest.TestCase):
@patch ( " ansible.plugins.connection.paramiko_ssh.Connection._connect " )
def test_network_cli_exec_command ( self , mocked_super ) :
pc = PlayContext ( )
new_stdin = StringIO ( )
conn = network_cli. Connection ( pc , new_stdin )
pc. network_os = ' ios '
conn = connection_loader. get ( ' network_cli ' , pc , ' /dev/null ' )
mock_send = MagicMock ( return_value = b ' command response ' )
conn . send = mock_send
@ -124,8 +114,9 @@ class TestConnectionClass(unittest.TestCase):
def test_network_cli_send ( self ) :
pc = PlayContext ( )
new_stdin = StringIO ( )
conn = network_cli . Connection ( pc , new_stdin )
pc . network_os = ' ios '
conn = connection_loader . get ( ' network_cli ' , pc , ' /dev/null ' )
mock__terminal = MagicMock ( )
mock__terminal . terminal_stdout_re = [ re . compile ( b ' device# ' ) ]
mock__terminal . terminal_stderr_re = [ re . compile ( b ' ^ERROR ' ) ]