From fc72887d319227ee37f56379661cb6965e684e5a Mon Sep 17 00:00:00 2001
From: Piotr Parczewski <piotr@stackhpc.com>
Date: Fri, 5 Feb 2021 11:34:30 +0100
Subject: [PATCH] Add Neutron DHCP agent to OVN networking setup
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This commit adds possibility to deploy Neutron's DHCP agents in OVN
networking scenario.

Co-Authored-By: MichaƂ Nasiadka <mnasiadka@gmail.com>

Change-Id: I073d04319b510182f5c1478e728c0c5bcc8799f1
---
 ansible/roles/neutron/defaults/main.yml              |  7 ++++++-
 ansible/roles/neutron/templates/neutron.conf.j2      |  2 +-
 doc/source/reference/networking/neutron.rst          | 12 ++++++++++++
 etc/kolla/globals.yml                                |  3 +++
 .../ovn-neutron-dhcp-agent-21aaafe5e1cda501.yaml     |  6 ++++++
 5 files changed, 28 insertions(+), 2 deletions(-)
 create mode 100644 releasenotes/notes/ovn-neutron-dhcp-agent-21aaafe5e1cda501.yaml

diff --git a/ansible/roles/neutron/defaults/main.yml b/ansible/roles/neutron/defaults/main.yml
index 7e46c4326e..09bb89fb81 100644
--- a/ansible/roles/neutron/defaults/main.yml
+++ b/ansible/roles/neutron/defaults/main.yml
@@ -71,7 +71,7 @@ neutron_services:
     container_name: "neutron_dhcp_agent"
     image: "{{ neutron_dhcp_agent_image_full }}"
     privileged: True
-    enabled: "{{ neutron_plugin_agent not in ['ovn', 'vmware_nsxv', 'vmware_nsxv3'] }}"
+    enabled: "{{ neutron_plugin_agent not in ['ovn', 'vmware_nsxv', 'vmware_nsxv3'] or neutron_ovn_dhcp_agent | bool }}"
     group: "neutron-dhcp-agent"
     host_in_groups: "{{ inventory_hostname in groups['neutron-dhcp-agent'] }}"
     volumes: "{{ neutron_dhcp_agent_default_volumes + neutron_dhcp_agent_extra_volumes }}"
@@ -730,6 +730,11 @@ notification_drivers: []
 
 neutron_notification_drivers: "{{ notification_drivers | selectattr('enabled', 'equalto', true) | list }}"
 
+######################
+# OVN
+######################
+neutron_ovn_dhcp_agent: "no"
+
 ####################
 # Kolla
 ####################
diff --git a/ansible/roles/neutron/templates/neutron.conf.j2 b/ansible/roles/neutron/templates/neutron.conf.j2
index f63dbac96f..4766a20b74 100644
--- a/ansible/roles/neutron/templates/neutron.conf.j2
+++ b/ansible/roles/neutron/templates/neutron.conf.j2
@@ -27,7 +27,7 @@ rpc_state_report_workers = {{ openstack_service_rpc_workers }}
 # in it is because we are sharing this socket in a volume which is it's own dir
 metadata_proxy_socket = /var/lib/neutron/kolla/metadata_proxy
 
-{% if neutron_plugin_agent == "openvswitch" %}
+{% if neutron_plugin_agent == "openvswitch" or (neutron_plugin_agent == "ovn" and neutron_ovn_dhcp_agent | bool) %}
 interface_driver = openvswitch
 {% elif neutron_plugin_agent == "linuxbridge" %}
 interface_driver = linuxbridge
diff --git a/doc/source/reference/networking/neutron.rst b/doc/source/reference/networking/neutron.rst
index 7747956332..b96d39503e 100644
--- a/doc/source/reference/networking/neutron.rst
+++ b/doc/source/reference/networking/neutron.rst
@@ -80,6 +80,18 @@ To change this behaviour you need to set the following:
 
    neutron_ovn_distributed_fip: "yes"
 
+Similarly - in order to have Neutron DHCP agents deployed in OVN networking
+scenario, use:
+
+.. path /etc/kolla/globals.yml
+.. code-block:: yaml
+
+   neutron_ovn_dhcp_agent: "yes"
+
+This might be desired for example when Ironic bare metal nodes are
+used as a compute service. Currently OVN is not able to answer DHCP
+queries on port type external, this is where Neutron agent helps.
+
 Mellanox Infiniband (ml2/mlnx)
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
diff --git a/etc/kolla/globals.yml b/etc/kolla/globals.yml
index 198cf87e90..cf16376843 100644
--- a/etc/kolla/globals.yml
+++ b/etc/kolla/globals.yml
@@ -556,6 +556,9 @@
 # Enable distributed floating ip for OVN deployments
 #neutron_ovn_distributed_fip: "no"
 
+# Enable DHCP agent(s) to use with OVN
+#neutron_ovn_dhcp_agent: "no"
+
 #############################
 # Horizon - Dashboard Options
 #############################
diff --git a/releasenotes/notes/ovn-neutron-dhcp-agent-21aaafe5e1cda501.yaml b/releasenotes/notes/ovn-neutron-dhcp-agent-21aaafe5e1cda501.yaml
new file mode 100644
index 0000000000..976f0c7191
--- /dev/null
+++ b/releasenotes/notes/ovn-neutron-dhcp-agent-21aaafe5e1cda501.yaml
@@ -0,0 +1,6 @@
+---
+features:
+  - |
+    It is now possible to use Neutron DHCP agent together with OVN
+    networking. New variable is added to control this feature:
+    ``neutron_ovn_dhcp_agent``, defaulting to ``no``.