class Packager(object):
- def __init__(self, ctx: CephadmContext,
- stable: Optional[str] = None, version: Optional[str] = None,
- branch: Optional[str] = None, commit: Optional[str] = None):
- assert \
- (stable and not version and not branch and not commit) or \
- (not stable and version and not branch and not commit) or \
- (not stable and not version and branch) or \
- (not stable and not version and not branch and not commit)
+ def __init__(
+ self,
+ ctx: CephadmContext,
+ stable: Optional[str] = None,
+ version: Optional[str] = None,
+ branch: Optional[str] = None,
+ commit: Optional[str] = None,
+ ):
+ assert (
+ (stable and not version and not branch and not commit)
+ or (not stable and version and not branch and not commit)
+ or (not stable and not version and branch)
+ or (not stable and not version and not branch and not commit)
+ )
self.ctx = ctx
self.stable = stable
self.version = version
def install_podman(self) -> None:
raise NotImplementedError
- def query_shaman(self, distro: str, distro_version: Any, branch: Optional[str], commit: Optional[str]) -> str:
+ def query_shaman(
+ self,
+ distro: str,
+ distro_version: Any,
+ branch: Optional[str],
+ commit: Optional[str],
+ ) -> str:
# query shaman
arch = platform.uname().machine
logger.info('Fetching repo metadata from shaman and chacra...')
try:
shaman_response = urlopen(shaman_url)
except HTTPError as err:
- logger.error('repository not found in shaman (might not be available yet)')
+ logger.error(
+ 'repository not found in shaman (might not be available yet)'
+ )
raise Error('%s, failed to fetch %s' % (err, shaman_url))
chacra_url = ''
try:
chacra_url = shaman_response.geturl()
chacra_response = urlopen(chacra_url)
except HTTPError as err:
- logger.error('repository not found in chacra (might not be available yet)')
+ logger.error(
+ 'repository not found in chacra (might not be available yet)'
+ )
raise Error('%s, failed to fetch %s' % (err, chacra_url))
return chacra_response.read().decode('utf-8')
'debian': 'debian',
}
- def __init__(self, ctx: CephadmContext,
- stable: Optional[str], version: Optional[str], branch: Optional[str], commit: Optional[str],
- distro: Optional[str], distro_version: Optional[str], distro_codename: Optional[str]) -> None:
- super(Apt, self).__init__(ctx, stable=stable, version=version,
- branch=branch, commit=commit)
+ def __init__(
+ self,
+ ctx: CephadmContext,
+ stable: Optional[str],
+ version: Optional[str],
+ branch: Optional[str],
+ commit: Optional[str],
+ distro: Optional[str],
+ distro_version: Optional[str],
+ distro_codename: Optional[str],
+ ) -> None:
+ super(Apt, self).__init__(
+ ctx, stable=stable, version=version, branch=branch, commit=commit
+ )
assert distro
self.ctx = ctx
self.distro = self.DISTRO_NAMES[distro]
return '/etc/apt/sources.list.d/ceph.list'
def add_repo(self) -> None:
-
url, name = self.repo_gpgkey()
logger.info('Installing repo GPG key from %s...' % url)
try:
response = urlopen(url)
except HTTPError as err:
- logger.error('failed to fetch GPG repo key from %s: %s' % (
- url, err))
+ logger.error(
+ 'failed to fetch GPG repo key from %s: %s' % (url, err)
+ )
raise Error('failed to fetch GPG key')
key = response.read()
with open('/etc/apt/trusted.gpg.d/ceph.%s.gpg' % name, 'wb') as f:
if self.version:
content = 'deb %s/debian-%s/ %s main\n' % (
- self.ctx.repo_url, self.version, self.distro_codename)
+ self.ctx.repo_url,
+ self.version,
+ self.distro_codename,
+ )
elif self.stable:
content = 'deb %s/debian-%s/ %s main\n' % (
- self.ctx.repo_url, self.stable, self.distro_codename)
+ self.ctx.repo_url,
+ self.stable,
+ self.distro_codename,
+ )
else:
- content = self.query_shaman(self.distro, self.distro_codename, self.branch,
- self.commit)
+ content = self.query_shaman(
+ self.distro, self.distro_codename, self.branch, self.commit
+ )
logger.info('Installing repo file at %s...' % self.repo_path())
with open(self.repo_path(), 'w') as f:
self.install(['docker.io'])
def kubic_repo_url(self) -> str:
- return 'https://download.opensuse.org/repositories/devel:/kubic:/' \
- 'libcontainers:/stable/xUbuntu_%s/' % self.distro_version
+ return (
+ 'https://download.opensuse.org/repositories/devel:/kubic:/'
+ 'libcontainers:/stable/xUbuntu_%s/' % self.distro_version
+ )
def kubic_repo_path(self) -> str:
return '/etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list'
try:
response = urlopen(url)
except HTTPError as err:
- logger.error('failed to fetch GPG repo key from %s: %s' % (
- url, err))
+ logger.error(
+ 'failed to fetch GPG repo key from %s: %s' % (url, err)
+ )
raise Error('failed to fetch GPG key')
key = response.read().decode('utf-8')
tmp_key = write_tmp(key, 0, 0)
keyring = self.kubic_repo_gpgkey_path()
- call_throws(self.ctx, ['apt-key', '--keyring', keyring, 'add', tmp_key.name])
+ call_throws(
+ self.ctx, ['apt-key', '--keyring', keyring, 'add', tmp_key.name]
+ )
logger.info('Installing repo file at %s...' % self.kubic_repo_path())
content = 'deb %s /\n' % self.kubic_repo_url()
'mariner': ('mariner', 'cm'),
}
- def __init__(self, ctx: CephadmContext,
- stable: Optional[str], version: Optional[str], branch: Optional[str], commit: Optional[str],
- distro: Optional[str], distro_version: Optional[str]) -> None:
- super(YumDnf, self).__init__(ctx, stable=stable, version=version,
- branch=branch, commit=commit)
+ def __init__(
+ self,
+ ctx: CephadmContext,
+ stable: Optional[str],
+ version: Optional[str],
+ branch: Optional[str],
+ commit: Optional[str],
+ distro: Optional[str],
+ distro_version: Optional[str],
+ ) -> None:
+ super(YumDnf, self).__init__(
+ ctx, stable=stable, version=version, branch=branch, commit=commit
+ )
assert distro
assert distro_version
self.ctx = ctx
self.major = int(distro_version.split('.')[0])
self.distro_normalized = self.DISTRO_NAMES[distro][0]
self.distro_code = self.DISTRO_NAMES[distro][1] + str(self.major)
- if (self.distro_code == 'fc' and self.major >= 30) or \
- (self.distro_code == 'el' and self.major >= 8):
+ if (self.distro_code == 'fc' and self.major >= 30) or (
+ self.distro_code == 'el' and self.major >= 8
+ ):
self.tool = 'dnf'
- elif (self.distro_code == 'cm'):
+ elif self.distro_code == 'cm':
self.tool = 'tdnf'
else:
self.tool = 'yum'
def repo_baseurl(self) -> str:
assert self.stable or self.version
if self.version:
- return '%s/rpm-%s/%s' % (self.ctx.repo_url, self.version,
- self.distro_code)
+ return '%s/rpm-%s/%s' % (
+ self.ctx.repo_url,
+ self.version,
+ self.distro_code,
+ )
else:
- return '%s/rpm-%s/%s' % (self.ctx.repo_url, self.stable,
- self.distro_code)
+ return '%s/rpm-%s/%s' % (
+ self.ctx.repo_url,
+ self.stable,
+ self.distro_code,
+ )
def validate(self) -> None:
if self.distro_code.startswith('fc'):
- raise Error('Ceph team does not build Fedora specific packages and therefore cannot add repos for this distro')
+ raise Error(
+ 'Ceph team does not build Fedora specific packages and therefore cannot add repos for this distro'
+ )
if self.distro_code == 'el7':
if self.stable and self.stable >= 'pacific':
- raise Error('Ceph does not support pacific or later for this version of this linux distro and therefore cannot add a repo for it')
+ raise Error(
+ 'Ceph does not support pacific or later for this version of this linux distro and therefore cannot add a repo for it'
+ )
if self.version and self.version.split('.')[0] >= '16':
- raise Error('Ceph does not support 16.y.z or later for this version of this linux distro and therefore cannot add a repo for it')
+ raise Error(
+ 'Ceph does not support 16.y.z or later for this version of this linux distro and therefore cannot add a repo for it'
+ )
if self.stable or self.version:
# we know that yum & dnf require there to be a
urlopen(test_url)
except HTTPError as err:
logger.error('unable to fetch repo metadata: %r', err)
- raise Error('failed to fetch repository metadata. please check'
- ' the provided parameters are correct and try again')
+ raise Error(
+ 'failed to fetch repository metadata. please check'
+ ' the provided parameters are correct and try again'
+ )
def add_repo(self) -> None:
if self.stable or self.version:
content = ''
for n, t in {
- 'Ceph': '$basearch',
- 'Ceph-noarch': 'noarch',
- 'Ceph-source': 'SRPMS'}.items():
+ 'Ceph': '$basearch',
+ 'Ceph-noarch': 'noarch',
+ 'Ceph-source': 'SRPMS',
+ }.items():
content += '[%s]\n' % (n)
content += self.custom_repo(
name='Ceph %s' % t,
)
content += '\n\n'
else:
- content = self.query_shaman(self.distro_normalized, self.major,
- self.branch,
- self.commit)
+ content = self.query_shaman(
+ self.distro_normalized, self.major, self.branch, self.commit
+ )
logger.info('Writing repo to %s...' % self.repo_path())
with open(self.repo_path(), 'w') as f:
if self.distro_code.startswith('el'):
logger.info('Enabling EPEL...')
- call_throws(self.ctx, [self.tool, 'install', '-y', 'epel-release'])
+ call_throws(
+ self.ctx, [self.tool, 'install', '-y', 'epel-release']
+ )
def rm_repo(self) -> None:
if os.path.exists(self.repo_path()):
class Zypper(Packager):
- DISTRO_NAMES = [
- 'sles',
- 'opensuse-tumbleweed',
- 'opensuse-leap'
- ]
-
- def __init__(self, ctx: CephadmContext,
- stable: Optional[str], version: Optional[str], branch: Optional[str], commit: Optional[str],
- distro: Optional[str], distro_version: Optional[str]) -> None:
- super(Zypper, self).__init__(ctx, stable=stable, version=version,
- branch=branch, commit=commit)
+ DISTRO_NAMES = ['sles', 'opensuse-tumbleweed', 'opensuse-leap']
+
+ def __init__(
+ self,
+ ctx: CephadmContext,
+ stable: Optional[str],
+ version: Optional[str],
+ branch: Optional[str],
+ commit: Optional[str],
+ distro: Optional[str],
+ distro_version: Optional[str],
+ ) -> None:
+ super(Zypper, self).__init__(
+ ctx, stable=stable, version=version, branch=branch, commit=commit
+ )
assert distro is not None
self.ctx = ctx
self.tool = 'zypper'
def repo_baseurl(self) -> str:
assert self.stable or self.version
if self.version:
- return '%s/rpm-%s/%s' % (self.ctx.repo_url,
- self.stable, self.distro)
+ return '%s/rpm-%s/%s' % (
+ self.ctx.repo_url,
+ self.stable,
+ self.distro,
+ )
else:
- return '%s/rpm-%s/%s' % (self.ctx.repo_url,
- self.stable, self.distro)
+ return '%s/rpm-%s/%s' % (
+ self.ctx.repo_url,
+ self.stable,
+ self.distro,
+ )
def add_repo(self) -> None:
if self.stable or self.version:
content = ''
for n, t in {
- 'Ceph': '$basearch',
- 'Ceph-noarch': 'noarch',
- 'Ceph-source': 'SRPMS'}.items():
+ 'Ceph': '$basearch',
+ 'Ceph-noarch': 'noarch',
+ 'Ceph-source': 'SRPMS',
+ }.items():
content += '[%s]\n' % (n)
content += self.custom_repo(
name='Ceph %s' % t,
)
content += '\n\n'
else:
- content = self.query_shaman(self.distro, self.distro_version,
- self.branch,
- self.commit)
+ content = self.query_shaman(
+ self.distro, self.distro_version, self.branch, self.commit
+ )
logger.info('Writing repo to %s...' % self.repo_path())
with open(self.repo_path(), 'w') as f:
self.install(['podman'])
-def create_packager(ctx: CephadmContext,
- stable: Optional[str] = None, version: Optional[str] = None,
- branch: Optional[str] = None, commit: Optional[str] = None) -> Packager:
+def create_packager(
+ ctx: CephadmContext,
+ stable: Optional[str] = None,
+ version: Optional[str] = None,
+ branch: Optional[str] = None,
+ commit: Optional[str] = None,
+) -> Packager:
distro, distro_version, distro_codename = get_distro()
if distro in YumDnf.DISTRO_NAMES:
- return YumDnf(ctx, stable=stable, version=version,
- branch=branch, commit=commit,
- distro=distro, distro_version=distro_version)
+ return YumDnf(
+ ctx,
+ stable=stable,
+ version=version,
+ branch=branch,
+ commit=commit,
+ distro=distro,
+ distro_version=distro_version,
+ )
elif distro in Apt.DISTRO_NAMES:
- return Apt(ctx, stable=stable, version=version,
- branch=branch, commit=commit,
- distro=distro, distro_version=distro_version,
- distro_codename=distro_codename)
+ return Apt(
+ ctx,
+ stable=stable,
+ version=version,
+ branch=branch,
+ commit=commit,
+ distro=distro,
+ distro_version=distro_version,
+ distro_codename=distro_codename,
+ )
elif distro in Zypper.DISTRO_NAMES:
- return Zypper(ctx, stable=stable, version=version,
- branch=branch, commit=commit,
- distro=distro, distro_version=distro_version)
- raise Error('Distro %s version %s not supported' % (distro, distro_version))
+ return Zypper(
+ ctx,
+ stable=stable,
+ version=version,
+ branch=branch,
+ commit=commit,
+ distro=distro,
+ distro_version=distro_version,
+ )
+ raise Error(
+ 'Distro %s version %s not supported' % (distro, distro_version)
+ )