Skip to content

Commit 70721d5

Browse files
committed
Add a custom playbook to fix OVN chassis priorities
Sometimes, typically after restarting OVN services, the priorities of entries in the ha_chassis and gateway_chassis tables in the OVN northbound database can become misaligned. This results in broken routing for external (bare metal/SR-IOV) ports. This playbook can be used to fix the issue by realigning the priorities of the table entries. It does so by assigning the highest priority to the "first" (sorted alphabetically) OVN NB DB host. This results in all gateways being scheduled to a single host, but is less complicated than trying to balance them (and it's also not clear to me how to map between individual ha_chassis and gateway_chassis entries). The playbook can be run as follows: kayobe playbook run $KAYOBE_CONFIG_PATH/ansible/ovn-fix-chassis-priorities.yml If the 'controllers' group does not align with the group used to deploy the OVN NB DB, this can be overridden by passing the following: '-e ovn_nb_db_group=some_other_group'
1 parent ef4cabe commit 70721d5

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
---
2+
# Sometimes, typically after restarting OVN services, the priorities of entries
3+
# in the ha_chassis and gateway_chassis tables in the OVN northbound database
4+
# can become misaligned. This results in broken routing for external (bare
5+
# metal/SR-IOV) ports.
6+
7+
# This playbook can be used to fix the issue by realigning the priorities of
8+
# the table entries. It does so by assigning the highest priority to the
9+
# "first" (sorted alphabetically) OVN NB DB host. This results in all gateways
10+
# being scheduled to a single host, but is less complicated than trying to
11+
# balance them (and it's also not clear to me how to map between individual
12+
# ha_chassis and gateway_chassis entries).
13+
14+
# The playbook can be run as follows:
15+
# kayobe playbook run $KAYOBE_CONFIG_PATH/ansible/ovn-fix-chassis-priorities.yml
16+
17+
# If the 'controllers' group does not align with the group used to deploy the
18+
# OVN NB DB, this can be overridden by passing the following:
19+
# '-e ovn_nb_db_group=some_other_group'
20+
21+
- name: Find OVN DB DB Leader
22+
hosts: "{{ ovn_nb_db_group | default('controllers') }}"
23+
tasks:
24+
- name: Find the OVN NB DB leader
25+
command: docker exec -it ovn_nb_db ovn-nbctl get-connection
26+
changed_when: false
27+
failed_when: false
28+
register: ovn_check_result
29+
check_mode: no
30+
31+
- name: Group hosts by leader/follower role
32+
group_by:
33+
key: "ovn_nb_{{ 'leader' if ovn_check_result.rc == 0 else 'follower' }}"
34+
changed_when: false
35+
36+
- name: Assert one leader exists
37+
assert:
38+
that:
39+
- groups['ovn_nb_leader'] | default([]) | length == 1
40+
41+
- name: Fix OVN chassis priorities
42+
hosts: ovn_nb_leader
43+
vars:
44+
ovn_nb_db_group: controllers
45+
ovn_nb_db_hosts_sorted: "{{ query('inventory_hostnames', ovn_nb_db_group) | sort | list }}"
46+
ha_chassis_max_priority: 32767
47+
# We've always used priority 5 for the winner in habrok, so didn't want to
48+
# change this, but strictly the +2 isn't necessary.
49+
gateway_chassis_max_priority: "{{ ovn_nb_db_hosts_sorted | length + 2 }}"
50+
tasks:
51+
- name: Fix ha_chassis priorities
52+
command: >-
53+
docker exec -it ovn_nb_db
54+
bash -c '
55+
ovn-nbctl find ha_chassis chassis_name={{ item }} |
56+
awk '\''$1 == "_uuid" { print $3 }'\'' |
57+
while read uuid; do ovn-nbctl set ha_chassis $uuid priority={{ priority }}; done'
58+
loop: "{{ ovn_nb_db_hosts_sorted }}"
59+
vars:
60+
priority: "{{ ha_chassis_max_priority | int - ovn_nb_db_hosts_sorted.index(item) }}"
61+
62+
- name: Fix gateway_chassis priorities
63+
command: >-
64+
docker exec -it ovn_nb_db
65+
bash -c '
66+
ovn-nbctl find gateway_chassis chassis_name={{ item }} |
67+
awk '\''$1 == "_uuid" { print $3 }'\'' |
68+
while read uuid; do ovn-nbctl set gateway_chassis $uuid priority={{ priority }}; done'
69+
loop: "{{ ovn_nb_db_hosts_sorted }}"
70+
vars:
71+
priority: "{{ gateway_chassis_max_priority | int - ovn_nb_db_hosts_sorted.index(item) }}"

0 commit comments

Comments
 (0)