From 9c9d7ed695a3b08f1cae4f3fb4f96f9f03acb3b1 Mon Sep 17 00:00:00 2001 From: Sebastian Gode Date: Tue, 15 Apr 2025 09:37:52 +0000 Subject: [PATCH] Added testservice --- .../data/documents/testservice-api-ref.yaml | 13 + otc_metadata/services.py | 2 - otc_metadata/templates/tox.ini.j2 | 2 - tools/bootstrap_repositories.py | 3 +- tools/generate_doc_confpy.py | 253 +++++++++--------- 5 files changed, 147 insertions(+), 126 deletions(-) create mode 100644 otc_metadata/data/documents/testservice-api-ref.yaml diff --git a/otc_metadata/data/documents/testservice-api-ref.yaml b/otc_metadata/data/documents/testservice-api-ref.yaml new file mode 100644 index 0000000..8151263 --- /dev/null +++ b/otc_metadata/data/documents/testservice-api-ref.yaml @@ -0,0 +1,13 @@ +--- +hc_location: usermanual/testservice +html_location: docs/testservice/api-ref +link: /testservice/api-ref/ +rst_location: api-ref/source +service_type: testservice +title: User Guide +type: api-ref +cloud_environments: + - name: swiss + visibility: public + pdf_visibility: public + pdf_enabled: true diff --git a/otc_metadata/services.py b/otc_metadata/services.py index 71f1002..c2ad881 100644 --- a/otc_metadata/services.py +++ b/otc_metadata/services.py @@ -350,11 +350,9 @@ class Services(object): res = dict() res = {} services = self.all_services - print(services) for service in services: if service["service_type"] == service_type: res = service - print(res) for repositories in self.all_repositories: if repositories["service_type"] == service["service_type"]: res["repositories"] = repositories["repositories"] diff --git a/otc_metadata/templates/tox.ini.j2 b/otc_metadata/templates/tox.ini.j2 index edfd5f1..82a1bc5 100644 --- a/otc_metadata/templates/tox.ini.j2 +++ b/otc_metadata/templates/tox.ini.j2 @@ -64,11 +64,9 @@ commands = wget -O {toxinidir}/_templates/longtable.tex.jinja https://gitea.eco.tsi-dev.otc-service.com/infra/docs-templates/raw/branch/main/templates/longtable.tex.jinja wget -O {toxinidir}/_templates/tabular.tex.jinja https://gitea.eco.tsi-dev.otc-service.com/infra/docs-templates/raw/branch/main/templates/tabular.tex.jinja wget -O {toxinidir}/_templates/tabulary.tex.jinja https://gitea.eco.tsi-dev.otc-service.com/infra/docs-templates/raw/branch/main/templates/tabulary.tex.jinja -{%- for doc in docs %} {%- if doc.pdf_enabled %} {[testenv:{{ doc.type }}-pdf-docs]commands} {%- endif %} -{%- endfor %} {% endif %} {% for doc in docs -%} diff --git a/tools/bootstrap_repositories.py b/tools/bootstrap_repositories.py index 46b0880..8340d99 100644 --- a/tools/bootstrap_repositories.py +++ b/tools/bootstrap_repositories.py @@ -103,6 +103,7 @@ def create_repo(repo, repo_dir, service): git_repo = Repo(repo_dir) git_repo.create_remote("origin", repo_url) git_repo.remotes.origin.fetch() + git_repo.git.branch("-m", "main") git_repo.git.push("--set-upstream", "origin", "main") @@ -155,9 +156,7 @@ def main(): else: services = data.services_with_repos() - print(services) for service in services: - print(service) process_repositories(args, service) diff --git a/tools/generate_doc_confpy.py b/tools/generate_doc_confpy.py index ce2e764..0457cd2 100644 --- a/tools/generate_doc_confpy.py +++ b/tools/generate_doc_confpy.py @@ -56,69 +56,70 @@ def process_repositories(args, service): doc_requirements_template = env.get_template("doc_requirements.txt.j2") for repo in service["repositories"]: - logging.debug(f"Processing repository {repo}") - repo_dir = pathlib.Path(workdir, repo["type"], repo["repo"]) + if repo["cloud_environments"][0] == args.cloud_environment: + logging.debug(f"Processing repository {repo}") + repo_dir = pathlib.Path(workdir, repo["type"], repo["repo"]) - if repo["environment"] == args.target_environment: - copy_to = repo_dir - else: - logging.debug(f"Skipping repository {repo}") - continue + if repo["environment"] == args.target_environment: + copy_to = repo_dir + else: + logging.debug(f"Skipping repository {repo}") + continue - repo_dir.mkdir(parents=True, exist_ok=True) - if repo["type"] == "gitea": - repo_url = ( - f"ssh://git@gitea.eco.tsi-dev.otc-service.com:2222/" - f"{repo['repo']}" - ) - git_fqdn = "gitea.eco.tsi-dev.otc-service.com" - elif repo["type"] == "github": - repo_url = f"git@github.com:/{repo['repo']}" - else: - logging.error(f"Repository type {repo['type']} is not supported") - error_list.append({ - "error": f"Repository type {repo['type']} is not supported", - "repo": repo['repo'] - }) - continue - - if repo_dir.exists(): - logging.debug(f"Repository {repo} already checked out") - try: - git_repo = Repo(repo_dir) - git_repo.remotes.origin.fetch() - git_repo.heads.main.checkout() - git_repo.remotes.origin.pull() - except exc.InvalidGitRepositoryError: - logging.error("Existing repository checkout is bad") - repo_dir.rmdir() - except Exception as e: + repo_dir.mkdir(parents=True, exist_ok=True) + if repo["type"] == "gitea": + repo_url = ( + f"ssh://git@gitea.eco.tsi-dev.otc-service.com:2222/" + f"{repo['repo']}" + ) + git_fqdn = "gitea.eco.tsi-dev.otc-service.com" + elif repo["type"] == "github": + repo_url = f"git@github.com:/{repo['repo']}" + else: + logging.error(f"Repository type {repo['type']} is not supported") error_list.append({ - "error": e, - "repo": repo['repo'] - }) - - if not repo_dir.exists(): - try: - git_repo = Repo.clone_from(repo_url, repo_dir, branch="main") - except Exception: - logging.error(f"Error cloning repository {repo_url}") - error_list.append({ - "error": f"Error cloning repository {repo_url}", + "error": f"Repository type {repo['type']} is not supported", "repo": repo['repo'] }) continue - if repo["environment"] == args.target_environment: - url_to = repo_url - repo_to = git_repo - target_repo = repo - break + if repo_dir.exists(): + logging.debug(f"Repository {repo} already checked out") + try: + git_repo = Repo(repo_dir) + git_repo.remotes.origin.fetch() + git_repo.heads.main.checkout() + git_repo.remotes.origin.pull() + except exc.InvalidGitRepositoryError: + logging.error("Existing repository checkout is bad") + repo_dir.rmdir() + except Exception as e: + error_list.append({ + "error": e, + "repo": repo['repo'] + }) + + if not repo_dir.exists(): + try: + git_repo = Repo.clone_from(repo_url, repo_dir, branch="main") + except Exception: + logging.error(f"Error cloning repository {repo_url}") + error_list.append({ + "error": f"Error cloning repository {repo_url}", + "repo": repo['repo'] + }) + continue + + if repo["environment"] == args.target_environment: + url_to = repo_url + repo_to = git_repo + target_repo = repo + break if not target_repo: logging.info( f"No repository service {service['service_title']}" - f"for environment {args.target_environment}" + f"for environment {args.target_environment} in cloud_environment {args.cloud_environment}" ) return @@ -149,69 +150,70 @@ def process_repositories(args, service): service_docs = list(data.docs_by_service_type(service["service_type"])) for doc in service_docs: - logging.debug(f"Analyzing document {doc}") + for cloud_environment in doc["cloud_environments"]: + if cloud_environment["name"] == args.cloud_environment: + logging.debug(f"Analyzing document {doc}") - conf_py_path = pathlib.Path(copy_to, doc["rst_location"], "conf.py") - if not conf_py_path.exists(): - logging.info(f"Path for document {doc['title']} does not exist") - conf_py_path.parent.mkdir(parents=True, exist_ok=True) - context = dict( - repo_name=target_repo["repo"], - project=service["service_title"], - # pdf_name=doc["pdf_name"], - title=f"{service['service_title']} - {doc['title']}", - ) - if "pdf_name" in doc: - context["pdf_name"] = doc["pdf_name"] - if git_fqdn: - context["git_fqdn"] = git_fqdn - if target_repo.get("type") != "github": - context["git_type"] = target_repo["type"] - if (args.target_environment == "public" - and target_repo["repo"].split("/")[0] == "opentelekomcloud-docs-swiss"): - context["html_options"] = dict( - logo_url="https://docs.sc.otc.t-systems.com", - ) - elif (args.target_environment == "public"): - context["html_options"] = dict( - logo_url="https://docs.otc.t-systems.com", - ) - elif (args.target_environment == "internal" - and target_repo["repo"].split("/")[0] == "docs-swiss"): - context["html_options"] = dict( - disable_search=True, - site_name="Internal Documentation Portal", - logo_url="https://docs-swiss-int.otc-service.com", - ) - elif args.target_environment == "internal": - context["html_options"] = dict( - disable_search=True, - site_name="Internal Documentation Portal", - logo_url="https://docs-int.otc-service.com", - ) - context["doc_environment"] = args.target_environment - if doc['link']: - context["doc_link"] = doc['link'] - else: - context["doc_link"] = ( - '/' - + service['service_uri'] - + '/' - + doc['type'] - + '/' - ) - context["doc_title"] = doc['title'] - context["doc_type"] = doc['type'] - context["service_category"] = service['service_category'] - context["service_title"] = service['service_title'] - context["service_type"] = service['service_type'] + conf_py_path = pathlib.Path(copy_to, doc["rst_location"], "conf.py") + if not conf_py_path.exists(): + logging.info(f"Path for document {doc['title']} does not exist") + conf_py_path.parent.mkdir(parents=True, exist_ok=True) + context = dict( + repo_name=target_repo["repo"], + project=service["service_title"], + title=f"{service['service_title']} - {doc['title']}", + ) + if "pdf_name" in doc: + context["pdf_name"] = doc["pdf_name"] + if git_fqdn: + context["git_fqdn"] = git_fqdn + if target_repo.get("type") != "github": + context["git_type"] = target_repo["type"] + if (args.target_environment == "public" + and args.cloud_environment == "swiss"): + context["html_options"] = dict( + logo_url="https://docs.sc.otc.t-systems.com", + ) + elif (args.target_environment == "public"): + context["html_options"] = dict( + logo_url="https://docs.otc.t-systems.com", + ) + elif (args.target_environment == "internal" + and args.cloud_environment == "swiss"): + context["html_options"] = dict( + disable_search=True, + site_name="Internal Documentation Portal", + logo_url="https://docs-swiss-int.otc-service.com", + ) + elif args.target_environment == "internal": + context["html_options"] = dict( + disable_search=True, + site_name="Internal Documentation Portal", + logo_url="https://docs-int.otc-service.com", + ) + context["doc_environment"] = args.target_environment + if doc['link']: + context["doc_link"] = doc['link'] + else: + context["doc_link"] = ( + '/' + + service['service_uri'] + + '/' + + doc['type'] + + '/' + ) + context["doc_title"] = doc['title'] + context["doc_type"] = doc['type'] + context["service_category"] = service['service_category'] + context["service_title"] = service['service_title'] + context["service_type"] = service['service_type'] - conf_py_content = conf_py_template.render(**context) - with open(conf_py_path, "w", encoding="utf-8", newline="") as out: - logging.debug(f"Generating {conf_py_path} from template...") - out.write(conf_py_content) + conf_py_content = conf_py_template.render(**context) + with open(conf_py_path, "w", encoding="utf-8", newline="") as out: + logging.debug(f"Generating {conf_py_path} from template...") + out.write(conf_py_content) - repo_to.index.add([doc["rst_location"]]) + repo_to.index.add([doc["rst_location"]]) if args.update_sbv: """Add or update service-based-view""" @@ -234,7 +236,7 @@ def process_repositories(args, service): if target_repo.get("type") != "github": context["git_type"] = target_repo["type"] if (args.target_environment == "public" - and target_repo["repo"].split("/")[0] == "opentelekomcloud-docs-swiss"): + and args.cloud_environment == "swiss"): context["html_options"] = dict( logo_url="https://docs.sc.otc.t-systems.com", ) @@ -243,7 +245,7 @@ def process_repositories(args, service): logo_url="https://docs.otc.t-systems.com", ) elif (args.target_environment == "internal" - and target_repo["repo"].split("/")[0] == "docs-swiss"): + and args.cloud_environment == "swiss"): context["html_options"] = dict( disable_search=True, site_name="Internal Documentation Portal", @@ -289,9 +291,12 @@ def process_repositories(args, service): """Update tox.ini""" context = dict(docs=[]) for doc in service_docs: - if doc["type"] == "dev": - doc["type"] = "dev-guide" - context["docs"].append(doc) + for cloud_environment in doc["cloud_environments"]: + if cloud_environment["name"] == args.cloud_environment: + if doc["type"] == "dev": + doc["type"] = "dev-guide" + context["docs"].append(doc) + context["pdf_enabled"] = cloud_environment["pdf_enabled"] context["target_environment"] = args.target_environment context["service_type"] = service['service_type'] @@ -320,9 +325,11 @@ def process_repositories(args, service): """Update zuul.yaml""" context = dict(docs=[]) for doc in service_docs: - if doc["type"] == "dev": - doc["type"] = "dev-guide" - context["docs"].append(doc) + for cloud_environment in doc["cloud_environments"]: + if cloud_environment["name"] == args.cloud_environment: + if doc["type"] == "dev": + doc["type"] = "dev-guide" + context["docs"].append(doc) context["service_type"] = service['service_type'] zuul_yaml_content = zuul_yaml_template.render(**context) @@ -451,6 +458,12 @@ def main(): ), help="Commit description for the commit", ) + parser.add_argument( + "--cloud-environment", + required=True, + default="eu_de", + help="Cloud Environment. Default: eu_de", + ) args = parser.parse_args() logging.basicConfig(level=logging.DEBUG)