def cancelCallback(button, jobname, loginInfo): print('\n[CALLBACK] Canceling custom job') cancelResponse = '' if button == 0: return '' userValid, userMessage = reCheckUserCred(loginInfo) if not userValid: return userMessage # Check if jobs with jobname exist in queue existing_jobnames = QueueObject.objects.distinct('job') if jobname is not None and jobname in existing_jobnames: cancelResponse += f'Job {jobname} found.\n' else: return f'Job {jobname} is not in active Queue' # Cancel jobs objects = QueueObject.objects(job=jobname) num = len(objects) for q in objects: q.delete() cancelResponse += f'{num} tests deleted.' return cancelResponse
def addToQueue(c: CheckFlow, sha: str): # TODO: Add mode without GitHub interaction and manual DB auth entry runUrl = c._createCheckRun(sha, f'MANUAL TEST RUN {time.asctime()}') q = QueueObject() q.runUrl = runUrl q.commitSHA = sha q.installID = 2027548 q.running = False q.save()
def checkQueue(self): """ Checks Queue for remaining tests recursively :return: True if queue is """ nextUp: QueueObject queue = QueueObject.objects(running=False) if len(queue) != 0: nextUp = queue.order_by('_id').first() # Should work through queue by FIFO del queue else: return True nextUp.running = True nextUp.save() # Update status to running # Custom Jobs if hasattr(nextUp, 'customYaml') and nextUp.customYaml is not None: try: # Running Test c = Commit(self.checkflow.repo.repo, nextUp.commitSHA) self.checkflow.repo._testCommit(c, nextUp, plotting=False) # reset to previous state self.checkflow.repo.repo.head.reset(self.checkflow.repo.initialHead, index=True, working_tree=True) nextUp.status = "completed" nextUp.save() nextUp.delete() # Bit unnecessary to change status earlier, but hey except Exception as exc: nextUp.status = str(exc) nextUp.save() else: try: self.checkflow.auth.updateInstallID(nextUp.installID) if self.checkflow.runCheck(nextUp): # Run perf measurements if nextUp.compareUrl is not None: self.checkflow.comparePerformance(nextUp) # Run comparison nextUp.status = "completed" nextUp.save() nextUp.delete() # Bit unnecessary to change status earlier, but hey except Exception as exc: nextUp.status = str(exc) nextUp.save() # Recursion to check for remaining queue if self.checkQueue(): print('Queue is done')
def submitCallback(button, jobname, SHAs, yamlSelect, yamlUploadFileName, yamlUploadContent, yamlExisting, checkSelect, checkUploadFileName, checkUploadContent, checkExisting, loginData): print('\n[CALLBACK] Submitting custom job') submitResponse = 'Submit Status:\n' if button == 0: return '' # Double Check log-in data. Button shouldn't even be visible if no user is logged in userValid, userMessage = reCheckUserCred(loginData) if not userValid: return userMessage # Check if jobname exists in db or is empty if jobname is None: return submitResponse + 'EMPTY JOB NAME' existing_jobnames = QueueObject.objects.distinct('job') if jobname in existing_jobnames: return submitResponse + 'JOB NAME ALREADY EXISTS' else: submitResponse += f'Job Name:\t{jobname}\n' # Check if Git SHAs are valid check_SHAs = [] if SHAs is not None: for line in SHAs.splitlines(): match = bool(re.match('[a-fA-F0-9]{40}$', line)) if match: check_SHAs.append(line) else: return submitResponse + 'BAD SHA' else: return submitResponse + 'MISSING SHAs' # Existing YAML if yamlSelect == 'existing': if yamlExisting is not None: usedSetup = Setup.objects.get(yamlHash=yamlExisting) submitResponse += f'Yaml: {usedSetup.name}\n' else: return submitResponse + 'SELECT YAML' # Check yaml file if valid and if already uploaded via hash elif yamlSelect == 'uploaded': newSetup = Setup() newSetup.name = yamlUploadFileName decoded_yaml = base64.b64decode(yamlUploadContent.split(';base64,')[1].encode('utf-8')).decode('utf-8') # TODO: Strip white space before hashing / order lines yamlHash = hashlib.sha256(decoded_yaml.encode('utf-8')).hexdigest() newSetup.yamlHash = yamlHash existing_hashes = Setup.objects.distinct('yamlHash') if yamlHash in existing_hashes: del newSetup # TODO: Just select the corresponding setup return submitResponse + 'Trying to upload existing yaml. Please select from list instead of re-upload.' else: usedSetup = newSetup newSetup.active = False newSetup.uploadDate = datetime.utcnow() newSetup.yaml = decoded_yaml newSetup.save() # This can lead to bad user experience if checkpoint upload fails submitResponse += f'Uploaded YAML: {yamlUploadFileName}' else: return 'BAD YAML SELECTION' # TODO: Check if checkpoint file is set / valid / uploaded if checkSelect == 'noCheckPoint': submitResponse += 'No Checkpoint selected\n' usedCheckpoint = None elif checkSelect == 'existing': if checkExisting is not None: usedCheckpoint = Checkpoint.objects.get(vtk_hash=checkExisting) submitResponse += f'Checkpoint: {usedCheckpoint.name}\n' else: return submitResponse + 'SELECT CHECKPOINT or choose No Checkpoint' elif checkSelect == 'uploaded': newCheckpoint = Checkpoint() newCheckpoint.name = checkUploadFileName decoded_checkpoint = base64.b64decode(checkUploadContent.split(';base64,')[1].encode('utf-8')).decode('utf-8') checkpointHash = hashlib.sha256(decoded_checkpoint.encode('utf-8')).hexdigest() newCheckpoint.vtk_hash = checkpointHash newCheckpoint.vtk.put(decoded_checkpoint.encode('utf-8')) existing_check_hashes = Checkpoint.objects.distinct('vtk_hash') if checkpointHash in existing_check_hashes: del newCheckpoint return submitResponse + 'Trying to upload existing Checkpoint. Please select from list instead of re-upload.' else: usedCheckpoint = newCheckpoint newCheckpoint.active = False newCheckpoint.uploadDate = datetime.utcnow() newCheckpoint.save() submitResponse += f"Uploaded Checkpoint: {checkUploadFileName}" else: return 'BAD CHECKPOINT SELECTION' # TODO: Kill setup if checkpoint fails for sha in check_SHAs: q = QueueObject() q.commitSHA = sha q.job = jobname q.customYaml = usedSetup if usedCheckpoint is not None: q.customCheckpoint = usedCheckpoint q.jobuser = loginData['user'] q.running = False try: q.save() except (me.NotUniqueError, DuplicateKeyError): submitResponse += 'Jobs partly submitted, tried to submit same SHA/Jobname combination' try: spawnWorker() except Exception as e: return f'{submitResponse} \n Job submitted to queue, but failed to launch worker with {e}' return submitResponse
def _checkCommits(self, url): """ Gets list of pull request commits and runs checks :param url: url to receive commits from :return: if worker is needed """ self.baseSHA = self._getBranchHead(f'origin/{self.base}') compareSHAs = {'0_BaseSHA': self.baseSHA} # Adding Fork Point if available try: forkPoint = self._getForkPoint(baseBranch=f'origin/{self.base}', branchRef=f'origin/{self.branch}') compareSHAs['1_ForkPoint'] = forkPoint except ValueError: print(f'No Forkpoint found for {self.branch} on {self.base}') # Adding Last Common Commit if available try: lastCommon = self._getLastCommonRef( baseRef=f'origin/{self.base}', branchRef=f'origin/{self.branch}') compareSHAs['2_LastCommon'] = lastCommon except ValueError: print(f'No common ancestor between {self.base} and {self.branch}') needWorker = False # if nothing is added to queue, no worker needs to be spawned prSHAs = self._getCommitSHAsFromURL(url) allSHAs = list(compareSHAs.values()) + prSHAs for sha in allSHAs: # CHECKING IF ALREADY TESTED and order by newest shaConfigs = Config.objects(commitSHA=sha).order_by('-id') if shaConfigs.count() == 0: print("NEW COMMIT", sha) queue = QueueObject() queue.commitSHA = sha queue.installID = self.auth.install_id try: queue.save() except me.NotUniqueError: print('SHA is already queued') continue queue.runUrl = self._createCheckRun(sha, "Performance Run") if sha in prSHAs: queue.compareOptions = compareSHAs queue.compareUrl = self._createCheckRun( sha, "Performance Comparison") queue.running = False queue.save() needWorker = True # Switch on worker spawn else: print("Available Tests for SHA", shaConfigs.count()) print("COMMIT ALREADY TESTED", sha) continue return needWorker
check = CheckFlow(initRepo=True) try: bc = check._getBranchHead('origin/master') print(bc) lc = check._getLastCommonRef('637c2e2', 'a6e67a4') print(lc) fc = check._getForkPoint('origin/master', 'a6e67a4') print(fc) except ValueError: pass single_sha = "64a5b092bc32a7b01e19be4091a79148fecb04e7" # check.baseSHA = "cb22dd6e28ad8d4f25b076562e4bf861613b3153" check.baseUrl = "https://api.github.com/repos/AutoPas/AutoPas" check.auth.updateInstallID(2027548) compareUrl = check._createCheckRun(single_sha, "DEBUG TEST") q = QueueObject() q.compareUrl = compareUrl q.commitSHA = single_sha q.installID = 2027548 q.compareOptions = { '0_BaseSHA': '1baed181eaf3e698b8e7061a8ac8d0607844d39f', '1_ForkPoint': '7596386e4c48807003f506daf4938d6135ad6a0a', '2_LastCommont': '7596386e4c48807003f506daf4938d6135ad6a0a' } check.comparePerformance(q) # runUrl = check._createCheckRun(single_sha, "DEBUG TEST") # check.runCheck(single_sha, runUrl)
from mongoDocuments import QueueObject from checks import CheckFlow if __name__ == '__main__': # me.connect('performancedb', host='localhost:30017', username=os.environ['USERNAME'], # password=os.environ['PASSWORD']) q = QueueObject() c = CheckFlow(initRepo=False) c.auth.updateInstallID(2027548) c.baseUrl = "https://api.github.com/repos/AutoPas/AutoPas" testSHA = '5c489e1630fb5091b23a40452133223cbf333aea' # TODO: Add mode without GitHub interaction and manual DB auth entry runUrl = c._createCheckRun(testSHA, 'MANUAL TEST RUN') q.runUrl = runUrl q.commitSHA = testSHA q.installID = 2027548 q.running = False q.save()
from mongoDocuments import QueueObject from checks import CheckFlow import time if __name__ == '__main__': testSHA = "1baed181eaf3e698b8e7061a8ac8d0607844d39f" compareSHA = 'a3193c3dfc47afd976b1e1061bddb579b04c7ab9' c = CheckFlow(initRepo=False) c.baseUrl = "https://api.github.com/repos/AutoPas/AutoPas" c.auth.updateInstallID(2027548) compareUrl = c._createCheckRun(testSHA, f"MANUAL COMPARE {time.asctime()}") q = QueueObject() q.compareUrl = compareUrl q.commitSHA = testSHA q.installID = 2027548 q.compareOptions = {'0_BaseSHA': compareSHA} c.comparePerformance(q)