diff options
Diffstat (limited to 'buildbot_gentoo_ci/steps/clean.py')
-rw-r--r-- | buildbot_gentoo_ci/steps/clean.py | 70 |
1 files changed, 49 insertions, 21 deletions
diff --git a/buildbot_gentoo_ci/steps/clean.py b/buildbot_gentoo_ci/steps/clean.py index 73733f1..e4d8573 100644 --- a/buildbot_gentoo_ci/steps/clean.py +++ b/buildbot_gentoo_ci/steps/clean.py @@ -31,6 +31,7 @@ class SetupPropertys(BuildStep): days = 30 days_in_s = 86400 * days now = int(self.master.reactor.seconds()) + bb_build_ids = [] for ebuild_data in deleted_ebuilds_data: no_bug = True # check if older the days @@ -41,13 +42,20 @@ class SetupPropertys(BuildStep): print(build_data_list) for build_data in build_data_list: if build_data['bug_id'] == 0: - # get buildsets print(f"Build : {build_data['id']} will be removed") - yield self.build.addStepsAfterCurrentStep([RemoveBuildFromDb(build_data)]) + if build_data['buildbot_build_id'] != 0: + bb_build_ids.append(build_data['buildbot_build_id']) + # make a list with build_ids from parent_buildid + # get parent_buildid from buildsets + # bb_buildset = yield self.master.db.buildsets.getBuildset(build_data['buildbot_build_id']) + yield self.gentooci.db.builds.removeBuild(build_data['id']) else: no_bug = False if no_bug: - yield self.build. addStepsAfterLastStep([RemoveEbuildFromDb(ebuild_data)]) + yield self.build.addStepsAfterCurrentStep([RemoveEbuildFromDb(ebuild_data['uuid'])]) + yield self.build.addStepsAfterCurrentStep([RemoveChangesFromDb(ebuild_data['commit_id'])]) + for bb_build_id in bb_build_ids: + yield self.build.addStepsAfterCurrentStep([RemoveBuildFromDb(bb_build_id)]) return SUCCESS class RemoveEbuildFromDb(BuildStep): @@ -57,17 +65,34 @@ class RemoveEbuildFromDb(BuildStep): haltOnFailure = True flunkOnFailure = True - def __init__(self, ebuild_data, **kwargs): - self.ebuild_data = ebuild_data + def __init__(self, uuid, **kwargs): + self.uuid = uuid super().__init__(**kwargs) @defer.inlineCallbacks def run(self): self.gentooci = self.master.namedServices['services'].namedServices['gentooci'] - yield self.gentooci.db.versions.removeVersionKeyword(self.ebuild_data['uuid']) - yield self.gentooci.db.versions.removeVersionMetadata(self.ebuild_data['uuid']) - yield self.gentooci.db.versions.removeVersion(self.ebuild_data['uuid']) - self.descriptionDone = f"Ebuild : {self.ebuild_data['uuid']} will be removed" + yield self.gentooci.db.versions.removeVersionKeyword(self.uuid) + yield self.gentooci.db.versions.removeVersionMetadata(self.uuid) + yield self.gentooci.db.versions.removeVersion(self.uuid) + self.descriptionDone = f"Ebuild : {self.uuid} will be removed" + return SUCCESS + +class RemoveChangesFromDb(BuildStep): + name = 'Clean Changes from db' + description = 'Running' + descriptionSuffix = None + haltOnFailure = True + flunkOnFailure = True + + def __init__(self, commit_id, **kwargs): + self.commit_id = commit_id + super().__init__(**kwargs) + + @defer.inlineCallbacks + def run(self): + yield self.master.db.changes.pruneChangesId(self.commit_id) + self.descriptionDone = f"Change : {self.commit_id} will be removed" return SUCCESS class RemoveBuildFromDb(BuildStep): @@ -77,21 +102,24 @@ class RemoveBuildFromDb(BuildStep): haltOnFailure = True flunkOnFailure = True - def __init__(self, build_data, **kwargs): - self.build_data = build_data + def __init__(self, build_id, **kwargs): + self.build_id = build_id super().__init__(**kwargs) @defer.inlineCallbacks def run(self): self.gentooci = self.master.namedServices['services'].namedServices['gentooci'] - if self.build_data['buildbot_build_id'] != 0: - self.descriptionDone = f"BuildBot Build : {self.build_data['buildbot_build_id']} will be removed" - bb_build_data = yield self.master.db.builds.getBuild(self.build_data['buildbot_build_id']) - # remove buildbot data on db - # remove steps and logs - yield self.master.db.logs.deleteLogChunks(self.build_data['buildbot_build_id']) - # remove propertys - # get buildsets - # remove build_data - yield self.gentooci.db.builds.removeBuild(self.build_data['id']) + self.descriptionDone = f"BuildBot Build : {self.build_id} will be removed" + bb_build_data = yield self.master.db.builds.getBuild(self.build_id) + # remove steps and logs + yield self.master.db.logs.deleteLogChunks(self.build_id) + # remove propertys + yield self.master.db.builds.pruneBuildProperties(self.build_id) + # remove buildset_sourcestamps + # remove buildrequests/buildrequest_claims + # remove buildsets/buildset_properties + # remove build_data + yield self.master.db.build_data.pruneBuildData(self.build_id) + # remove build + yield self.master.db.builds.pruneBuild(self.build_id) return SUCCESS |