[patch] Avoid ifup run if noifupdown is turned on
[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 diff --git a/linux/files/ovs_bridge b/linux/files/ovs_bridge
14 new file mode 100644
15 index 0000000..d33864c
16 --- /dev/null
17 +++ b/linux/files/ovs_bridge
18 @@ -0,0 +1,18 @@
19 +auto {{ bridge_name }}
20 +allow-ovs {{ bridge_name }}
21 +iface {{ bridge_name }} inet static
22 +  ovs_type OVSBridge
23 +  address {{ bridge.address }}
24 +  netmask {{ bridge.netmask }}
25 +  {%- if bridge.use_interfaces is defined %}
26 +  ovs_ports {{ bridge.use_interfaces|join(' ') }}
27 +  {%- endif %}
28 +  {%- if bridge.datapath_type is defined %}
29 +  ovs_extra set Bridge ${IFACE} datapath_type={{ bridge.datapath_type }}
30 +  {%- endif %}
31 +  {%- if bridge.gateway is defined %}
32 +  gateway {{ bridge.gateway }}
33 +  {%- endif %}
34 +  {%- if bridge.name_servers is defined %}
35 +  dns-nameservers {{ bridge.name_servers | join(' ') }}
36 +  {%- endif %}
37 diff --git a/linux/files/ovs_port b/linux/files/ovs_port
38 index 222ca8e..03072cd 100644
39 --- a/linux/files/ovs_port
40 +++ b/linux/files/ovs_port
41 @@ -1,6 +1,11 @@
42 -auto {{ port_name }}
43 +# With systemd, adding OVS bridges as 'auto' can cause race conditions
44 +# https://github.com/openvswitch/ovs/blob/master/debian/openvswitch-switch.README.Debian
45 +# auto {{ port_name }}
46  allow-{{ port.bridge }} {{ port_name }}
47  iface {{ port_name }} inet {{ port.get('proto', 'manual') }}
48 +{%- if '.' in port_name %}
49 +vlan-raw-device {{ port_name.split('.')[0] }}
50 +{%- endif %}
51  ovs_type {{ port.get('ovs_port_type', 'OVSIntPort') }}
52  mtu {{ port.get('mtu', '1500') }}
53  ovs_bridge {{ port.bridge }}
54 diff --git a/linux/network/interface.sls b/linux/network/interface.sls
55 index a39fc37..c4a94a3 100644
56 --- a/linux/network/interface.sls
57 +++ b/linux/network/interface.sls
58 @@ -92,6 +92,37 @@ add_int_{{ int_name }}_to_ovs_dpdk_bridge_{{ interface_name }}:
59  ovs_bridge_{{ interface_name }}:
60    openvswitch_bridge.present:
61    - name: {{ interface_name }}
62 +{%- if interface.get('proto', 'manual') == 'static' %}
63 +  file.managed:
64 +  - name: /etc/network/interfaces.u/ifcfg-{{ interface_name }}
65 +  - makedirs: True
66 +  - source: salt://linux/files/ovs_bridge
67 +  - defaults:
68 +      bridge: {{ interface|yaml }}
69 +      bridge_name: {{ interface_name }}
70 +  - template: jinja
71 +
72 +linux_interfaces_include_{{ interface_name }}:
73 +  file.prepend:
74 +  - name: /etc/network/interfaces
75 +  - text: |
76 +      source /etc/network/interfaces.d/*
77 +      # Workaround for Upstream-Bug: https://github.com/saltstack/salt/issues/40262
78 +      source /etc/network/interfaces.u/*
79 +
80 +ovs_bridge_up_{{ interface_name }}:
81 +  cmd.run:
82 +  - name: ifup --ignore-errors {{ interface_name }}
83 +  - require:
84 +    - file: ovs_bridge_{{ interface_name }}
85 +    - openvswitch_bridge: ovs_bridge_{{ interface_name }}
86 +    - file: linux_interfaces_final_include
87 +  {%- if network.noifupdown|d(false) or interface.noifupdown|d(false) %}
88 +  - onlyif: /bin/false
89 +  {%- else %}
90 +  - unless: ip link show {{ interface_name }} | grep -q '\<UP\>'
91 +  {%- endif %}
92 +{%- endif %}
93
94  {# add linux network interface into OVS bridge #}
95  {%- for int_name, int in network.interface.items() %}
96 @@ -176,6 +207,9 @@ ovs_port_{{ interface_name }}_line2:
97  ovs_port_up_{{ interface_name }}:
98    cmd.run:
99    - name: ifup {{ interface_name }}
100 +  {%- if network.noifupdown|d(false) or interface.noifupdown|d(false) %}
101 +  - onlyif: /bin/false
102 +  {%- endif %}
103    - require:
104      - file: ovs_port_{{ interface_name }}
105      - file: ovs_port_{{ interface_name }}_line1