Add jobs to generate Nova OpenAPI spec

Change-Id: I6c1d45db9214fd5678cc277a27bbd2a0ba5f78ec
This commit is contained in:
gtema 2024-03-04 18:40:21 +01:00 committed by Artem Goncharov
parent 4d23d8aab5
commit 87c5849b9c
8 changed files with 165 additions and 2 deletions

View File

@ -60,7 +60,9 @@ class NovaGenerator(OpenStackServerSourceBase):
work_dir = Path(target_dir)
work_dir.mkdir(parents=True, exist_ok=True)
impl_path = Path(work_dir, "openapi_specs", "compute", "v2.yaml")
impl_path = Path(
work_dir, "openapi_specs", "compute", f"v{self.api_version}.yaml"
)
impl_path.parent.mkdir(parents=True, exist_ok=True)
openapi_spec = self.load_openapi(impl_path)
@ -102,6 +104,9 @@ class NovaGenerator(OpenStackServerSourceBase):
)
self.dump_openapi(openapi_spec, impl_path, args.validate)
lnk = Path(impl_path.parent, "v2.yaml")
lnk.unlink(missing_ok=True)
lnk.symlink_to(impl_path.name)
return impl_path
@ -111,7 +116,6 @@ class NovaGenerator(OpenStackServerSourceBase):
proc.join()
if proc.exitcode != 0:
raise RuntimeError("Error generating Compute OpenAPI schema")
return Path(target_dir, "openapi_specs", "compute", "v2.yaml")
def _get_param_ref(
self,

View File

@ -0,0 +1,37 @@
---
- hosts: all
tasks:
- name: Ensure local output dirs
delegate_to: localhost
ansible.builtin.file:
path: "{{ zj_output_dir }}"
state: directory
mode: 0755
with_items:
- "{{ zuul.executor.work_root }}/artifacts"
loop_control:
loop_var: zj_output_dir
- name: Collect OpenAPI specs
synchronize:
dest: "{{ zj_output.dest }}/"
mode: pull
src: "{{ ansible_user_dir }}/{{ codegenerator_work_dir }}/{{ zj_output.src }}"
verify_host: true
owner: false
group: false
loop:
- dest: "{{ zuul.executor.work_root }}/artifacts"
src: "openapi_specs"
loop_control:
loop_var: zj_output
- name: Return artifact to Zuul
zuul_return:
data:
zuul:
artifacts:
- name: "OpenAPI specs"
url: "artifacts/openapi_specs"
metadata:
type: openapi

View File

@ -0,0 +1,14 @@
---
- hosts: all
roles:
- ensure-tox
tasks:
# tox_executable var is filled by ensure-tox role
- name: Build service api-ref
ansible.builtin.command: "{{ tox_executable }} -e api-ref"
args:
chdir: "{{ zuul.projects[codegenerator_api_ref.project].src_dir }}"
when:
- "codegenerator_api_ref is defined"
- "codegenerator_api_ref is mapping"

View File

@ -0,0 +1,21 @@
---
- hosts: all
roles:
- ensure-pip
- ensure-virtualenv
tasks:
- name: Install openstack-codegenerator from sources
ansible.builtin.pip:
chdir: "{{ zuul.projects['opendev.org/openstack/codegenerator'].src_dir }}"
name: "."
virtualenv: "{{ ansible_user_dir }}/.venv"
- name: Install additional dependencies from sources
ansible.builtin.pip:
chdir: "{{ zuul.projects[zj_dep.project].src_dir }}"
name: "{{ zj_dep.name }}"
virtualenv: "{{ ansible_user_dir }}/.venv"
loop: "{{ install_additional_projects }}"
loop_control:
loop_var: zj_dep

View File

@ -0,0 +1,22 @@
---
- hosts: all
tasks:
- name: Update openapi-core
ansible.builtin.pip:
name: "openapi-core"
state: "latest"
virtualenv: "{{ ansible_user_dir }}/.venv"
- name: Generate OpenAPI spec
args:
chdir: "{{ ansible_user_dir }}/.venv"
executable: /bin/bash
ansible.builtin.shell: >-
source {{ ansible_user_dir }}/.venv/bin/activate;
openstack-codegenerator
--work-dir {{ ansible_user_dir }}/{{ codegenerator_work_dir }}
--target openapi-spec
--service-type {{ openapi_service }}
{%- if codegenerator_api_ref is defined and codegenerator_api_ref is mapping %}
--api-ref-src {{ ansible_user_dir }}/{{ zuul.projects[codegenerator_api_ref.project].src_dir }}/{{ codegenerator_api_ref.path | default("/api-ref/build/html/index.html") }}
{% endif %}

View File

@ -12,5 +12,6 @@ mdformat>=0.7 # MIT
# Get sphinx docstrings from source code
sphinx>=2.0.0,!=2.1.0 # BSD
wsgi-intercept>=1.13 # MIT
wsme>=0.12 # MIT
oslotest>=5.0.0 # Apache-2.0
openstacksdk>=2.0 # Apache-2.0

63
zuul.d/openapi.yaml Normal file
View File

@ -0,0 +1,63 @@
---
- job:
name: codegenerator-openapi-tips-base
parent: unittests
description: |
Base job for generation of the OpenAPI spec
The job expects following variables to be set:
.. zuul:jobvar:: openapi_service
OpenStack service to generate OpenAPI spec for.
Supported are:
- block-storage
- compute
- identity
- image
- load-balancing
- network
- placement
required-projects:
- name: openstack/codegenerator
attempts: 1
timeout: 600
pre-run:
- playbooks/openapi/pre.yaml
run:
- playbooks/openapi/run.yaml
post-run:
- playbooks/openapi/post.yaml
vars:
codegenerator_work_dir: "wrk"
install_additional_projects: []
- job:
name: codegenerator-openapi-compute-tips
parent: codegenerator-openapi-tips-base
description: |
Generate OpenAPI spec for nova
required-projects:
- name: openstack/nova
vars:
openapi_service: compute
install_additional_projects:
- project: "opendev.org/openstack/nova"
name: "."
- job:
name: codegenerator-openapi-compute-tips-with-api-ref
parent: codegenerator-openapi-compute-tips
description: |
Generate OpenAPI spec for nova consuming API-REF
required-projects:
- name: openstack/nova
pre-run:
- playbooks/openapi/pre-api-ref.yaml
vars:
codegenerator_api_ref:
project: "opendev.org/openstack/nova"
path: "/api-ref/build/html/index.html"

View File

@ -6,3 +6,4 @@
jobs:
- openstack-tox-pep8
- openstack-tox-py311
- codegenerator-openapi-compute-tips-with-api-ref