Merge "[fdio] salt-formula-neutron: Fix VPP support patch"
[fuel.git] / mcp / patches / salt-formula-linux / 0001-Set-ovs-bridges-as-L3-interfaces.patch
1 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
2 : Copyright (c) 2019 Mirantis Inc., Enea AB and others.
3 :
4 : All rights reserved. This program and the accompanying materials
5 : are made available under the terms of the Apache License, Version 2.0
6 : which accompanies this distribution, and is available at
7 : http://www.apache.org/licenses/LICENSE-2.0
8 ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
9 From: Michael Polenchuk <mpolenchuk@mirantis.com>
10 Date: Wed, 28 Feb 2018 17:54:28 +0400
11 Subject: [PATCH] Set ovs bridges as L3 interfaces
12
13 ---
14  linux/files/ovs_bridge      | 22 ++++++++++++++++++++++
15  linux/files/ovs_port        |  8 +++++++-
16  linux/network/interface.sls | 34 +++++++++++++++++++++++++++++++++-
17  3 files changed, 62 insertions(+), 2 deletions(-)
18  create mode 100644 linux/files/ovs_bridge
19
20 diff --git a/linux/files/ovs_bridge b/linux/files/ovs_bridge
21 new file mode 100644
22 index 0000000..4718b91
23 --- /dev/null
24 +++ b/linux/files/ovs_bridge
25 @@ -0,0 +1,22 @@
26 +# With systemd, adding OVS bridges as 'auto' can cause race conditions
27 +# https://github.com/openvswitch/ovs/blob/master/debian/openvswitch-switch.README.Debian
28 +# auto {{ bridge_name }}
29 +allow-ovs {{ bridge_name }}
30 +iface {{ bridge_name }} inet {{ bridge.get('proto', 'static' if bridge.address is defined else 'manual') }}
31 +  ovs_type OVSBridge
32 +  {%- if bridge.address is defined %}
33 +  address {{ bridge.address }}
34 +  netmask {{ bridge.netmask }}
35 +  {%- endif %}
36 +  {%- if bridge.use_interfaces is defined %}
37 +  ovs_ports {{ bridge.use_interfaces|join(' ') }}
38 +  {%- endif %}
39 +  {%- if bridge.datapath_type is defined %}
40 +  ovs_extra set Bridge ${IFACE} datapath_type={{ bridge.datapath_type }}
41 +  {%- endif %}
42 +  {%- if bridge.gateway is defined %}
43 +  gateway {{ bridge.gateway }}
44 +  {%- endif %}
45 +  {%- if bridge.name_servers is defined %}
46 +  dns-nameservers {{ bridge.name_servers | join(' ') }}
47 +  {%- endif %}
48 diff --git a/linux/files/ovs_port b/linux/files/ovs_port
49 index 222ca8e..41821b7 100644
50 --- a/linux/files/ovs_port
51 +++ b/linux/files/ovs_port
52 @@ -1,6 +1,12 @@
53 -auto {{ port_name }}
54 +# With systemd, adding OVS bridges as 'auto' can cause race conditions
55 +# https://github.com/openvswitch/ovs/blob/master/debian/openvswitch-switch.README.Debian
56 +# OVS ports will be automatically ifup-ed when ifup-ing the OVS bridge
57 +# auto {{ port_name }}
58  allow-{{ port.bridge }} {{ port_name }}
59  iface {{ port_name }} inet {{ port.get('proto', 'manual') }}
60 +{%- if '.' in port_name %}
61 +vlan-raw-device {{ port_name.split('.')[0] }}
62 +{%- endif %}
63  ovs_type {{ port.get('ovs_port_type', 'OVSIntPort') }}
64  mtu {{ port.get('mtu', '1500') }}
65  ovs_bridge {{ port.bridge }}
66 diff --git a/linux/network/interface.sls b/linux/network/interface.sls
67 index a39fc37..8bce092 100644
68 --- a/linux/network/interface.sls
69 +++ b/linux/network/interface.sls
70 @@ -92,6 +92,35 @@ add_int_{{ int_name }}_to_ovs_dpdk_bridge_{{ interface_name }}:
71  ovs_bridge_{{ interface_name }}:
72    openvswitch_bridge.present:
73    - name: {{ interface_name }}
74 +  file.managed:
75 +  - name: /etc/network/interfaces.u/ifcfg-{{ interface_name }}
76 +  - makedirs: True
77 +  - source: salt://linux/files/ovs_bridge
78 +  - defaults:
79 +      bridge: {{ interface|yaml }}
80 +      bridge_name: {{ interface_name }}
81 +  - template: jinja
82 +
83 +linux_interfaces_include_{{ interface_name }}:
84 +  file.prepend:
85 +  - name: /etc/network/interfaces
86 +  - text: |
87 +      source /etc/network/interfaces.d/*
88 +      # Workaround for Upstream-Bug: https://github.com/saltstack/salt/issues/40262
89 +      source /etc/network/interfaces.u/*
90 +
91 +ovs_bridge_up_{{ interface_name }}:
92 +  cmd.run:
93 +  - name: ifup --ignore-errors {{ interface_name }}
94 +  - require:
95 +    - file: ovs_bridge_{{ interface_name }}
96 +    - openvswitch_bridge: ovs_bridge_{{ interface_name }}
97 +    - file: linux_interfaces_final_include
98 +  {%- if network.noifupdown|d(false) or interface.noifupdown|d(false) %}
99 +  - onlyif: /bin/false
100 +  {%- else %}
101 +  - unless: grep -qFx up /sys/class/net/{{ interface_name }}/operstate
102 +  {%- endif %}
103
104  {# add linux network interface into OVS bridge #}
105  {%- for int_name, int in network.interface.items() %}
106 @@ -102,7 +131,7 @@ ovs_bridge_{{ interface_name }}:
107
108  add_int_{{ int_name }}_to_ovs_bridge_{{ interface_name }}:
109    cmd.run:
110 -    - unless: ovs-vsctl show | grep {{ int_name }}
111 +    - unless: ovs-vsctl list-ports {{ interface_name }} | grep -qFx {{ int_name }}
112      - name: ovs-vsctl{%- if network.ovs_nowait %} --no-wait{%- endif %} add-port {{ interface_name }} {{ int_name }}
113
114  {%- endif %}
115 @@ -176,6 +205,9 @@ ovs_port_{{ interface_name }}_line2:
116  ovs_port_up_{{ interface_name }}:
117    cmd.run:
118    - name: ifup {{ interface_name }}
119 +  {%- if network.noifupdown|d(false) or interface.noifupdown|d(false) %}
120 +  - onlyif: /bin/false
121 +  {%- endif %}
122    - require:
123      - file: ovs_port_{{ interface_name }}
124      - file: ovs_port_{{ interface_name }}_line1