def test_connect_src2(self, mock_run):
     """Test connect flow with mocked manager."""
     serializer = SourceSerializer(self.source2)
     source = serializer.data
     hosts = source['hosts']
     connection_port = source['port']
     _connect(Value('i', ScanJob.JOB_RUN), self.scan_task, hosts, Mock(),
              self.cred, connection_port)
     mock_run.assert_called_with(ANY)
 def test_connect_paramiko(self, mock_run):
     """Test connect with paramiko."""
     mock_run.return_value.status = 'successful'
     serializer = SourceSerializer(self.source3)
     source = serializer.data
     hosts = source['hosts']
     connection_port = source['port']
     _connect(Value('i', ScanJob.JOB_RUN),
              self.scan_task, hosts, Mock(), self.cred,
              connection_port, self.concurrency)
     mock_run.assert_called()
 def test_connect_failure_src2(self, mock_run, mock_ssh_pass):
     """Test connect flow with mocked manager and failure."""
     serializer = SourceSerializer(self.source2)
     source = serializer.data
     hosts = source['hosts']
     connection_port = source['port']
     with self.assertRaises(AnsibleError):
         _connect(Value('i', ScanJob.JOB_RUN), self.scan_task, hosts,
                  Mock(), self.cred, connection_port)
         mock_run.assert_called()
         mock_ssh_pass.assert_called()
 def test_secret_file_fail(self, mock_run):
     """Test modifying the log level."""
     mock_run.side_effect = AnsibleRunnerException()
     serializer = SourceSerializer(self.source2)
     source = serializer.data
     hosts = source['hosts']
     connection_port = source['port']
     with self.assertRaises(AnsibleRunnerException):
         _connect(Value('i', ScanJob.JOB_RUN),
                  self.scan_task, hosts, Mock(), self.cred,
                  connection_port, self.concurrency)
         mock_run.assert_called()
 def test_connect_runner_error(self, mock_run):
     """Test connect flow with mocked manager."""
     mock_run.side_effect = AnsibleRunnerException('Fail')
     serializer = SourceSerializer(self.source2)
     source = serializer.data
     hosts = source['hosts']
     connection_port = source['port']
     with self.assertRaises(AnsibleRunnerException):
         _connect(Value('i', ScanJob.JOB_RUN), self.scan_task,
                  hosts, Mock(), self.cred, connection_port,
                  self.concurrency)
         mock_run.assert_called()
 def test_connect(self, mock_run):
     """Test connect flow with mocked manager."""
     mock_run.return_value.status = 'successful'
     serializer = SourceSerializer(self.source)
     source = serializer.data
     hosts = source['hosts']
     exclude_hosts = source['exclude_hosts']
     connection_port = source['port']
     _connect(Value('i', ScanJob.JOB_RUN),
              self.scan_task, hosts, Mock(), self.cred,
              connection_port, self.concurrency,
              exclude_hosts)
     mock_run.assert_called()
 def test_modifying_log_level(self, mock_run):
     """Test modifying the log level."""
     mock_run.return_value.status = 'successful'
     serializer = SourceSerializer(self.source2)
     source = serializer.data
     hosts = source['hosts']
     connection_port = source['port']
     _connect(Value('i', ScanJob.JOB_RUN),
              self.scan_task, hosts, Mock(), self.cred,
              connection_port, self.concurrency)
     mock_run.assert_called()
     calls = mock_run.mock_calls
     # Check to see if the parameter was passed into the runner.run()
     self.assertIn('verbosity=1', str(calls[0]))
 def test_pause_connect(self, mock_run):
     """Test pause of connect."""
     # Test cancel at _connect level
     serializer = SourceSerializer(self.source3)
     source = serializer.data
     hosts = source['hosts']
     connection_port = source['port']
     with self.assertRaises(NetworkPauseException):
         _connect(Value('i', ScanJob.JOB_TERMINATE_PAUSE),
                  self.scan_task, hosts, Mock(), self.cred,
                  connection_port, self.concurrency)
     # Test cancel at run() level
     mock_run.side_effect = NetworkPauseException()
     scanner = ConnectTaskRunner(self.scan_job3, self.scan_task3)
     _, scan_result = scanner.run(Value('i', ScanJob.JOB_RUN))
     self.assertEqual(scan_result, ScanTask.PAUSED)
 def test_connect_ssh_crash(self, mock_run):
     """Simulate an ssh crash."""
     mock_run.return_value.status = 'successful'
     serializer = SourceSerializer(self.source)
     source = serializer.data
     hosts = source['hosts']
     exclude_hosts = source['exclude_hosts']
     connection_port = source['port']
     path = os.path.abspath(
         os.path.join(os.path.dirname(__file__),
                      'test_util/crash.py'))
     _connect(Value('i', ScanJob.JOB_RUN), self.scan_task,
              hosts, Mock(), self.cred, connection_port,
              self.concurrency, exclude_hosts,
              base_ssh_executable=path)
     mock_run.assert_called()
 def test_connect_ssh_hang(self, mock_run):
     """Simulate an ssh hang."""
     serializer = SourceSerializer(self.source)
     source = serializer.data
     hosts = source['hosts']
     exclude_hosts = source['exclude_hosts']
     connection_port = source['port']
     path = os.path.abspath(
         os.path.join(os.path.dirname(__file__),
                      '../../../test_util/hang.py'))
     _connect(Value('i', ScanJob.JOB_RUN),
              self.scan_task,
              hosts,
              Mock(),
              self.cred,
              connection_port,
              exclude_hosts,
              base_ssh_executable=path,
              ssh_timeout='0.1s')
     mock_run.assert_called_with(ANY)