Skip to content

Commit

Permalink
Merge pull request #1432 from jberry-suse/stagingapi-lazy-load-all
Browse files Browse the repository at this point in the history
osclib/staging-api: lazy-load all config values to allow for placement in remote config.
  • Loading branch information
jberry-suse committed Mar 8, 2018
2 parents 17ebaaa + e450a15 commit 568be98
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 26 deletions.
14 changes: 7 additions & 7 deletions osclib/accept_command.py
Expand Up @@ -48,7 +48,7 @@ def virtual_accept_request_has_no_binary(self, project, package):
return True

def find_virtually_accepted_requests(self, project):
query = "match=state/@name='review'+and+(action/target/@project='{}'+and+action/@type='delete')+and+(review/@state='new'+and+review/@by_group='{}')".format(project, self.api.delreq_review)
query = "match=state/@name='review'+and+(action/target/@project='{}'+and+action/@type='delete')+and+(review/@state='new'+and+review/@by_group='{}')".format(project, self.api.cdelreq_review)
url = self.api.makeurl(['search', 'request'], query)

f = http_GET(url)
Expand Down Expand Up @@ -86,7 +86,7 @@ def reset_rebuild_data(self, project):
http_PUT(url + '?comment=accept+command+update', data=content)

def virtually_accept_delete(self, request_id, package):
self.api.add_review(request_id, by_group=self.api.delreq_review, msg='Request accepted. Cleanup in progress - DO NOT REVOKE!')
self.api.add_review(request_id, by_group=self.api.cdelreq_review, msg='Request accepted. Cleanup in progress - DO NOT REVOKE!')

filelist = self.api.get_filelist_for_package(pkgname=package, project=self.api.project, expand='1', extension='spec')
pkgs = self.api.extract_specfile_short(filelist)
Expand All @@ -97,7 +97,7 @@ def virtually_accept_delete(self, request_id, package):
meta = ''.join(meta)
# Update package meta to disable build
self.api.create_package_container(self.api.project, pkg, meta=meta, disable_build=True)
wipebinaries(self.api.apiurl, self.api.project, package=pkg, repo=self.api.main_repo)
wipebinaries(self.api.apiurl, self.api.project, package=pkg, repo=self.api.cmain_repo)

# Remove package from Rings
if self.api.ring_packages.get(pkg):
Expand Down Expand Up @@ -129,7 +129,7 @@ def perform(self, project, force=False):
oldspecs = self.api.get_filelist_for_package(pkgname=req['package'],
project=self.api.project,
extension='spec')
if 'type' in req and req['type'] == 'delete' and self.api.delreq_review:
if 'type' in req and req['type'] == 'delete' and self.api.cdelreq_review:
msg += ' and started handling of virtual accept process'
print(msg)
# Virtually accept the delete request
Expand All @@ -154,7 +154,7 @@ def cleanup(self, project):
return False

pkglist = self.api.list_packages(project)
clean_list = set(pkglist) - set(self.api.cstaging_nocleanup)
clean_list = set(pkglist) - set(self.api.cnocleanup_packages)

for package in clean_list:
print "[cleanup] deleted %s/%s" % (project, package)
Expand Down Expand Up @@ -189,13 +189,13 @@ def cleanup(self, project):
def accept_other_new(self):
changed = False

if self.api.delreq_review:
if self.api.cdelreq_review:
rqlist = self.find_virtually_accepted_requests(self.api.project)
for req in rqlist:
if self.virtual_accept_request_has_no_binary(self.api.project, req['packages'][0]):
# Accepting delreq-review review
self.api.do_change_review_state(req['id'], 'accepted',
by_group=self.api.delreq_review,
by_group=self.api.cdelreq_review,
message='Virtually accepted delete {}'.format(req['packages'][0]))

rqlist = self.find_new_requests(self.api.project)
Expand Down
36 changes: 17 additions & 19 deletions osclib/stagingapi.py
Expand Up @@ -67,19 +67,7 @@ def __init__(self, apiurl, project):
self.project = project

# Store some prefix / data used in the code.
self.cstaging = conf.config[project]['staging']
self.cstaging_group = conf.config[project]['staging-group']
self.cstaging_archs = conf.config[project]['staging-archs'].split()
self.cstaging_dvd_archs = conf.config[project]['staging-dvd-archs'].split()
self._cstaging_nocleanup = None
self.crings = conf.config[project]['rings']
self.cnonfree = conf.config[project]['nonfree']
self.crebuild = conf.config[project]['rebuild']
self.cproduct = conf.config[project]['product']
self.copenqa = conf.config[project]['openqa']
self.user = conf.get_apiurl_usr(apiurl)
self.delreq_review = conf.config[project]['delreq-review']
self.main_repo = conf.config[project]['main-repo']
self._ring_packages = None
self._ring_packages_for_links = None
self._packages_staged = None
Expand All @@ -99,13 +87,23 @@ def __init__(self, apiurl, project):

Cache.init()

@property
def cstaging_nocleanup(self):
"""Lazy-load value to allow for placement in remote config."""
if self._cstaging_nocleanup is None:
self._cstaging_nocleanup = conf.config[self.project]['nocleanup-packages'].split()
def __getattr__(self, attr):
"""Lazy-load all config values to allow for placement in remote config."""
if attr.startswith('c'):
# Drop 'c' prefix and change to config key format.
key = attr[1:].replace('_', '-')

# This will intentionally cause error if key does not exists.
value = conf.config[self.project][key]
if key.endswith('archs') or key == 'nocleanup-packages':
value = value.split()

# This code will only be called for the first access.
setattr(self, attr, value)
return value

return self._cstaging_nocleanup
# Raise AttributeError like normal.
return self.__getattribute__(attr)

@property
def ring_packages(self):
Expand Down Expand Up @@ -1285,7 +1283,7 @@ def ensure_staging_archs(self, project):
url = self.makeurl(['source', project, '_meta'])
meta = ET.parse(http_GET(url))

repository = meta.find('repository[@name="{}"]'.format(self.main_repo))
repository = meta.find('repository[@name="{}"]'.format(self.cmain_repo))
changed = False
for arch in self.cstaging_archs:
if not repository.xpath('./arch[text()="{}"]'.format(arch)):
Expand Down

0 comments on commit 568be98

Please sign in to comment.