def accept_dud(session, dud, builder): fire = dud.get_firehose() failed = True if dud.get('X-Debile-Failed', None) == "Yes" else False job = session.query(Job).get(dud['X-Debile-Job']) fire, _ = idify(fire) fire = uniquify(session, fire) result = Result.from_job(job) result.failed = failed result.firehose = fire session.merge(result) # Needed because a *lot* of the Firehose is # going to need unique ${WORLD}. job.dud_uploaded(session, result) session.commit() # Neato. repo = result.get_repo() try: repo.add_dud(dud) except FilesAlreadyRegistered: return reject_dud(session, dud, "dud-files-already-registered") emit('receive', 'result', result.debilize())
def get_next_job(self, suites, arches, capabilities): arches_conditions = [ Arch.name == a for a in arches ] arches = [ x.id for x in NAMESPACE.session.query(Arch).filter( or_(*arches_conditions) ).all() ] # This horseshit nonsense is due to SQLAlchemy not doing # the sane thing with Job.affinity.name.in_. Nonsense. Horseshit. job = NAMESPACE.session.query(Job).filter( Job.assigned_at==None, Job.finished_at==None, Job.arch_id.in_(arches), Job.affinity_id.in_(arches) | Job.affinity_id==None, ).outerjoin(Job.depedencies).filter( JobDependencies.id==None ).first() if job is None: return None job.assigned_at = dt.datetime.utcnow() job.builder = NAMESPACE.machine NAMESPACE.session.add(job) NAMESPACE.session.commit() emit('start', 'job', job.debilize()) return job.debilize()
def get_next_job(self, suites, components, arches, capabilities): arches = [ x.id for x in NAMESPACE.session.query(Arch).filter( Arch.name.in_(arches) ).all() ] # This horseshit nonsense is due to SQLAlchemy not doing # the sane thing with Job.affinity.name.in_. Nonsense. Horseshit. job = NAMESPACE.session.query(Job).filter( Job.externally_blocked==False, Job.assigned_at==None, Job.finished_at==None, Suite.name.in_(suites), Component.name.in_(components), Job.arch_id.in_(arches), Job.affinity_id.in_(arches), Check.name.in_(capabilities), ).outerjoin(Job.depedencies).filter( JobDependencies.id==None ).first() if job is None: return None job.assigned_at = datetime.utcnow() job.builder = NAMESPACE.machine NAMESPACE.session.add(job) NAMESPACE.session.commit() emit('start', 'job', job.debilize()) return job.debilize()
def accept_source_changes(session, changes, user): group = changes.get('X-Lucy-Group', "default") suite = changes['Distribution'] try: group_suite = session.query(GroupSuite).filter( Group.name==group, Suite.name==suite, ).one() except MultipleResultsFound: return reject_changes(session, changes, "internal-error") except NoResultFound: return reject_changes(session, changes, "invalid-suite-for-group") dsc = changes.get_dsc_obj() if dsc['Source'] != changes['Source']: return reject_changes(session, changes, "dsc-does-not-march-changes") if dsc['Version'] != changes['Version']: return reject_changes(session, changes, "dsc-does-not-march-changes") try: source = session.query(Source).filter( Source.name==dsc['Source'], Source.version==dsc['Version'], GroupSuite.group==group_suite.group, ).one() return reject_changes(session, changes, "source-already-in-group") except MultipleResultsFound: return reject_changes(session, changes, "internal-error") except NoResultFound: pass component = session.query(Component).filter_by(name="main").one() if 'Build-Architecture-Indep' in dsc: valid_affinities = dsc['Build-Architecture-Indep'] elif 'X-Build-Architecture-Indep' in dsc: valid_affinities = dsc['X-Build-Architecture-Indep'] elif 'X-Arch-Indep-Build-Arch' in dsc: valid_affinities = dsc['X-Arch-Indep-Build-Arch'] else: valid_affinities = "any" source = create_source(dsc, group_suite, component, user) create_jobs(source, valid_affinities) session.add(source) # OK. Populated entry. Let's insert. session.commit() # Neato. # OK. We have a changes in order. Let's roll. repo = Repo(group_suite.group.repo_path) repo.add_changes(changes) emit('accept', 'source', source.debilize()) # OK. It's safely in the database and repo. Let's cleanup. for fp in [changes.get_filename()] + changes.get_files(): os.unlink(fp)
def forfeit_job(self, job_id): job = NAMESPACE.session.query(Job).get(job_id) job.assigned_at = None job.builder = None NAMESPACE.session.add(job) NAMESPACE.session.commit() emit('abort', 'job', job.debilize()) return True
def close_job(self, job_id, failed): job = NAMESPACE.session.query(Job).get(job_id) job.finished_at = datetime.utcnow() NAMESPACE.session.add(job) NAMESPACE.session.commit() emit('complete', 'job', job.debilize()) return True
def reject_changes(session, changes, tag): print "REJECT: {source} because {tag}".format( tag=tag, source=changes.get_package_name()) emit('reject', 'source', { "tag": tag, "source": changes.get_package_name(), }) for fp in [changes.get_changes_file()] + changes.get_files(): os.unlink(fp)
def reject_changes(session, changes, tag): print "REJECT: {source} because {tag}".format( tag=tag, source=changes.get_package_name()) emit('reject', 'source', { "tag": tag, "source": changes.get_package_name(), }) for fp in [changes.get_filename()] + changes.get_files(): os.unlink(fp)
def close_job(self, job_id, failed): job = NAMESPACE.session.query(Job).get(job_id) job.finished_at = dt.datetime.utcnow() # We don't actually close the job here because we wait until # we accept the DUD (so that we have the artifacts to actually # give the job out to new nodes), so avoid job.close() NAMESPACE.session.add(job) NAMESPACE.session.commit() emit('complete', 'job', job.debilize()) return True
def create_builder(self, slave_name, slave_password, key): keyid = import_key(key) obid = NAMESPACE.session.query(Builder).filter_by( name=slave_name).count() if obid != 0: raise ValueError("Slave already exists.") b = Builder(maintainer=NAMESPACE.user, name=slave_name, key=keyid, password=slave_password, last_ping=dt.datetime.utcnow()) emit('create', 'slave', b.debilize()) NAMESPACE.session.add(b) NAMESPACE.session.commit() return b.debilize()
def reject_dud(session, dud, tag): print "REJECT: {source} because {tag}".format(tag=tag, source=dud['Source']) e = None try: dud.validate() except DudFileException as e: print e emit('reject', 'result', { "tag": tag, "source": dud['Source'], }) for fp in [dud.get_filename()] + dud.get_files(): os.unlink(fp)
def accept_binary_changes(session, changes, builder): # OK. We'll relate this back to a build job. job = changes.get('X-Debile-Job', None) if job is None: return reject_changes(session, changes, "no-job") job = session.query(Job).get(job) source = job.source if changes.get('Source') != source.name: return reject_changes(session, changes, "binary-source-name-mismatch") if changes.get("Version") != source.version: return reject_changes(session, changes, "binary-source-version-mismatch") if changes.get('X-Lucy-Group', "default") != source.group_suite.group.name: return reject_changes(session, changes, "binary-source-group-mismatch") if changes.get('Distribution') != source.group_suite.suite.name: return reject_changes(session, changes, "binary-source-suite-mismatch") if changes.get("Architecture") != job.arch.name: return reject_changes(session, changes, "wrong-architecture") if builder != job.builder: return reject_changes(session, changes, "wrong-builder") binary = Binary.from_job(job) ## OK. Let's make sure we can add this. try: repo = Repo(job.source.group_suite.group.repo_path) repo.add_changes(changes) except RepoSourceAlreadyRegistered: return reject_changes(session, changes, 'stupid-source-thing') job.changes_uploaded(session, binary) session.add(binary) session.commit() emit('accept', 'binary', binary.debilize()) # OK. It's safely in the database and repo. Let's cleanup. for fp in [changes.get_filename()] + changes.get_files(): os.unlink(fp)
def accept_binary_changes(session, changes, builder): # OK. We'll relate this back to a build job. job = changes.get('X-Debile-Job', None) if job is None: return reject_changes(session, changes, "no-job") job = session.query(Job).get(job) source = job.source if changes.get('Source') != source.name: return reject_changes(session, changes, "binary-source-name-mismatch") if changes.get("Version") != source.version: return reject_changes(session, changes, "binary-source-version-mismatch") if changes.get("Architecture") != job.arch.name: return reject_changes(session, changes, "wrong-architecture") if builder != job.builder: return reject_changes(session, changes, "wrong-builder") binary = Binary.from_job(job) ## OK. Let's make sure we can add this. repo = binary.group.get_repo() try: repo.add_changes(changes) except RepoSourceAlreadyRegistered: return reject_changes(session, changes, 'stupid-source-thing') job.changes_uploaded(session, binary) session.add(binary) session.commit() emit('accept', 'binary', binary.debilize()) # OK. It's safely in the database and repo. Let's cleanup. for fp in [changes.get_filename()] + changes.get_files(): os.unlink(fp)
def accept_source_changes(session, changes, user): gid = changes.get('X-Lucy-Group', "default") sid = changes['Distribution'] try: group = session.query(Group).filter_by(name=gid).one() suite = session.query(Suite).filter_by(name=sid).one() except MultipleResultsFound: return reject_changes(session, changes, "internal-error") except NoResultFound: return reject_changes(session, changes, "invalid-group-or-suite") try: source = session.query(Source).filter_by( name=changes['Source'], version=changes['Version'], group=group, ).one() return reject_changes(session, changes, "source-already-in-group") except MultipleResultsFound: return reject_changes(session, changes, "internal-error") except NoResultFound: pass MAINTAINER = re.compile("(?P<name>.*) \<(?P<email>.*)\>") source = Source(uploader=user, name=changes['Source'], version=changes['Version'], group=group, suite=suite, uploaded_at=dt.datetime.utcnow(), updated_at=dt.datetime.utcnow()) source.maintainers.append( Maintainer(comaintainer=False, **MAINTAINER.match(changes['Maintainer']).groupdict())) dsc = changes.get_dsc_obj() whos = (x.strip() for x in dsc.get("Uploaders", "").split(",") if x != "") for who in whos: source.maintainers.append( Maintainer(comaintainer=True, **MAINTAINER.match(who).groupdict())) arches = dsc['Architecture'].split() create_jobs(source, session, arches) session.add(source) # OK. Populated entry. Let's insert. session.commit() # Neato. # OK. We have a changes in order. Let's roll. repo = group.get_repo() repo.add_changes(changes) emit('accept', 'source', source.debilize()) # OK. It's safely in the database and repo. Let's cleanup. for fp in [changes.get_filename()] + changes.get_files(): os.unlink(fp)