From bdd98eca87890666f66b8b3d920f7ce0948ace44 Mon Sep 17 00:00:00 2001 From: Michal Nasiadka Date: Thu, 10 Jul 2025 11:14:36 +0200 Subject: ovn-db: Add OVN_NB_DB and OVN_SB_DB env variables MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It will make running ovn-nbctl and ovn-sbctl working on all nodes irrespective of their cluster role. Excerpt from ovn-nbctl: --db database The OVSDB database remote to contact. If the OVN_NB_DB en‐ vironment variable is set, its value is used as the de‐ fault. Otherwise, the default is unix:/ovnnb_db.sock, but this default is unlikely to be useful outside of single-ma‐ chine OVN test environments. Closes-Bug: #2116313 Change-Id: I85f7bfd0aaa6f2d426ddb28950acbbca9d385aac Signed-off-by: Michal Nasiadka --- ansible/roles/ovn-db/defaults/main.yml | 7 ++++++ ansible/roles/ovn-db/handlers/main.yml | 3 +++ ansible/roles/ovn-db/tasks/bootstrap-db.yml | 8 ++++-- doc/source/reference/networking/neutron.rst | 7 ++++++ .../notes/ovn-env-variables-b622b4c53ee275f4.yaml | 6 +++++ tests/run.yml | 1 + tests/test-ovn.sh | 29 +++++++++++++++++++--- 7 files changed, 55 insertions(+), 6 deletions(-) create mode 100644 releasenotes/notes/ovn-env-variables-b622b4c53ee275f4.yaml diff --git a/ansible/roles/ovn-db/defaults/main.yml b/ansible/roles/ovn-db/defaults/main.yml index 18e999e1e..0bc27949b 100644 --- a/ansible/roles/ovn-db/defaults/main.yml +++ b/ansible/roles/ovn-db/defaults/main.yml @@ -4,6 +4,9 @@ ovn_db_services: container_name: ovn_northd group: ovn-northd enabled: true + environment: + OVN_NB_DB: "{{ ovn_nb_connection }}" + OVN_SB_DB: "{{ ovn_sb_connection_no_relay }}" image: "{{ ovn_northd_image_full }}" volumes: "{{ ovn_northd_default_volumes + ovn_northd_extra_volumes }}" dimensions: "{{ ovn_northd_dimensions }}" @@ -11,6 +14,8 @@ ovn_db_services: container_name: ovn_nb_db group: ovn-nb-db enabled: true + environment: + OVN_NB_DB: "{{ ovn_nb_connection }}" image: "{{ ovn_nb_db_image_full }}" volumes: "{{ ovn_nb_db_default_volumes + ovn_nb_db_extra_volumes }}" dimensions: "{{ ovn_nb_db_dimensions }}" @@ -18,6 +23,8 @@ ovn_db_services: container_name: ovn_sb_db group: ovn-sb-db enabled: true + environment: + OVN_SB_DB: "{{ ovn_sb_connection_no_relay }}" image: "{{ ovn_sb_db_image_full }}" volumes: "{{ ovn_sb_db_default_volumes + ovn_sb_db_extra_volumes }}" dimensions: "{{ ovn_sb_db_dimensions }}" diff --git a/ansible/roles/ovn-db/handlers/main.yml b/ansible/roles/ovn-db/handlers/main.yml index 76c04399f..128659c7a 100644 --- a/ansible/roles/ovn-db/handlers/main.yml +++ b/ansible/roles/ovn-db/handlers/main.yml @@ -7,6 +7,7 @@ kolla_container: action: "recreate_or_restart_container" common_options: "{{ docker_common_options }}" + environment: "{{ service.environment }}" name: "{{ service.container_name }}" image: "{{ service.image }}" volumes: "{{ service.volumes | reject('equalto', '') | list }}" @@ -20,6 +21,7 @@ kolla_container: action: "recreate_or_restart_container" common_options: "{{ docker_common_options }}" + environment: "{{ service.environment }}" name: "{{ service.container_name }}" image: "{{ service.image }}" volumes: "{{ service.volumes | reject('equalto', '') | list }}" @@ -48,6 +50,7 @@ kolla_container: action: "recreate_or_restart_container" common_options: "{{ docker_common_options }}" + environment: "{{ service.environment }}" name: "{{ service.container_name }}" image: "{{ service.image }}" volumes: "{{ service.volumes | reject('equalto', '') | list }}" diff --git a/ansible/roles/ovn-db/tasks/bootstrap-db.yml b/ansible/roles/ovn-db/tasks/bootstrap-db.yml index 79bace7b6..d325ca9ac 100644 --- a/ansible/roles/ovn-db/tasks/bootstrap-db.yml +++ b/ansible/roles/ovn-db/tasks/bootstrap-db.yml @@ -24,7 +24,9 @@ become: true command: >- {{ kolla_container_engine }} exec ovn_nb_db - ovn-nbctl --inactivity-probe={{ ovn_nb_db_inactivity_probe }} + ovn-nbctl + --db unix:/var/run/ovn/ovnnb_db.sock + --inactivity-probe={{ ovn_nb_db_inactivity_probe }} set-connection ptcp:{{ ovn_nb_db_port }}:0.0.0.0 register: ovn_nb_set_connection_result retries: 3 @@ -47,7 +49,9 @@ become: true command: >- {{ kolla_container_engine }} exec ovn_sb_db - ovn-sbctl --inactivity-probe={{ ovn_sb_db_inactivity_probe }} + ovn-sbctl + --db unix:/var/run/ovn/ovnsb_db.sock + --inactivity-probe={{ ovn_sb_db_inactivity_probe }} set-connection ptcp:{{ ovn_sb_db_port }}:0.0.0.0 register: ovn_sb_set_connection_result retries: 3 diff --git a/doc/source/reference/networking/neutron.rst b/doc/source/reference/networking/neutron.rst index 0dae7dcb6..01ce34044 100644 --- a/doc/source/reference/networking/neutron.rst +++ b/doc/source/reference/networking/neutron.rst @@ -279,6 +279,13 @@ In order to deploy Neutron OVN Agent you need to set the following: Currently the agent is only needed for QoS for hardware offloaded ports. +When in need of running `ovn-nbctl` or `ovn-sbctl` commands it's most +convenient to run them from ``ovn_northd`` container: + +.. code-block:: console + + docker exec ovn_northd ovn-nbctl show + Mellanox Infiniband (ml2/mlnx) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/releasenotes/notes/ovn-env-variables-b622b4c53ee275f4.yaml b/releasenotes/notes/ovn-env-variables-b622b4c53ee275f4.yaml new file mode 100644 index 000000000..69f2665c3 --- /dev/null +++ b/releasenotes/notes/ovn-env-variables-b622b4c53ee275f4.yaml @@ -0,0 +1,6 @@ +--- +features: + - | + The OVN container images (``ovn-nb-db``, ``ovn-northd`` and ``ovn-sb-db``) + have now default environment variables in place that ease running of + ``ovn-nbctl`` and ``ovn-sbctl`` commands for operators. diff --git a/tests/run.yml b/tests/run.yml index eca77e215..b0736c807 100644 --- a/tests/run.yml +++ b/tests/run.yml @@ -440,6 +440,7 @@ when: scenario == "ovn" environment: CONTAINER_ENGINE: "{{ container_engine }}" + IS_UPGRADE: "{{ is_upgrade | bool | ternary('yes', 'no') }}" - name: Run test-core-openstack.sh script script: diff --git a/tests/test-ovn.sh b/tests/test-ovn.sh index a9d77a95a..a48fb1161 100755 --- a/tests/test-ovn.sh +++ b/tests/test-ovn.sh @@ -15,10 +15,20 @@ function test_ovn { # List OVN NB/SB entries echo "OVN NB DB entries:" - sudo ${container_engine} exec ovn_northd ovn-nbctl --db "$ovn_nb_connection" show + # TODO(mnasiadka): Remove the first part of conditional in G cycle + if [ $IS_UPGRADE == "yes" ]; then + sudo ${container_engine} exec ovn_northd ovn-nbctl --db "$ovn_nb_connection" show + else + sudo ${container_engine} exec ovn_northd ovn-nbctl show + fi echo "OVN SB DB entries:" - sudo ${container_engine} exec ovn_northd ovn-sbctl --db "$ovn_sb_connection" show + # TODO(mnasiadka): Remove the first part of conditional in G cycle + if [ $IS_UPGRADE == "yes" ]; then + sudo ${container_engine} exec ovn_northd ovn-sbctl --db "$ovn_sb_connection" show + else + sudo ${container_engine} exec ovn_northd ovn-sbctl show + fi OVNNB_STATUS=$(sudo ${container_engine} exec ovn_nb_db ovs-appctl -t /var/run/ovn/ovnnb_db.ctl cluster/status OVN_Northbound) OVNSB_STATUS=$(sudo ${container_engine} exec ovn_sb_db ovs-appctl -t /var/run/ovn/ovnsb_db.ctl cluster/status OVN_Southbound) @@ -92,9 +102,20 @@ function test_octavia { openstack floating ip set $lb_fip --port $lb_port_id echo "OVN NB entries for LB:" - sudo ${container_engine} exec ovn_northd ovn-nbctl --db "$ovn_nb_connection" list load_balancer + # TODO(mnasiadka): Remove the first part of conditional in G cycle + if [ $IS_UPGRADE == "yes" ]; then + sudo ${container_engine} exec ovn_northd ovn-nbctl --db "$ovn_nb_connection" list load_balancer + else + sudo ${container_engine} exec ovn_northd ovn-nbctl list load_balancer + fi + echo "OVN NB entries for NAT:" - sudo ${container_engine} exec ovn_northd ovn-nbctl --db "$ovn_nb_connection" list nat + # TODO(mnasiadka): Remove the first part of conditional in G cycle + if [ $IS_UPGRADE == "yes" ]; then + sudo ${container_engine} exec ovn_northd ovn-nbctl --db "$ovn_nb_connection" list nat + else + sudo ${container_engine} exec ovn_northd ovn-nbctl list nat + fi echo "Attempt to access the load balanced HTTP server." attempts=12 -- cgit v1.2.3