def test_populate_not_build_all(self): self.env.get_repository = lambda authname=None: Mock( get_changeset=lambda rev: Mock(date=to_datetime(rev * 1000, utc)), get_node=lambda path, rev=None: Mock( get_entries=lambda: [Mock(), Mock()], get_history=lambda: [('somepath', 123, 'edit'), ('somepath', 121, 'edit'), ('somepath', 120, 'edit')] ), normalize_path=lambda path: path, rev_older_than=lambda rev1, rev2: rev1 < rev2 ) BuildConfig(self.env, 'test', path='somepath', active=True).insert() platform1 = TargetPlatform(self.env, config='test', name='P1') platform1.insert() platform2 = TargetPlatform(self.env, config='test', name='P2') platform2.insert() queue = BuildQueue(self.env) queue.populate() queue.populate() queue.populate() builds = list(Build.select(self.env, config='test')) builds.sort(lambda a, b: cmp(a.platform, b.platform)) self.assertEqual(2, len(builds)) self.assertEqual(platform1.id, builds[0].platform) self.assertEqual('123', builds[0].rev) self.assertEqual(platform2.id, builds[1].platform) self.assertEqual('123', builds[1].rev)
def test_reset_orphaned_builds(self): BuildConfig(self.env, 'test').insert() platform = TargetPlatform(self.env, config='test', name='Foo') platform.insert() build1 = Build(self.env, config='test', platform=platform.id, rev=123, rev_time=42, status=Build.IN_PROGRESS, slave='heinz', started=time.time() - 600) # Started ten minutes ago build1.insert() build2 = Build(self.env, config='test', platform=platform.id, rev=124, rev_time=42, status=Build.IN_PROGRESS, slave='heinz', started=time.time() - 60) # Started a minute ago build2.insert() queue = BuildQueue(self.env, timeout=300) # 5 minutes timeout build = queue.reset_orphaned_builds() self.assertEqual(Build.PENDING, Build.fetch(self.env, build1.id).status) self.assertEqual(Build.IN_PROGRESS, Build.fetch(self.env, build2.id).status)
def test_should_delete_build_outside_revision_range(self): messages = [] self.env.log = Mock(info=lambda msg, *args: messages.append(msg)) self.repos.rev_older_than = lambda rev1, rev2: rev1 < rev2 config = BuildConfig(self.env, 'test', active=True, min_rev=120, max_rev=123) config.insert() platform = TargetPlatform(self.env, config='test', name='stuff') platform.insert() build1 = Build(self.env, config=config.name, rev=42, platform=platform.id, rev_time=123456) build1.insert() build2 = Build(self.env, config=config.name, rev=10042, platform=platform.id, rev_time=123456) build2.insert() queue = BuildQueue(self.env, build_all=True) self.assertEqual(True, queue.should_delete_build(build1, self.repos)) self.assertEqual(True, queue.should_delete_build(build2, self.repos)) self.assert_("outside of the revision range" in messages[0]) self.assert_("outside of the revision range" in messages[1])
def _process_build_creation(self, req, slave_token): queue = BuildQueue(self.env, build_all=self.build_all, stabilize_wait=self.stabilize_wait, timeout=self.slave_timeout) try: queue.populate() except AssertionError, e: self.log.error(e.message, exc_info=True) self._send_error(req, HTTP_BAD_REQUEST, e.message)
def test_register_slave_match_simple_fail(self): BuildConfig(self.env, 'test', active=True).insert() platform = TargetPlatform(self.env, config='test', name="Unix") platform.rules.append(('family', 'posix')) platform.insert() queue = BuildQueue(self.env) platforms = queue.match_slave('foo', {'family': 'nt'}) self.assertEqual([], platforms)
def test_register_slave_match_regexp_invalid(self): BuildConfig(self.env, 'test', active=True).insert() platform = TargetPlatform(self.env, config='test', name="Unix") platform.rules.append(('version', '8(\.\d')) platform.insert() queue = BuildQueue(self.env) platforms = queue.match_slave('foo', {'version': '7.8.1'}) self.assertEqual([], platforms)
def test_register_slave_match_case_insensitive(self): BuildConfig(self.env, 'test', active=True).insert() platform = TargetPlatform(self.env, config='test', name="Unix") platform.rules.append(('os', 'LiNUX')) platform.insert() platform_id = platform.id queue = BuildQueue(self.env) platforms = queue.match_slave('foo', {'os': 'linux'}) self.assertEqual(1, len(platforms)) self.assertEqual(platform_id, platforms[0].id)
def test_register_slave_match_regexp(self): BuildConfig(self.env, 'test', active=True).insert() platform = TargetPlatform(self.env, config='test', name="Unix") platform.rules.append(('version', '8\.\d\.\d')) platform.insert() platform_id = platform.id queue = BuildQueue(self.env) platforms = queue.match_slave('foo', {'version': '8.2.0'}) self.assertEqual(1, len(platforms)) self.assertEqual(platform_id, platforms[0].id)
def test_match_slave_match(self): BuildConfig(self.env, 'test', active=True).insert() platform = TargetPlatform(self.env, config='test', name="Unix") platform.rules.append(('family', 'posix')) platform.insert() platform_id = platform.id queue = BuildQueue(self.env) platforms = queue.match_slave('foo', {'family': 'posix'}) self.assertEqual(1, len(platforms)) self.assertEqual(platform_id, platforms[0].id)
def _process_build_creation(self, req): queue = BuildQueue(self.env, build_all=self.build_all, stabilize_wait=self.stabilize_wait, timeout=self.slave_timeout) queue.populate() try: elem = xmlio.parse(req.read()) except xmlio.ParseError, e: self.log.error('Error parsing build initialization request: %s', e, exc_info=True) raise HTTPBadRequest('XML parser error')
def test_should_delete_build_platform_dont_exist(self): messages = [] self.env.log = Mock(info=lambda msg, *args: messages.append(msg)) config = BuildConfig(self.env, 'test', active=True) config.insert() build = Build(self.env, config=config.name, rev=42, platform="no-stuff", rev_time=123456) build.insert() queue = BuildQueue(self.env, build_all=True) self.assertEqual(True, queue.should_delete_build(build, self.repos)) self.assert_("platform no longer exists" in messages[0])
def test_register_slave_match_regexp_multi(self): BuildConfig(self.env, 'test', active=True).insert() platform = TargetPlatform(self.env, config='test', name="Unix") platform.rules.append(('os', '^Linux')) platform.rules.append(('processor', '^[xi]\d?86$')) platform.insert() platform_id = platform.id queue = BuildQueue(self.env) platforms = queue.match_slave('foo', {'os': 'Linux', 'processor': 'i686'}) self.assertEqual(1, len(platforms)) self.assertEqual(platform_id, platforms[0].id)
def test_next_pending_build_inactive_config(self): """ Make sure that builds for a deactived build config are not scheduled. """ BuildConfig(self.env, 'test').insert() platform = TargetPlatform(self.env, config='test', name='Foo') platform.insert() build = Build(self.env, config='test', platform=platform.id, rev=123, rev_time=42, status=Build.PENDING) build.insert() queue = BuildQueue(self.env) build = queue.get_build_for_slave('foobar', {}) self.assertEqual(None, build)
def test_should_delete_build_config_none(self): out = [] self.env.log = Mock( info=lambda msg, *args: out.extend([msg] + list(args))) platform = TargetPlatform(self.env, config='test', name='stuff') platform.insert() build = Build(self.env, config='does_not_exist', rev=42, platform=platform.id, rev_time=123456) build.insert() queue = BuildQueue(self.env, build_all=True) self.assertEqual(True, queue.should_delete_build(build, self.repos)) self.assertTrue("configuration is deactivated" in out[0]) self.assertEquals('unknown config "does_not_exist"', out[1])
def test_should_delete_build_config_deactivated(self): messages = [] self.env.log = Mock(info=lambda msg, *args: messages.append(msg)) config = BuildConfig(self.env, 'test', active=False) config.insert() platform = TargetPlatform(self.env, config='test', name='stuff') platform.insert() build = Build(self.env, config=config.name, rev=42, platform=platform.id, rev_time=123456) build.insert() queue = BuildQueue(self.env, build_all=True) self.assertEqual(True, queue.should_delete_build(build, self.repos)) self.assert_("configuration is deactivated" in messages[0])
def test_next_pending_build_no_matching_slave(self): """ Make sure that builds for which there is no slave matching the target platform are not scheduled. """ BuildConfig(self.env, 'test', active=True).insert() build = Build(self.env, config='test', platform=1, rev=123, rev_time=42, status=Build.PENDING) build.insert() build_id = build.id queue = BuildQueue(self.env) build = queue.get_build_for_slave('foobar', {}) self.assertEqual(None, build)
def _process_build_creation(self, req, slave_token): queue = BuildQueue(self.env, build_all=self.build_all, stabilize_wait=self.stabilize_wait, timeout=self.slave_timeout) queue.populate() try: elem = xmlio.parse(req.read()) except xmlio.ParseError, e: self.log.error('Error parsing build initialization request: %s', e, exc_info=True) self._send_error(req, HTTP_BAD_REQUEST, 'XML parser error')
def test_get_build_for_slave(self): """ Make sure that a pending build of an activated configuration is scheduled for a slave that matches the target platform. """ BuildConfig(self.env, 'test', active=True).insert() platform = TargetPlatform(self.env, config='test', name='Foo') platform.insert() build = Build(self.env, config='test', platform=platform.id, rev=123, rev_time=42, status=Build.PENDING) build.insert() build_id = build.id queue = BuildQueue(self.env) build = queue.get_build_for_slave('foobar', {}) self.assertEqual(build_id, build.id)
def test_populate_no_repos(self): """ Cannot work when there are no repositories defined. """ self.env.get_repository = lambda: None queue = BuildQueue(self.env) self.assertRaises(AssertionError, queue.populate)
def test_should_delete_build_old_with_not_buildall(self): messages = [] self.env.log = Mock(info=lambda msg, *args: messages.append(msg)) config = BuildConfig(self.env, 'test', active=True) config.insert() platform = TargetPlatform(self.env, config='test', name='stuff') platform.insert() build1 = Build(self.env, config=config.name, rev=42, platform=platform.id, rev_time=123456) build1.insert() build2 = Build(self.env, config=config.name, rev=43, platform=platform.id, rev_time=123457, slave='slave') build2.insert() queue = BuildQueue(self.env, build_all=False) self.assertEqual(True, queue.should_delete_build(build1, self.repos)) self.assert_("more recent build exists" in messages[0])
def build_populator(): queue = BuildQueue(self.env, build_all=True) queue.populate()