def prepare_basic_data(self): pkg = m.Package(name='rnv') self.s.add(pkg) self.s.flush() build = m.Build(package_id=pkg.id, state=m.Build.RUNNING, task_id=666) self.s.add(build) self.s.commit() return pkg, build
def prepare_builds(self, **kwargs): builds = {} for i, (name, state) in enumerate(sorted(kwargs.items())): pkg = m.Package(name=name) self.s.add(pkg) self.s.flush() build = m.Build(package_id=pkg.id, task_id=i + 1, state=state) self.s.add(build) builds[name] = build self.s.commit() return builds
def prio_table(self, tablename='tmp', **kwargs): try: table = Table(tablename, MetaData(), Column('pkg_id', Integer), Column('priority', Integer)) conn = self.s.connection() table.create(bind=conn) priorities = { name: prio for name, prio in kwargs.items() if '_' not in name } builds = { name[:-len("_build")]: state for name, state in kwargs.items() if name.endswith('_build') } states = { name[:-len('_state')]: state for name, state in kwargs.items() if name.endswith('_state') } pkgs = [] for name in priorities.keys(): pkg = self.s.query(m.Package).filter_by(name=name).first() if not pkg: pkg = m.Package(name=name, tracked=states.get(name) != 'ignored', collection_id=self.collection.id) self.s.add(pkg) self.s.flush() if states.get(name, True) is not None: pkg.resolved = states.get(name) != 'unresolved' pkgs.append((name, pkg)) if name in builds: self.s.add( m.Build(package_id=pkg.id, state=builds[name], task_id=self.task_id_counter, version='1', release='1.fc25', repo_id=1 if builds[name] != m.Build.RUNNING else None)) self.task_id_counter += 1 conn.execute(table.insert(), [{ 'pkg_id': pkg.id, 'priority': priorities[name] } for name, pkg in pkgs]) self.s.commit() yield table finally: self.s.rollback() conn = self.s.connection() table.drop(bind=conn, checkfirst=True) self.s.commit()
def test_time_priority(self): for days in [0, 2, 5, 7, 12]: pkg = m.Package(name='p{}'.format(days)) self.s.add(pkg) self.s.flush() build = m.Build(package_id=pkg.id, started=datetime.now() - timedelta(days, hours=1)) self.s.add(build) self.s.commit() query = self.get_scheduler().get_time_priority_query() self.assert_priority_query(query) res = sorted(query.all(), key=lambda x: x.priority) self.assertEqual(5, len(res)) expected_prios = [ -30.0, 161.339324401, 230.787748579, 256.455946637, 297.675251883 ] for item, exp in zip(res, expected_prios): self.assertAlmostEqual(exp, item.priority, places=1)
def prepare_builds(self, repo_id=1, **builds): new_builds = [] for pkg_name, state in sorted(builds.items()): states = { True: m.Build.COMPLETE, False: m.Build.FAILED, None: m.Build.RUNNING, } if isinstance(state, bool): state = states[state] package_id = self.s.query( m.Package.id).filter_by(name=pkg_name).scalar() build = m.Build(package_id=package_id, state=state, repo_id=repo_id, task_id=self.task_id_counter) self.task_id_counter += 1 self.s.add(build) new_builds.append(build) self.s.commit() return new_builds
def prepare_build(self, pkg_name, state=None, repo_id=None, resolved=True): states = { True: m.Build.COMPLETE, False: m.Build.FAILED, None: m.Build.RUNNING, } if isinstance(state, bool): state = states[state] self.prepare_packages([pkg_name]) package_id = self.s.query( m.Package.id).filter_by(name=pkg_name).scalar() build = m.Build(package_id=package_id, state=state, repo_id=repo_id or (1 if state != m.Build.RUNNING else None), version='1', release='1.fc25', task_id=self.task_id_counter, deps_resolved=resolved) self.task_id_counter += 1 self.s.add(build) self.s.commit() return build