centos-sig lookaside cache support

This commit is contained in:
Leonardo Rossetti 2022-04-05 13:53:42 -03:00
parent cb72cfd724
commit f5ba2652d9
5 changed files with 43 additions and 8 deletions

0
src/bin/centpkg-sig Normal file → Executable file
View file

View file

@ -1,7 +1,10 @@
[centpkg-sig] [centpkg-sig]
lookaside = https://git.centos.org/sources lookaside = https://git.centos.org/sources
lookasidehash = sha512 lookasidehash = sha512
lookaside_cgi = https://git.centos.org/sources/upload.cgi lookaside_cgi = https://git.centos.org/sources/upload_sig.cgi
# lookaside_cgi = https://git.centos.org/sources/upload.cgi
lookaside_structure = hash
# lookaside_structure = branch
distgit_namespaced = True distgit_namespaced = True
distgit_namespaces = rpms distgit_namespaces = rpms
gitbaseurl = ssh://git@git.centos.org/%(repo)s.git gitbaseurl = ssh://git@git.centos.org/%(repo)s.git

View file

@ -151,6 +151,11 @@ class Commands(Commands):
# should only be used when configured for SHA512 # should only be used when configured for SHA512
self.source_entry_type = 'bsd' if self.lookasidehash != 'md5' else 'old' self.source_entry_type = 'bsd' if self.lookasidehash != 'md5' else 'old'
self.branchre = 'c\d{1,}(s)?(tream)?|master' self.branchre = 'c\d{1,}(s)?(tream)?|master'
self.lookaside_structure = None
def update(self, config):
if self.lookaside_structure is None:
self.lookaside_structure = config.get('lookaside_structure', 'hash')
@property @property
def distgitdir(self): def distgitdir(self):
@ -168,7 +173,8 @@ class Commands(Commands):
self.lookaside, self.lookaside,
self.lookaside_cgi, self.lookaside_cgi,
self.repo_name, self.repo_name,
self.branch_merge) self.branch_merge,
structure=self.lookaside_structure)
# redefined loaders # redefined loaders
def load_rpmdefines(self): def load_rpmdefines(self):

View file

@ -35,6 +35,11 @@ class centpkgClient(cliClient):
self.setup_centos_subparsers() self.setup_centos_subparsers()
def load_cmd(self):
super(centpkgClient, self).load_cmd()
cfg = self.config[self.get_name()]
self._cmd.update(cfg)
def setup_centos_subparsers(self): def setup_centos_subparsers(self):
self.register_do_fork() self.register_do_fork()
self.register_request_gated_side_tag() self.register_request_gated_side_tag()

View file

@ -94,7 +94,7 @@ class StreamLookasideCache(CGILookasideCache):
return super(StreamLookasideCache, self).remote_file_exists( return super(StreamLookasideCache, self).remote_file_exists(
_name, filename, hashstr) _name, filename, hashstr)
def upload(self, name, filename, hashstr, offline=False): def upload(self, name, filename, hashstr, offline=False, **kwargs):
""" """
Uploads a file to lookaside cache. Uploads a file to lookaside cache.
@ -169,13 +169,32 @@ class StreamLookasideCache(CGILookasideCache):
class SIGLookasideCache(CGILookasideCache): class SIGLookasideCache(CGILookasideCache):
def __init__(self, hashtype, download_url, upload_url, name, branch): def __init__(self, hashtype, download_url, upload_url, name, branch, structure='hash'):
super(SIGLookasideCache, self).__init__( super(SIGLookasideCache, self).__init__(
hashtype, download_url, upload_url, client_cert="/home/bstinson/.centos.cert") hashtype, download_url, upload_url, client_cert="/home/bstinson/.centos.cert")
self.name = name
self.branch = branch self.branch = branch
self.structure = structure
self.download_path = ( @property
'%(name)s/%(branch)s/%(hash)s') def download_path(self):
if self.structure == 'hash':
return '%(name)s/%(filename)s/%(hashtype)s/%(hash)s'
return '%(name)s/%(branch)s/%(hash)s'
def get_download_url(self, name, filename, hash, hashtype=None, **kwargs):
if self.structure == 'hash':
path_dict = {
'name': name,
'filename': filename,
'hash': hash,
'hashtype': hashtype
}
path = self.download_path % path_dict
return os.path.join(self.download_url, path)
return super(SIGLookasideCache, self).get_download_url(name, filename, hash, hashtype, **kwargs)
def remote_file_exists(self, name, filename, hash): def remote_file_exists(self, name, filename, hash):
"""Verify whether a file exists on the lookaside cache """Verify whether a file exists on the lookaside cache
@ -201,8 +220,9 @@ class SIGLookasideCache(CGILookasideCache):
post_data = [('name', _name), post_data = [('name', _name),
('%ssum' % self.hashtype, hash), ('%ssum' % self.hashtype, hash),
('branch', self.branch),
('filename', filename)] ('filename', filename)]
if self.structure == 'branch':
post_data.append(('branch', self.branch))
with io.BytesIO() as buf: with io.BytesIO() as buf:
c = pycurl.Curl() c = pycurl.Curl()
@ -279,8 +299,9 @@ class SIGLookasideCache(CGILookasideCache):
self.log.info("Uploading: %s", filepath) self.log.info("Uploading: %s", filepath)
post_data = [('name', name), post_data = [('name', name),
('%ssum' % self.hashtype, hash), ('%ssum' % self.hashtype, hash),
('branch', self.branch),
('file', (pycurl.FORM_FILE, filepath))] ('file', (pycurl.FORM_FILE, filepath))]
if self.structure == 'branch':
post_data.append(('branch', self.branch))
with io.BytesIO() as buf: with io.BytesIO() as buf:
c = pycurl.Curl() c = pycurl.Curl()