Gentoo Archives: gentoo-commits

From: Magnus Granberg <zorry@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/tinderbox-cluster:master commit in: buildbot_gentoo_ci/config/, buildbot_gentoo_ci/steps/
Date: Tue, 18 May 2021 09:14:19
Message-Id: 1621329239.cdbe9295f945bd4f40db2333e016c075e2c64784.zorry@gentoo
1 commit: cdbe9295f945bd4f40db2333e016c075e2c64784
2 Author: Magnus Granberg <zorry <AT> gentoo <DOT> org>
3 AuthorDate: Tue May 18 09:13:59 2021 +0000
4 Commit: Magnus Granberg <zorry <AT> gentoo <DOT> org>
5 CommitDate: Tue May 18 09:13:59 2021 +0000
6 URL: https://gitweb.gentoo.org/proj/tinderbox-cluster.git/commit/?id=cdbe9295
7
8 Add support to push log to Minio
9
10 Signed-off-by: Magnus Granberg <zorry <AT> gentoo.org>
11
12 buildbot_gentoo_ci/config/buildfactorys.py | 2 +-
13 buildbot_gentoo_ci/steps/logs.py | 28 ++++++++++++++
14 buildbot_gentoo_ci/steps/minio.py | 60 ++++++++++++++++++++++++++++++
15 3 files changed, 89 insertions(+), 1 deletion(-)
16
17 diff --git a/buildbot_gentoo_ci/config/buildfactorys.py b/buildbot_gentoo_ci/config/buildfactorys.py
18 index 417e385..d2e195c 100644
19 --- a/buildbot_gentoo_ci/config/buildfactorys.py
20 +++ b/buildbot_gentoo_ci/config/buildfactorys.py
21 @@ -171,7 +171,7 @@ def parse_build_log():
22 # pers the log from pkg check
23 #f.addStep(logs.ParserPkgCheckLog())
24 # Upload the log to the cloud and remove the log
25 - #f.addStep(logs.Upload())
26 + f.addStep(logs.Upload())
27 # check the sum log if we need to make a issue/bug/pr report
28 # set it SUCCESS/FAILURE/WARNINGS
29 f.addStep(logs.MakeIssue())
30
31 diff --git a/buildbot_gentoo_ci/steps/logs.py b/buildbot_gentoo_ci/steps/logs.py
32 index 3c0ef8d..d69c447 100644
33 --- a/buildbot_gentoo_ci/steps/logs.py
34 +++ b/buildbot_gentoo_ci/steps/logs.py
35 @@ -18,6 +18,8 @@ from buildbot.process.results import FAILURE
36 from buildbot.process.results import WARNINGS
37 from buildbot.plugins import steps
38
39 +from buildbot_gentoo_ci.steps import minio
40 +
41 class SetupPropertys(BuildStep):
42
43 name = 'SetupPropertys'
44 @@ -277,6 +279,32 @@ class setEmergeInfoLog(BuildStep):
45 yield log.addStdout(line + '\n')
46 return SUCCESS
47
48 +class Upload(BuildStep):
49 +
50 + name = 'Upload'
51 + description = 'Running'
52 + descriptionDone = 'Ran'
53 + descriptionSuffix = None
54 + haltOnFailure = False
55 + flunkOnFailure = True
56 + warnOnWarnings = True
57 +
58 + def __init__(self, **kwargs):
59 + super().__init__(**kwargs)
60 +
61 + @defer.inlineCallbacks
62 + def run(self):
63 + if self.getProperty('faild_cpv'):
64 + log_cpv = self.getProperty('log_build_data')[self.getProperty('faild_cpv')]
65 + else:
66 + log_cpv = self.getProperty('log_build_data')[self.getProperty('cpv')]
67 + bucket = self.getProperty('project_data')['uuid'] + '-' + 'logs'
68 + file_path = yield os.path.join(self.master.basedir, 'cpv_logs', log_cpv['full_logname'])
69 + aftersteps_list = []
70 + aftersteps_list.append(minio.putFileToMinio(file_path, log_cpv['full_logname'], bucket))
71 + yield self.build.addStepsAfterCurrentStep(aftersteps_list)
72 + return SUCCESS
73 +
74 class setBuildStatus(BuildStep):
75
76 name = 'setBuildStatus'
77
78 diff --git a/buildbot_gentoo_ci/steps/minio.py b/buildbot_gentoo_ci/steps/minio.py
79 new file mode 100644
80 index 0000000..ac9ac3d
81 --- /dev/null
82 +++ b/buildbot_gentoo_ci/steps/minio.py
83 @@ -0,0 +1,60 @@
84 +# Copyright 2021 Gentoo Authors
85 +# Distributed under the terms of the GNU General Public License v2
86 +
87 +from minio import Minio
88 +from minio.error import ResponseError, BucketAlreadyOwnedByYou, BucketAlreadyExists
89 +
90 +from twisted.internet import defer
91 +from twisted.python import log
92 +
93 +from buildbot.process.buildstep import BuildStep
94 +from buildbot.process.results import SUCCESS
95 +from buildbot.process.results import FAILURE
96 +
97 +#FIXME:
98 +# get url, user from config
99 +# get password from secret
100 +url = ''
101 +user = ''
102 +password = ''
103 +
104 +class putFileToMinio(BuildStep):
105 +
106 + name = 'putFileToMinio'
107 + description = 'Running'
108 + descriptionDone = 'Ran'
109 + descriptionSuffix = None
110 + haltOnFailure = False
111 + flunkOnFailure = True
112 + warnOnWarnings = True
113 +
114 + def __init__(self, filename, target, bucket, **kwargs):
115 + self.filename = filename
116 + self.bucket = bucket
117 + self.target = target
118 + super().__init__(**kwargs)
119 +
120 + def getMinioConnect(self, url, user, password):
121 + minioclient = Minio(
122 + url,
123 + access_key = user,
124 + secret_key = password,
125 + secure = False
126 + )
127 + return minioclient
128 +
129 + @defer.inlineCallbacks
130 + def pushFileToMinio(self):
131 + try:
132 + yield self.minio_connect.fput_object(self.bucket, self.target, self.filename)
133 + except ResponseError as err:
134 + print(err)
135 + return FAILURE
136 + return True
137 +
138 + @defer.inlineCallbacks
139 + def run(self):
140 + self.gentooci = self.master.namedServices['services'].namedServices['gentooci']
141 + self.minio_connect = yield self.getMinioConnect(url, user, password)
142 + success = yield self.pushFileToMinio()
143 + return SUCCESS