import argparse
import configobj
import contextlib
-import errno
import logging
import os
import json
import yaml
from io import BytesIO, StringIO
-import toml
from tarfile import ReadError
from tasks.ceph_manager import CephManager
from teuthology import misc as teuthology
pass
@contextlib.contextmanager
-def ceph_bootstrap(ctx, config, registry):
+def ceph_bootstrap(ctx, config):
"""
- Bootstrap ceph cluster, setup containers' registry mirror before
- the bootstrap if the registry is provided.
+ Bootstrap ceph cluster.
:param ctx: the argparse.Namespace object
:param config: the config dict
- :param registry: url to containers' mirror registry
"""
cluster_name = config['cluster']
testdir = teuthology.get_testdir(ctx)
ctx.cluster.run(args=[
'sudo', 'chmod', '777', '/etc/ceph',
]);
- if registry:
- add_mirror_to_cluster(ctx, registry)
try:
# write seed config
log.info('Writing seed config...')
"""
Deploy ceph cluster using cephadm
- Setup containers' mirrors before the bootstrap, if corresponding
- config provided in teuthology server config yaml file.
-
For example, teuthology.yaml can contain the 'defaults' section:
defaults:
cephadm:
containers:
- registry_mirrors:
- docker.io: 'registry.mirror.example.com:5000'
image: 'quay.io/ceph-ci/ceph'
Using overrides makes it possible to customize it per run.
overrides:
cephadm:
containers:
- registry_mirrors:
- docker.io: 'registry.mirror.example.com:5000'
image: 'quay.io/ceph-ci/ceph'
:param ctx: the argparse.Namespace object
teuth_defaults = teuth_config.get('defaults', {})
cephadm_defaults = teuth_defaults.get('cephadm', {})
containers_defaults = cephadm_defaults.get('containers', {})
- mirrors_defaults = containers_defaults.get('registry_mirrors', {})
- container_registry_mirror = mirrors_defaults.get('docker.io', None)
container_image_name = containers_defaults.get('image', None)
containers = config.get('containers', {})
- mirrors = containers.get('registry_mirrors', {})
container_image_name = containers.get('image', container_image_name)
- container_registry_mirror = mirrors.get('docker.io',
- container_registry_mirror)
if not hasattr(ctx.ceph[cluster_name], 'image'):
lambda: ceph_log(ctx=ctx, config=config),
lambda: ceph_crash(ctx=ctx, config=config),
lambda: _bypass() if (ctx.ceph[cluster_name].bootstrapped)\
- else ceph_bootstrap(ctx, config,
- container_registry_mirror),
+ else ceph_bootstrap(ctx, config),
lambda: crush_setup(ctx=ctx, config=config),
lambda: ceph_mons(ctx=ctx, config=config),
lambda: distribute_config_and_admin_keyring(ctx=ctx, config=config),
finally:
log.info('Teardown begin')
-
-def registries_add_mirror_to_docker_io(conf, mirror):
- config = toml.loads(conf)
- is_v1 = 'registries' in config
- if is_v1:
- search = config.get('registries', {}).get('search', {}).get('registries', [])
- insecure = config.get('registries', {}).get('search', {}).get('insecure', [])
- # v2: MutableMapping[str, Any] = { needs Python 3
- v2 = {
- 'unqualified-search-registries': search,
- 'registry': [
- {
- 'prefix': reg,
- 'location': reg,
- 'insecure': reg in insecure,
- 'blocked': False,
- } for reg in search
- ]
- }
- else:
- v2 = config # type: ignore
- dockers = [
- r for r in v2['registry'] if
- r.get('prefix') == 'docker.io' or r.get('location') == 'docker.io'
- ]
- if dockers:
- docker = dockers[0]
- if 'mirror' not in docker:
- docker['mirror'] = [{
- "location": mirror,
- "insecure": True,
- }]
- return v2
-
-
-def add_mirror_to_cluster(ctx, mirror):
- log.info('Adding local image mirror %s' % mirror)
-
- registries_conf = '/etc/containers/registries.conf'
-
- for remote in ctx.cluster.remotes.keys():
- try:
- config = remote.read_file(registries_conf)
- new_config = toml.dumps(registries_add_mirror_to_docker_io(config.decode('utf-8'), mirror))
-
- remote.sudo_write_file(registries_conf, new_config)
- except IOError as e: # py3: use FileNotFoundError instead.
- if e.errno != errno.ENOENT:
- raise
-
- # Docker doesn't ship a registries.conf
- log.info('Failed to add mirror: %s' % str(e))