From f5061cae9d94d01e6a93e878379813807892d4d8 Mon Sep 17 00:00:00 2001 From: Fabricio Aguiar Date: Tue, 19 Mar 2024 16:07:43 +0000 Subject: [PATCH] Test samples from inline docs Signed-off-by: Fabricio Aguiar --- .pre-commit-config.yaml | 5 + ...aPlaneNodeSet-CR-for-bare-metal-nodes.adoc | 23 ++-- ...neNodeSet-CR-for-preprovisioned-nodes.adoc | 20 +-- docs/docs_to_sample.sh | 10 ++ tests/kuttl/tests/docs-test/00-assert.yaml | 109 ++++++++++++++++ .../kuttl/tests/docs-test/00-doc-sample.yaml | 120 ++++++++++++++++++ 6 files changed, 265 insertions(+), 22 deletions(-) create mode 100755 docs/docs_to_sample.sh create mode 100644 tests/kuttl/tests/docs-test/00-assert.yaml create mode 100644 tests/kuttl/tests/docs-test/00-doc-sample.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 031ebb4bc..27f21e44a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,11 @@ repos: - repo: local hooks: + - id: doc-sample + name: doc-sample + language: system + entry: docs/docs_to_sample.sh + args: ["docs/assemblies/ref_example-OpenStackDataPlaneNodeSet-CR-for-preprovisioned-nodes.adoc", "tests/kuttl/tests/docs-test/00-doc-sample.yaml"] - id: gotidy name: gotidy language: system diff --git a/docs/assemblies/ref_example-OpenStackDataPlaneNodeSet-CR-for-bare-metal-nodes.adoc b/docs/assemblies/ref_example-OpenStackDataPlaneNodeSet-CR-for-bare-metal-nodes.adoc index 00b38529d..aa74bc500 100644 --- a/docs/assemblies/ref_example-OpenStackDataPlaneNodeSet-CR-for-bare-metal-nodes.adoc +++ b/docs/assemblies/ref_example-OpenStackDataPlaneNodeSet-CR-for-bare-metal-nodes.adoc @@ -10,10 +10,10 @@ kind: OpenStackDataPlaneNodeSet metadata: name: openstack-edpm-ipam spec: - env: <1> + env: #<1> - name: ANSIBLE_FORCE_COLOR value: "True" - services: <2> + services: #<2> - configure-network - validate-network - install-os @@ -23,19 +23,19 @@ spec: - libvirt - nova - telemetry - baremetalSetTemplate: <3> + baremetalSetTemplate: #<3> bmhLabelSelector: app: openstack ctlplaneInterface: enp1s0 cloudUserName: cloud-admin nodes: - edpm-compute-0: <4> + edpm-compute-0: #<4> hostName: edpm-compute-0 - networkAttachments: <5> + networkAttachments: #<5> - ctlplane - nodeTemplate: <6> - ansibleSSHPrivateKeySecret: dataplane-ansible-ssh-private-key-secret <7> - networks: <8> + nodeTemplate: #<6> + ansibleSSHPrivateKeySecret: dataplane-ansible-ssh-private-key-secret #<7> + networks: #<8> - name: CtlPlane subnetName: subnet1 defaultRoute: true @@ -47,16 +47,15 @@ spec: subnetName: subnet1 managementNetwork: ctlplane ansible: - ansibleUser: cloud-admin <9> + ansibleUser: cloud-admin #<9> ansiblePort: 22 - ansibleVars: <10> + ansibleVars: #<10> service_net_map: nova_api_network: internal_api nova_libvirt_network: internal_api edpm_chrony_ntp_servers: - pool.ntp.org - edpm_network_config_hide_sensitive_logs: false - edpm_network_config_template: | <11> + edpm_network_config_template: | #<11> --- {% set mtu_list = [ctlplane_mtu] %} {% for network in role_networks %} diff --git a/docs/assemblies/ref_example-OpenStackDataPlaneNodeSet-CR-for-preprovisioned-nodes.adoc b/docs/assemblies/ref_example-OpenStackDataPlaneNodeSet-CR-for-preprovisioned-nodes.adoc index e17706df2..5a387bb62 100644 --- a/docs/assemblies/ref_example-OpenStackDataPlaneNodeSet-CR-for-preprovisioned-nodes.adoc +++ b/docs/assemblies/ref_example-OpenStackDataPlaneNodeSet-CR-for-preprovisioned-nodes.adoc @@ -10,11 +10,11 @@ kind: OpenStackDataPlaneNodeSet metadata: name: openstack-edpm-ipam spec: - env: <1> + env: #<1> - name: ANSIBLE_FORCE_COLOR value: "True" - preProvisioned: true <2> - services: <3> + preProvisioned: true #<2> + services: #<3> - configure-network - validate-network - install-os @@ -25,7 +25,7 @@ spec: - nova - telemetry nodes: - edpm-compute-0: <4> + edpm-compute-0: #<4> hostName: edpm-compute-0 ansible: ansibleHost: 192.168.122.100 @@ -55,21 +55,21 @@ spec: subnetName: subnet1 - name: Tenant subnetName: subnet1 - networkAttachments: <5> + networkAttachments: #<5> - ctlplane - nodeTemplate: <6> - ansibleSSHPrivateKeySecret: dataplane-ansible-ssh-private-key-secret <7> + nodeTemplate: #<6> + ansibleSSHPrivateKeySecret: dataplane-ansible-ssh-private-key-secret #<7> managementNetwork: ctlplane ansible: - ansibleUser: cloud-admin <8> + ansibleUser: cloud-admin #<8> ansiblePort: 22 - ansibleVars: <9> + ansibleVars: #<9> service_net_map: nova_api_network: internal_api nova_libvirt_network: internal_api edpm_chrony_ntp_servers: - pool.ntp.org - edpm_network_config_template: | <10> + edpm_network_config_template: | #<10> --- {% set mtu_list = [ctlplane_mtu] %} {% for network in role_networks %} diff --git a/docs/docs_to_sample.sh b/docs/docs_to_sample.sh new file mode 100755 index 000000000..c11dc4337 --- /dev/null +++ b/docs/docs_to_sample.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +set -ex + +if [ $# -eq 0 ]; then + echo "Provide the adoc path" + exit 1 +fi + +echo "${1/adoc/yaml}" +sed '0,/----/d' $1 | sed -e '/----/,$d' > $2 diff --git a/tests/kuttl/tests/docs-test/00-assert.yaml b/tests/kuttl/tests/docs-test/00-assert.yaml new file mode 100644 index 000000000..7e1707324 --- /dev/null +++ b/tests/kuttl/tests/docs-test/00-assert.yaml @@ -0,0 +1,109 @@ +apiVersion: dataplane.openstack.org/v1beta1 +kind: OpenStackDataPlaneNodeSet +metadata: + name: openstack-edpm-ipam +spec: + env: + - name: ANSIBLE_FORCE_COLOR + value: "True" + nodes: + edpm-compute-0: + ansible: + ansibleHost: 192.168.122.100 + ansibleUser: cloud-admin + ansibleVars: + ctlplane_ip: 192.168.122.100 + fqdn_internalapi: edpm-compute-0.example.com + internalapi_ip: 172.17.0.100 + storage_ip: 172.18.0.100 + tenant_ip: 172.19.0.100 + hostName: edpm-compute-0 + nodeTemplate: + ansible: + ansiblePort: 22 + ansibleUser: cloud-admin + ansibleVars: + ctlplane_dns_nameservers: + - 192.168.122.1 + ctlplane_gateway_ip: 192.168.122.1 + ctlplane_host_routes: + - ip_netmask: 0.0.0.0/0 + next_hop: 192.168.122.1 + ctlplane_mtu: 1500 + ctlplane_cidr: 24 + dns_search_domains: [] + timesync_ntp_servers: + - hostname: clock.redhat.com + edpm_network_config_hide_sensitive_logs: false + edpm_nodes_validation_validate_controllers_icmp: false + edpm_nodes_validation_validate_gateway_icmp: false + edpm_selinux_mode: enforcing + edpm_sshd_allowed_ranges: + - 192.168.122.0/24 + edpm_sshd_configure_firewall: true + enable_debug: false + external_cidr: "24" + external_host_routes: [] + external_mtu: 1500 + external_vlan_id: 44 + gather_facts: false + internalapi_cidr: "24" + internalapi_host_routes: [] + internalapi_mtu: 1500 + internalapi_vlan_id: 20 + networks_lower: + External: external + InternalApi: internalapi + Storage: storage + Tenant: tenant + neutron_physical_bridge_name: br-ex + neutron_public_interface_name: eth0 + role_networks: + - InternalApi + - Storage + - Tenant + service_net_map: + nova_api_network: internalapi + nova_libvirt_network: internalapi + storage_cidr: "24" + storage_host_routes: [] + storage_mtu: 1500 + storage_vlan_id: 21 + tenant_cidr: "24" + tenant_host_routes: [] + tenant_mtu: 1500 + tenant_vlan_id: 22 + ansibleSSHPrivateKeySecret: dataplane-ansible-ssh-private-key-secret + managementNetwork: ctlplane + preProvisioned: true + services: + - download-cache + - bootstrap + - configure-network + - validate-network + - install-os + - configure-os + - run-os + - install-certs + - ovn + - neutron-metadata + - libvirt + - nova +status: + conditions: + - message: Deployment not started + reason: Requested + status: "False" + type: Ready + - message: Deployment not started + reason: Requested + status: "False" + type: DeploymentReady + - message: Input data complete + reason: Ready + status: "True" + type: InputReady + - message: Setup complete + reason: Ready + status: "True" + type: SetupReady diff --git a/tests/kuttl/tests/docs-test/00-doc-sample.yaml b/tests/kuttl/tests/docs-test/00-doc-sample.yaml new file mode 100644 index 000000000..be52e1a4f --- /dev/null +++ b/tests/kuttl/tests/docs-test/00-doc-sample.yaml @@ -0,0 +1,120 @@ +apiVersion: dataplane.openstack.org/v1beta1 +kind: OpenStackDataPlaneNodeSet +metadata: + name: openstack-edpm-ipam +spec: + env: #<1> + - name: ANSIBLE_FORCE_COLOR + value: "True" + preProvisioned: true #<2> + services: #<3> + - configure-network + - validate-network + - install-os + - configure-os + - run-os + - ovn + - libvirt + - nova + - telemetry + nodes: + edpm-compute-0: #<4> + hostName: edpm-compute-0 + ansible: + ansibleHost: 192.168.122.100 + networks: + - name: CtlPlane + subnetName: subnet1 + defaultRoute: true + fixedIP: 192.168.122.100 + - name: InternalApi + subnetName: subnet1 + - name: Storage + subnetName: subnet1 + - name: Tenant + subnetName: subnet1 + edpm-compute-1: + hostName: edpm-compute-1 + ansible: + ansibleHost: 192.168.122.101 + networks: + - name: CtlPlane + subnetName: subnet1 + defaultRoute: true + fixedIP: 192.168.122.101 + - name: InternalApi + subnetName: subnet1 + - name: Storage + subnetName: subnet1 + - name: Tenant + subnetName: subnet1 + networkAttachments: #<5> + - ctlplane + nodeTemplate: #<6> + ansibleSSHPrivateKeySecret: dataplane-ansible-ssh-private-key-secret #<7> + managementNetwork: ctlplane + ansible: + ansibleUser: cloud-admin #<8> + ansiblePort: 22 + ansibleVars: #<9> + service_net_map: + nova_api_network: internal_api + nova_libvirt_network: internal_api + edpm_chrony_ntp_servers: + - pool.ntp.org + edpm_network_config_template: | #<10> + --- + {% set mtu_list = [ctlplane_mtu] %} + {% for network in role_networks %} + {{ mtu_list.append(lookup('vars', networks_lower[network] ~ '_mtu')) }} + {%- endfor %} + {% set min_viable_mtu = mtu_list | max %} + network_config: + - type: ovs_bridge + name: {{ neutron_physical_bridge_name }} + mtu: {{ min_viable_mtu }} + use_dhcp: false + dns_servers: {{ ctlplane_dns_nameservers }} + domain: {{ dns_search_domains }} + addresses: + - ip_netmask: {{ ctlplane_ip }}/{{ ctlplane_subnet_cidr }} + routes: {{ ctlplane_host_routes }} + members: + - type: interface + name: nic1 + mtu: {{ min_viable_mtu }} + # force the MAC address of the bridge to this interface + primary: true + {% for network in role_networks %} + - type: vlan + mtu: {{ lookup('vars', networks_lower[network] ~ '_mtu') }} + vlan_id: {{ lookup('vars', networks_lower[network] ~ '_vlan_id') }} + addresses: + - ip_netmask: + {{ lookup('vars', networks_lower[network] ~ '_ip') }}/{{ lookup('vars', networks_lower[network] ~ '_cidr') }} + routes: {{ lookup('vars', networks_lower[network] ~ '_host_routes') }} + {% endfor %} + edpm_network_config_hide_sensitive_logs: false + # These vars are for the network config templates themselves and are + # considered EDPM network defaults. + neutron_physical_bridge_name: br-ex + neutron_public_interface_name: eth0 + role_networks: + - InternalApi + - Storage + - Tenant + networks_lower: + External: external + InternalApi: internal_api + Storage: storage + Tenant: tenant + # edpm_nodes_validation + edpm_nodes_validation_validate_controllers_icmp: false + edpm_nodes_validation_validate_gateway_icmp: false + gather_facts: false + enable_debug: false + # edpm firewall, change the allowed CIDR if needed + edpm_sshd_configure_firewall: true + edpm_sshd_allowed_ranges: ['192.168.122.0/24'] + # SELinux module + edpm_selinux_mode: enforcing