import uuid
from io import BytesIO
+import toml
from six import StringIO
from tarfile import ReadError
from tasks.ceph_manager import CephManager
ctx.cluster.run(args=[
'sudo', 'chmod', '777', '/etc/ceph',
]);
+ add_mirror_to_cluster(ctx, config.get('docker_registry_mirror', 'vossi04.front.sepia.ceph.com:5000'))
try:
# write seed config
log.info('Writing seed 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['prefix'] == 'docker.io']
+ if dockers:
+ docker = dockers[0]
+ 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():
+ config = teuthology.get_file(
+ remote=remote,
+ path=registries_conf
+ )
+ new_config = toml.dumps(registries_add_mirror_to_docker_io(config.decode('utf-8'), mirror))
+
+ teuthology.sudo_write_file(
+ remote=remote,
+ path=registries_conf,
+ data=new_config,
+ )
--- /dev/null
+from tasks import cephadm
+
+v1 = """
+[registries.search]
+registries = ['registry.access.redhat.com', 'registry.redhat.io', 'docker.io', 'quay.io']
+
+[registries.insecure]
+registries = []
+"""
+
+v2 = """
+unqualified-search-registries = ["registry.access.redhat.com", "registry.redhat.io", "docker.io", 'quay.io']
+
+[[registry]]
+prefix = "registry.access.redhat.com"
+location = "registry.access.redhat.com"
+insecure = false
+blocked = false
+
+[[registry]]
+prefix = "registry.redhat.io"
+location = "registry.redhat.io"
+insecure = false
+blocked = false
+
+[[registry]]
+prefix = "docker.io"
+location = "docker.io"
+insecure = false
+blocked = false
+
+[[registry.mirror]]
+location = "vossi04.front.sepia.ceph.com:5000"
+insecure = true
+
+[[registry]]
+prefix = "quay.io"
+location = "quay.io"
+insecure = false
+blocked = false
+"""
+
+expected = {
+ 'unqualified-search-registries': ['registry.access.redhat.com', 'registry.redhat.io',
+ 'docker.io', 'quay.io'],
+ 'registry': [
+ {'prefix': 'registry.access.redhat.com',
+ 'location': 'registry.access.redhat.com',
+ 'insecure': False,
+ 'blocked': False},
+ {'prefix': 'registry.redhat.io',
+ 'location': 'registry.redhat.io',
+ 'insecure': False,
+ 'blocked': False},
+ {'prefix': 'docker.io',
+ 'location': 'docker.io',
+ 'insecure': False,
+ 'blocked': False,
+ 'mirror': [{'location': 'vossi04.front.sepia.ceph.com:5000',
+ 'insecure': True}]},
+ {'prefix': 'quay.io',
+ 'location': 'quay.io',
+ 'insecure': False,
+ 'blocked': False}
+ ]
+}
+
+def test_add_mirror():
+ assert cephadm.registries_add_mirror_to_docker_io(v1, 'vossi04.front.sepia.ceph.com:5000') == expected
+ assert cephadm.registries_add_mirror_to_docker_io(v2, 'vossi04.front.sepia.ceph.com:5000') == expected
[tox]
-envlist = flake8-py2, flake8-py3, mypy
+envlist = flake8-py2, flake8-py3, mypy, pytest
skipsdist = True
[testenv:flake8-py2]
basepython = python3
deps = {env:TEUTHOLOGY_GIT:git+https://github.com/ceph/teuthology.git@master}#egg=teuthology[coverage,orchestra,test]
commands = python test_import.py {posargs:tasks/**/*.py}
+
+[testenv:pytest]
+basepython = python3
+deps =
+ {env:TEUTHOLOGY_GIT:git+https://github.com/ceph/teuthology.git@master}#egg=teuthology[test]
+ httplib2
+commands = pytest -vv tasks/tests
\ No newline at end of file