def test_replace_registries(datadir): """Test if registry is replaced in all files""" def _yield_yaml_files(dir_path): for root, _, files in os.walk(dir_path): for fname in files: fname_lower = fname.lower() if fname_lower.endswith('.yml') or fname_lower.endswith( '.yaml'): yield os.path.join(root, fname) dir_path = os.path.join(datadir, 'etcd_op_nested') old = 'quay.io' new = 'example.com' qo = QuayOrganization('testorg', 'random token', replace_registry_conf=[{ 'old': old, 'new': new, 'regexp': False }]) should_be_replaced = set() for fpath in _yield_yaml_files(dir_path): with open(fpath, 'r') as f: text = f.read() if old in text: should_be_replaced.add(fpath) replace_registries(qo, dir_path) for fpath in should_be_replaced: with open(fpath, 'r') as f: text = f.read() assert new in text assert old not in text
def _zip_flow(*, organization, repo, version, extract_manifest_func, extras_data=None): """ :param str organization: quay.io organization :param str|None repo: target repository (if not specified, will be taken from manifest data) :param str|None version: version of operator manifest :param Callable[str, int] extract_manifest_func: function to retrieve operator manifests zip file. First argument of function is path to target dir where zip archive content will be extracted, second argument max size of extracted files :param extras_data: extra data added to response :return: JSON response """ cnr_token = extract_auth_token(request) quay_org = ORG_MANAGER.get_org(organization, cnr_token) data = {} with TemporaryDirectory() as tmpdir: max_size = current_app.config['ZIPFILE_MAX_UNCOMPRESSED_SIZE'] extract_manifest_func(tmpdir, max_uncompressed_size=max_size) extracted_files = _dir_files(tmpdir) logger.info("Extracted files: %s", extracted_files) data['extracted_files'] = extracted_files with TemporaryDirectory() as tmpdir_flatten: # operator-courier supports only flat dir structure _flatten_manifest_structure(tmpdir, tmpdir_flatten) if repo is None: repo = _get_reponame_from_manifests(tmpdir_flatten) version = get_package_version(quay_org, repo, version) logger.info("Using release version: %s", version) replace_registries(quay_org, tmpdir_flatten) quay_org.push_operator_manifest(repo, version, tmpdir_flatten) data.update({ 'organization': organization, 'repo': repo, 'version': version, }) if extras_data: data.update(extras_data) resp = jsonify(data) resp.status_code = 200 return resp