class ParticipantHandler(object): """Participant class as defined by the SkyNET API.""" def __init__(self): self.oscrc = None self.obs = None def handle_wi_control(self, ctrl): """Job control thread.""" pass def handle_lifecycle_control(self, ctrl): """Participant control thread.""" if ctrl.message == "start": if ctrl.config.has_option("obs", "oscrc"): self.oscrc = ctrl.config.get("obs", "oscrc") def setup_obs(self, namespace): """Setup the Buildservice instance Using namespace as an alias to the apiurl. """ self.obs = BuildService(oscrc=self.oscrc, apiurl=namespace) def build_results(self, wid): """Main function to get new failures related to a build trial.""" wid.result = False if not wid.fields.msg: wid.fields.msg = [] if wid.params.project: prj = wid.params.project else: prj = wid.fields.project if wid.params.packages: pkgs = wid.params.package else: pkgs = wid.fields.packages or [] if wid.params.exclude_repos: exclude_repos = wid.params.exclude_repos else: exclude_repos = wid.fields.exclude_repos or [] if wid.params.exclude_archs: exclude_archs = wid.params.exclude_archs else: exclude_archs = wid.fields.exclude_archs or [] failures = set() for repo in self.obs.getProjectRepositories(prj): if repo in exclude_repos: continue archs = self.obs.getRepositoryArchs(prj, repo) archs = [arch for arch in archs if arch not in exclude_archs] # Get results results = self.obs.getRepoResults(prj, repo) failures.update(get_failures(results, archs)) #filter results if pkgs: failures = failures & set(pkgs) if len(failures): wid.fields.msg.append("%s failed to"\ " build in %s" % (" ".join(failures), prj)) wid.fields.failures = list(failures) def handle_wi(self, wid): """Actual job thread.""" self.setup_obs(wid.fields.ev.namespace) self.build_results(wid)
class ParticipantHandler(object): """Participant class as defined by the SkyNET API.""" def __init__(self): self.oscrc = None self.obs = None def handle_wi_control(self, ctrl): """Job control thread.""" pass def handle_lifecycle_control(self, ctrl): """Participant control thread.""" if ctrl.message == "start": if ctrl.config.has_option("obs", "oscrc"): self.oscrc = ctrl.config.get("obs", "oscrc") def setup_obs(self, namespace): """Setup the Buildservice instance Using namespace as an alias to the apiurl. """ self.obs = BuildService(oscrc=self.oscrc, apiurl=namespace) def check_trial(self, prj, targets, acts, exc): exclude_repos, exclude_archs = exc new_failures = set() old_failures = set() for target_prj in targets: for target_repo in self.obs.getProjectRepositories(target_prj): if target_repo in exclude_repos: continue archs = self.obs.getRepositoryArchs(target_prj, target_repo) archs = [arch for arch in archs if arch not in exclude_archs] print archs # Get the repository of the build trial which builds against the # required target repo in the target prj #build_in_repo = self.obs.getTargetRepo(build_in_prj, target_prj, # target_repo, archs) # Get trial build results trial_results = self.obs.getRepoResults(prj, target_repo) # Get destination results orig_results = self.obs.getRepoResults(target_prj, target_repo) # compare them and return new failures comparison = get_new_failures(trial_results, orig_results, archs, acts) new_failures.update(comparison[0]) old_failures.update(comparison[1]) return new_failures - old_failures def build_trial_results(self, wid): """Main function to get new failures related to a build trial.""" wid.result = False if not wid.fields.msg: wid.fields.msg = [] exclude_repos = wid.fields.exclude_repos or [] exclude_archs = wid.fields.exclude_archs or [] trial_project = wid.fields.build_trial.project trial_subprjs = wid.fields.build_trial.as_dict().get('subprojects', {}) subtargets = list(itertools.chain.from_iterable(trial_subprjs.values())) actions = [act for act in wid.fields.ev.actions if act["targetproject"] not in subtargets] targets = [act["targetproject"] for act in actions] messages = [] all_fails = [] fails = self.check_trial(trial_project, targets, actions, exc=(exclude_repos, exclude_archs)) if fails: all_fails.extend(fails) wid.fields.msg.append("During the trial build in %s, %s failed to"\ " build" % (trial_project, " ".join(fails))) else: wid.fields.msg.append("Trial build of packages in %s successful" % trial_project) for trial_sub, subtargets in trial_subprjs.items(): subactions = [act for act in wid.fields.ev.actions if act["targetproject"] in subtargets] fails = self.check_trial(trial_sub, subtargets, subactions, exc=(exclude_repos, exclude_archs)) if fails: all_fails.extend(fails) wid.fields.msg.append("During the trial build in %s, %s failed to build" % (trial_sub, " ".join(fails))) else: wid.fields.msg.append("Trial build of packages in %s successful" % trial_sub) if all_fails: wid.fields.new_failures = all_fails else: wid.result = True def handle_wi(self, wid): """Actual job thread.""" self.setup_obs(wid.fields.ev.namespace) self.build_trial_results(wid)
class ParticipantHandler(object): """Participant class as defined by the SkyNET API.""" def __init__(self): self.oscrc = None self.obs = None def handle_wi_control(self, ctrl): """Job control thread.""" pass def handle_lifecycle_control(self, ctrl): """Participant control thread.""" if ctrl.message == "start": if ctrl.config.has_option("obs", "oscrc"): self.oscrc = ctrl.config.get("obs", "oscrc") def setup_obs(self, namespace): """Setup the Buildservice instance Using namespace as an alias to the apiurl. """ self.obs = BuildService(oscrc=self.oscrc, apiurl=namespace) def build_trial_results(self, wid): """Main function to get new failures related to a build trial.""" wid.result = False if not wid.fields.msg: wid.fields.msg = [] target_prj = wid.fields.project build_in_prj = wid.params.build_in exclude_repos = wid.fields.exclude_repos or [] exclude_archs = wid.fields.exclude_archs or [] new_failures = set() for target_repo in self.obs.getProjectRepositories(target_prj): if target_repo in exclude_repos: continue archs = self.obs.getRepositoryArchs(target_prj, target_repo) archs = [arch for arch in archs if arch not in exclude_archs] # Get the repository of the build trial which builds against the # required target repo in the target prj build_in_repo = self.obs.getTargetRepo(build_in_prj, target_prj, target_repo, archs) # Get trial build results trial_results = self.obs.getRepoResults(build_in_prj, build_in_repo) # Get destination results orig_results = self.obs.getRepoResults(target_prj, target_repo) # compare them and return new failures new_failures.update(get_new_failures(trial_results, orig_results, archs)) if len(new_failures): wid.fields.msg.append("During the trial build in %s, %s failed to"\ " build for one of the archs : %s" % (build_in_prj, " ".join(new_failures), " ".join(archs))) wid.fields.new_failures = list(new_failures) else: wid.fields.msg.append("Trial build of packages in %s successful" % build_in_prj) wid.result = True def handle_wi(self, wid): """Actual job thread.""" self.setup_obs(wid.fields.ev.namespace) self.build_trial_results(wid)