forked from openSUSE/openSUSE-release-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstaging-installcheck.py
More file actions
executable file
·168 lines (140 loc) · 6.82 KB
/
Copy pathstaging-installcheck.py
File metadata and controls
executable file
·168 lines (140 loc) · 6.82 KB
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#!/usr/bin/python3
import argparse
import logging
import os
import sys
from urllib.error import HTTPError
import osc.core
from lxml import etree as ET
from osclib.conf import Config
from osclib.stagingapi import StagingAPI
from staginginstallchecker.installchecker import InstallChecker
SCRIPT_PATH = os.path.dirname(os.path.realpath(__file__))
class OBSInstallChecker(InstallChecker):
def staging(self, project, repository, force=False, devel=False):
# fetch the build ids at the beginning - mirroring takes a while
buildids = {}
try:
architectures = self.target_archs(project, repository)
except HTTPError as e:
if e.code == 404:
# adi disappear all the time, so don't worry
return False
raise e
all_done = True
for arch in architectures:
pra = f'{project}/{repository}/{arch}'
buildid = self.buildid(project, repository, arch)
if not buildid:
self.logger.error(f'No build ID in {pra}')
return False
buildids[arch] = buildid
url = self.report_url(project, repository, arch, buildid)
try:
root = ET.parse(osc.core.http_GET(url)).getroot()
check = root.find('check[@name="installcheck"]/state')
if check is not None and check.text != 'pending':
self.logger.info(f'{pra} already "{check.text}", ignoring')
else:
all_done = False
except HTTPError:
self.logger.info(f'{pra} has no status report')
all_done = False
if all_done and not force:
return True
result = self.staging_installcheck(project, repository, architectures, devel=devel)
if not devel:
if result.success:
self.report_state('success', self.gocd_url(), project, repository, buildids)
else:
result.comment.insert(0, f'Generated from {self.gocd_url()}\n')
self.report_state('failure', self.upload_failure(project, result.comment), project, repository, buildids)
self.logger.warning(f'Not accepting {project}')
return result.success
def upload_failure(self, project, comment):
print(project, '\n'.join(comment))
url = self.api.makeurl(['source', 'home:repo-checker', 'reports', project])
osc.core.http_PUT(url, data='\n'.join(comment))
url = self.api.apiurl.replace('api.', 'build.')
return f'{url}/package/view_file/home:repo-checker/reports/{project}'
def report_state(self, state, report_url, project, repository, buildids):
architectures = self.target_archs(project, repository)
for arch in architectures:
self.report_pipeline(state, report_url, project, repository, arch, buildids[arch])
def gocd_url(self):
if not os.environ.get('GO_SERVER_URL'):
# placeholder :)
return 'http://stephan.kulow.org/'
report_url = os.environ.get('GO_SERVER_URL').replace(':8154', '')
return report_url + '/tab/build/detail/{}/{}/{}/{}/{}#tab-console'.format(os.environ.get('GO_PIPELINE_NAME'),
os.environ.get('GO_PIPELINE_COUNTER'),
os.environ.get('GO_STAGE_NAME'),
os.environ.get('GO_STAGE_COUNTER'),
os.environ.get('GO_JOB_NAME'))
def buildid(self, project, repository, architecture):
url = self.api.makeurl(['build', project, repository, architecture], {'view': 'status'})
root = ET.parse(osc.core.http_GET(url)).getroot()
buildid = root.find('buildid')
if buildid is None:
return False
return buildid.text
def report_url(self, project, repository, architecture, buildid):
return self.api.makeurl(['status_reports', 'built', project,
repository, architecture, 'reports', buildid])
def report_pipeline(self, state, report_url, project, repository, architecture, buildid):
url = self.report_url(project, repository, architecture, buildid)
name = 'installcheck'
xml = self.check_xml(report_url, state, name)
try:
osc.core.http_POST(url, data=xml)
except HTTPError:
print('failed to post status to ' + url)
sys.exit(1)
def check_xml(self, url, state, name):
check = ET.Element('check')
if url:
se = ET.SubElement(check, 'url')
se.text = url
se = ET.SubElement(check, 'state')
se.text = state
se = ET.SubElement(check, 'name')
se.text = name
return ET.tostring(check)
if __name__ == '__main__':
parser = argparse.ArgumentParser(
description='Do an installcheck on staging project')
parser.add_argument('-s', '--staging', type=str, default=None,
help='staging project')
parser.add_argument('--devel', type=str, default=None,
help='devel project (ex GNOME:Factory)')
parser.add_argument('-r', '--repository', type=str, default=None,
help='repository to check, if not specified, use the staging configuration')
parser.add_argument('-p', '--project', type=str, default='openSUSE:Factory',
help='project to check (ex. openSUSE:Factory, openSUSE:Leap:15.1)')
parser.add_argument('-d', '--debug', action='store_true', default=False,
help='enable debug information')
parser.add_argument('-A', '--apiurl', metavar='URL', help='API URL')
args = parser.parse_args()
osc.conf.get_config(override_apiurl=args.apiurl)
osc.conf.config['debug'] = args.debug
apiurl = osc.conf.config['apiurl']
config = Config.get(apiurl, args.project)
api = StagingAPI(apiurl, args.project)
if not args.repository:
args.repository = api.cmain_repo
staging_report = OBSInstallChecker(api, config)
if args.debug:
logging.basicConfig(level=logging.DEBUG)
else:
logging.basicConfig(level=logging.INFO)
if args.staging:
if not staging_report.staging(api.prj_from_short(args.staging), repository=args.repository, force=True):
sys.exit(1)
elif args.devel:
if not staging_report.staging(args.devel, repository=args.repository, force=True, devel=True):
sys.exit(1)
else:
for staging in api.get_staging_projects():
if api.is_adi_project(staging):
staging_report.staging(staging, repository=args.repository)
sys.exit(0)