import os
import shutil
import tempfile
-import traceback
from ConfigParser import SafeConfigParser
from gitbuildsys.cmd_export import main as cmd_export
import gbp_repocache
from gbp_repocache import CachedRepo, CachedRepoError
-from obs_service_gbp_utils import GbpServiceError, fork_call, sanitize_uid_gid
-from obs_service_gbp_utils import write_treeish_meta
+from obs_service_gbp_utils import GbpServiceError, GbpChildBTError, fork_call
+from obs_service_gbp_utils import sanitize_uid_gid, write_treeish_meta
# Setup logging
'%s', err)
LOGGER.error('Most likely a configuration error (or a BUG)!')
raise ServiceError('Failed to run GBS thread: %s' % err, 1)
- except CmdError as err:
- raise ServiceError('GBS export failed: %s' % err, 2)
- except Exception as err:
- LOGGER.debug(traceback.format_exc())
- raise ServiceError('Uncaught exception in GBS, export failed', 2)
+ except GbpChildBTError as err:
+ # CmdError and its sublasses are exptected errors
+ if issubclass(err.typ, CmdError):
+ raise ServiceError('GBS export failed: %s' % err.val, 2)
+ else:
+ LOGGER.error('Uncaught exception in GBS:\n'
+ '%s', err.prettyprint_tb())
+ raise ServiceError('GBS crashed, export failed', 2)
# Move packaging files from tmpdir to actual outdir
exportdir = os.path.join(tmpdir, os.listdir(tmpdir)[0])
"""Tests for the GBS source service"""
import grp
+import mock
import json
import os
import shutil
TEST_DATA_DIR = os.path.abspath(os.path.join('tests', 'data'))
+class MockGbsError(Exception):
+ """Mock gbs crashes"""
+ pass
+
+def _mock_export():
+ """Mock export main function for testing crashes"""
+ raise MockGbsError()
+
+
def service(argv=None):
"""Wrapper for service"""
# Set non-existent config file so that user/system settings don't affect
eq_(service(['--url', self.orig_repo.path, '--revision', 'v0.1~1']), 2)
eq_(os.listdir('.'), [])
+ @mock.patch('obs_service_gbs.command.cmd_export', _mock_export)
+ def test_gbs_crash(self):
+ """Test crash of gbs export"""
+ eq_(service(['--url', self.orig_repo.path, '--revision', 'master']), 2)
+
def test_options_outdir(self):
"""Test the --outdir option"""
outdir = os.path.join(self.tmpdir, 'outdir')