def _execute_knotc(self, *knotc_args, **kw): """Run the Knot client and check the output :param expected_output: expected output (default: 'OK') :type expected_output: str :param expected_error: expected alternative output, will be \ logged as info(). Default: not set. :type expected_error: str """ # Knotc returns "0" even on failure, we have to check for 'OK' # https://gitlab.labs.nic.cz/labs/knot/issues/456 LOG.debug("Executing knotc with %r", knotc_args) expected = kw.get('expected_output', 'OK') expected_alt = kw.get('expected_error', None) try: out, err = execute(self._knotc_cmd_name, *knotc_args) out = out.rstrip() LOG.debug("Command output: %r" % out) if out != expected: if expected_alt is not None and out == expected_alt: LOG.info(_LI("Ignoring error: %r"), out) else: raise ProcessExecutionError(stdout=out, stderr=err) except ProcessExecutionError as e: LOG.error(_LE("Command output: %(out)r Stderr: %(err)r"), { 'out': e.stdout, 'err': e.stderr }) raise exceptions.Backend(e)
def test_run_failing(self, mock_run_validation, mock_cleanup_identity_file, mock_write_identity_file, mock_get_object_client, get_workflow_client_mock): mock_ctx = mock.MagicMock() mistral = mock.MagicMock() get_workflow_client_mock.return_value = mistral environment = collections.namedtuple('environment', ['variables']) mistral.environments.get.return_value = environment(variables={ 'private_key': 'shhhh' }) swiftclient = mock.MagicMock(url='http://swift:8080/v1/AUTH_test') mock_get_object_client.return_value = swiftclient mock_write_identity_file.return_value = 'identity_file_path' mock_run_validation.side_effect = ProcessExecutionError( stdout='output', stderr='error') action = validations.RunValidationAction('validation') expected = actions.Result( data=None, error={ 'stdout': 'output', 'stderr': 'error' }) self.assertEqual(expected, action.run(mock_ctx)) mock_write_identity_file.assert_called_once_with('shhhh') mock_run_validation.assert_called_once_with( mock_get_object_client(), 'validation', 'identity_file_path', constants.DEFAULT_CONTAINER_NAME, mock_ctx) mock_cleanup_identity_file.assert_called_once_with( 'identity_file_path')
def test_find_zone_serial_error(self, mock_exe): mock_exe.side_effect = ProcessExecutionError("blah") self.assertRaises(exceptions.Backend, self.kb.find_zone_serial, 'example.com')
def test_find_zone_serial__zone_not_found(self, mock_exe): mock_exe.side_effect = ProcessExecutionError( "error: [example.com.] (no such zone found)") serial = self.kb.find_zone_serial('example.com') self.assertIsNone(serial)