def test_context_manager(self): with bash.RemoteShell('192.168.2.10') as client: pass self.assertTrue(self.mock_connect.call_count == 1) # >=1 because __del__ (in most python implementations) # calls close() self.assertTrue(self.mock_close.call_count >= 1)
def setUp(self): super(TestRemoteShell, self).setUp() execute_patcher = mock.patch.object(bash.ssh.SSH, 'remote_execute') self.mock_execute = execute_patcher.start() self.mock_execute.return_value = self.resultdict self.remoteshell = bash.RemoteShell('192.168.2.10') self.addCleanup(execute_patcher.stop)
def test_init_contains_kwargs(self, mock_init): mock_init.side_effect = self.initpatch allkwargs = { 'password': '******', 'username': '******', 'private_key': 'pkey', 'key_filename': 'pkeyfile', 'port': self.port, 'timeout': 100, 'gateway': 'g', 'options': { 'StrictHostKeyChecking': False }, 'interactive': True, 'root_password': '******', } self.remoteshell = bash.RemoteShell(self.host, **allkwargs) mock_init.assert_called_once_with(self._instance, self.host, **allkwargs)
def get_systeminfo(ipaddress, config, interactive=False): """Run data plane discovery using this module against a host. :param ipaddress: address to the host to discover. :param config: arguments and configuration suppplied to satori. :keyword interactive: whether to prompt the user for information. """ if (ipaddress in utils.get_local_ips() or ipaddress_module.ip_address(unicode(ipaddress)).is_loopback): client = bash.LocalShell() client.host = "localhost" client.port = 0 else: client = bash.RemoteShell(ipaddress, username=config['host_username'], private_key=config['host_key'], interactive=interactive) install_remote(client) return system_info(client)