blob: e4d85738be616ce1c8805a66ecbe3becb1fd22ae (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
# Copyright 2023 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
from twisted.internet import defer
from twisted.python import log
from buildbot.process.buildstep import BuildStep
from buildbot.process.results import SUCCESS
from buildbot.process.results import FAILURE
from buildbot.process.results import SKIPPED
from buildbot.plugins import steps, util
class SetupPropertys(BuildStep):
name = 'Setup propertys for clean db'
description = 'Running'
descriptionSuffix = None
haltOnFailure = True
flunkOnFailure = True
def __init__(self, **kwargs):
super().__init__(**kwargs)
@defer.inlineCallbacks
def run(self):
self.gentooci = self.master.namedServices['services'].namedServices['gentooci']
aftersteps_list = []
# Check on deleted ebuild on package
deleted_ebuilds_data = yield self.gentooci.db.versions.getEbuildsByPackage(self.getProperty("package_data")['uuid'], deleted=True)
# check if older then X days
#FIXME: set days in config and move the check to db side
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
if ebuild_data['deleted_at'] < (now - days_in_s):
print(f"Ebuild : {ebuild_data['uuid']} will be removed")
# get build_data for deleted_ebuild_data['uuid']
build_data_list = yield self.gentooci.db.builds.getBuildsByVersionUuid(ebuild_data['uuid'])
print(build_data_list)
for build_data in build_data_list:
if build_data['bug_id'] == 0:
print(f"Build : {build_data['id']} will be removed")
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.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):
name = 'Clean ebuild from db'
description = 'Running'
descriptionSuffix = None
haltOnFailure = True
flunkOnFailure = True
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.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):
name = 'Clean builds from db'
description = 'Running'
descriptionSuffix = None
haltOnFailure = True
flunkOnFailure = True
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']
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
|