Browse Source

Convert test network setup to use the networkd role

The test network setup was using the legacy interface configs and
providing an inconsistent experience. These changes will pull it in plce
with the intergrated repo for all of our distros giving us a very
consistent experience.

Change-Id: I637b048b8c8a3fb44f91e4227a02787eacd32b57
Signed-off-by: Kevin Carter <kevin.carter@rackspace.com>
Kevin Carter 8 months ago
parent
commit
fe6c8344d1
No account linked to committer's email address

+ 0
- 27
network_interfaces/debian_interface_default.cfg.j2 View File

@@ -1,27 +0,0 @@
1
-auto {{ item.name | default('br-mgmt') }}
2
-iface {{ item.name | default('br-mgmt') }} inet static
3
-    bridge_stp off
4
-    bridge_waitport 0
5
-    bridge_fd 0
6
-    # Notice the bridge port is the vlan tagged interface
7
-    address {{ item.ip_addr | default('10.1.0.1') }}
8
-    netmask {{ item.netmask | default('255.255.255.0') }}
9
-    offload-sg off
10
-{% if item.veth_peer is defined %}
11
-    # Create veth pair, don't bomb if already exists
12
-    pre-up ip link add {{ item.name | default('br-mgmt') }}-veth type veth peer name {{ item.veth_peer | default('eth1') }} || true
13
-    # Set both ends UP
14
-    pre-up ip link set {{ item.name | default('br-mgmt') }}-veth up
15
-    pre-up ip link set {{ item.veth_peer | default('eth1') }} up
16
-    # Delete veth pair on DOWN
17
-    post-down ip link del {{ item.name | default('br-mgmt') }}-veth || true
18
-    bridge_ports {{ item.name | default('br-mgmt') }}-veth
19
-{% else %}
20
-    bridge_ports none
21
-{% endif %}
22
-
23
-{% if item.alias is defined %}
24
-iface {{ item.name | default('br-mgmt') }} inet static
25
-    address {{ item.alias }}
26
-    netmask {{ item.netmask | default('255.255.255.0') }}
27
-{% endif %}

+ 0
- 5
network_interfaces/redhat_interface_alias.cfg.j2 View File

@@ -1,5 +0,0 @@
1
-# This interface is an alias
2
-DEVICE={{ item.name | default('br-mgmt') }}:0
3
-IPADDR={{ item.alias | default('10.1.0.1') }}
4
-NETMASK={{ item.netmask | default('255.255.255.0') }}
5
-ONBOOT=yes

+ 0
- 12
network_interfaces/redhat_interface_default.cfg.j2 View File

@@ -1,12 +0,0 @@
1
-{% if item.veth_peer is defined %}
2
-# This interface has a veth peer
3
-{% endif %}
4
-DEVICE={{ item.name | default('br-mgmt') }}
5
-TYPE=Bridge
6
-IPADDR={{ item.ip_addr | default('10.1.0.1') }}
7
-NETMASK={{ item.netmask | default('255.255.255.0') }}
8
-ONBOOT=yes
9
-BOOTPROTO=none
10
-NM_CONTROLLED=no
11
-DELAY=0
12
-ETHTOOL_OPTS="-K ${DEVICE} sg off"

+ 0
- 29
network_interfaces/rpm_interface_ifdown-post.cfg.j2 View File

@@ -1,29 +0,0 @@
1
-#!/usr/bin/env bash
2
-# Copyright 2014, Rackspace US, Inc.
3
-#
4
-# Licensed under the Apache License, Version 2.0 (the "License");
5
-# you may not use this file except in compliance with the License.
6
-# You may obtain a copy of the License at
7
-#
8
-#     http://www.apache.org/licenses/LICENSE-2.0
9
-#
10
-# Unless required by applicable law or agreed to in writing, software
11
-# distributed under the License is distributed on an "AS IS" BASIS,
12
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
-# See the License for the specific language governing permissions and
14
-# limitations under the License.
15
-
16
-source /etc/os-release || source /usr/lib/os-release
17
-
18
-case "${ID}" in
19
-    *suse*) INTERFACE="${1}"; ;;
20
-    centos|rhel|fedora) INTERFACE="${DEVICE}"; ;;
21
-    *) echo "Unsupported distribution ${ID}"; exit 1;
22
-esac
23
-
24
-_ip=$(which ip 2>/dev/null || { echo "Failed to find ip executable"; exit 1; })
25
-
26
-if [ "${INTERFACE}" == "{{ item[1].name | default('br-mgmt') }}" ]; then
27
-    eval $_ip link set {{ item[1].name | default('br-mgmt') }}-veth nomaster || true
28
-    eval $_ip link del {{ item[1].name | default('br-mgmt') }}-veth || true
29
-fi

+ 0
- 36
network_interfaces/rpm_interface_ifup-post.cfg.j2 View File

@@ -1,36 +0,0 @@
1
-#!/usr/bin/env bash
2
-# Copyright 2014, Rackspace US, Inc.
3
-# Copyright 2017, SUSE LINUX GmbH.
4
-#
5
-# Licensed under the Apache License, Version 2.0 (the "License");
6
-# you may not use this file except in compliance with the License.
7
-# You may obtain a copy of the License at
8
-#
9
-#     http://www.apache.org/licenses/LICENSE-2.0
10
-#
11
-# Unless required by applicable law or agreed to in writing, software
12
-# distributed under the License is distributed on an "AS IS" BASIS,
13
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
-# See the License for the specific language governing permissions and
15
-# limitations under the License.
16
-
17
-source /etc/os-release || source /usr/lib/os-release
18
-
19
-case "${ID}" in
20
-    *suse*) INTERFACE="${1}"; ;;
21
-    centos|rhel|fedora) INTERFACE="${DEVICE}"; ;;
22
-    *) echo "Unsupported distribution ${ID}"; exit 1;
23
-esac
24
-
25
-_ip=$(which ip 2>/dev/null || { echo "Failed to find ip executable"; exit 1; })
26
-
27
-if [ "${INTERFACE}" == "{{ item[1].name | default('br-mgmt') }}" ]; then
28
-    # Create veth pair, don't bomb if already exists
29
-    echo "Creating veth"
30
-    eval $_ip link add {{ item[1].name | default('br-mgmt') }}-veth type veth peer name {{ item[1].veth_peer | default('eth0') }} || true
31
-    # Set both ends UP
32
-    eval $_ip link set {{ item[1].name | default('br-mgmt') }}-veth up || true
33
-    eval $_ip link set {{ item[1].veth_peer | default('eth0') }} up || true
34
-    # add eth12 to the bridge
35
-    eval $_ip link set {{ item[1].name | default('br-mgmt') }}-veth master {{ item[1].name | default('br-mgmt') }} || true
36
-fi

+ 0
- 9
network_interfaces/suse_interface_default.cfg.j2 View File

@@ -1,9 +0,0 @@
1
-{% if item.veth_peer is defined %}
2
-# This interface has a veth peer
3
-{% endif %}
4
-BRIDGE='yes'
5
-IPADDR={{ item.ip_addr | default('10.1.0.1') }}
6
-NETMASK={{ item.netmask | default('255.255.255.0') }}
7
-STARTMODE='auto'
8
-BOOTPROTO='static'
9
-ETHTOOL_OPTIONS_sg='-K iface sg off'

+ 120
- 139
test-prepare-host.yml View File

@@ -98,150 +98,131 @@
98 98
     - test-vars.yml
99 99
   roles:
100 100
     - role: "lxc_hosts"
101
-  post_tasks:
102
-    - name: Ensure that /etc/network/interfaces.d/ exists (Debian)
103
-      file:
104
-        path: /etc/network/interfaces.d/
105
-        state: directory
106
-      tags:
107
-        - networking-dir-create
108
-      when:
109
-        - ansible_pkg_mgr == 'apt'
110
-
111
-    - name: Copy network configuration (Debian)
112
-      template:
113
-        src: "network_interfaces/debian_interface_{{ item.type | default('default') }}.cfg.j2"
114
-        dest: "/etc/network/interfaces.d/{{ item.name | default('br-mgmt') }}.cfg"
115
-      with_items: "{{ bridges }}"
116
-      register: network_interfaces_deb
117
-      when:
118
-        - ansible_pkg_mgr == 'apt'
119
-
120
-    - name: Copy network configuration (RedHat)
121
-      template:
122
-        src: "network_interfaces/redhat_interface_{{ item.type | default('default') }}.cfg.j2"
123
-        dest: "/etc/sysconfig/network-scripts/ifcfg-{{ item.name | default('br-mgmt') }}"
124
-      with_items: "{{ bridges }}"
125
-      register: network_interfaces_rhel
126
-      when:
127
-        - ansible_pkg_mgr in ['yum', 'dnf']
128
-
129
-    - name: Copy network configuration (SUSE)
130
-      template:
131
-        src: "network_interfaces/suse_interface_{{ item.type | default('default') }}.cfg.j2"
132
-        dest: "/etc/sysconfig/network/ifcfg-{{ item.name | default('br-mgmt') }}"
133
-      with_items: "{{ bridges }}"
134
-      register: network_interfaces_suse
135
-      when:
136
-        - ansible_pkg_mgr == 'zypper'
137
-
138
-    - name: Create alias file when required
139
-      template:
140
-        src: "network_interfaces/redhat_interface_alias.cfg.j2"
141
-        dest: "/etc/sysconfig/network-scripts/ifcfg-{{ item.name | default('br-mgmt')}}:0"
142
-      with_items: "{{ bridges }}"
143
-      when:
144
-        - ansible_pkg_mgr in ['yum', 'dnf']
145
-        - item.alias is defined
146
-
147
-    - name: Put down post-up script for veth-peer interfaces (RedHat)
148
-      template:
149
-        src: "network_interfaces/rpm_interface_{{ item[0] }}.cfg.j2"
150
-        dest: "/etc/sysconfig/network-scripts/{{ item[0] }}-veth-{{ item[1].name | default('br-mgmt') }}-2-{{ item[1].veth_peer | default('eth1') }}"
151
-        mode: "0755"
152
-      with_nested:
153
-        - [ "ifup-post", "ifdown-post" ]
154
-        - "{{ bridges }}"
155
-      when:
156
-        - item[1].veth_peer is defined
157
-        - ansible_pkg_mgr in ['yum', 'dnf']
158
-
159
-    # NOTE(hworang): Nested loops do not work on blocks. See
160
-    # https://github.com/ansible/ansible/issues/13262
161
-    # As such we need to do that on a per-task basis.
162
-    - block:
163
-      - name: Put down post-up script for veth-peer interfaces (SUSE)
164
-        template:
165
-          src: "network_interfaces/rpm_interface_{{ item[0] }}.cfg.j2"
166
-          dest: "/etc/sysconfig/network/scripts/{{ item[0] }}-veth-{{ item[1].name | default('br-mgmt') }}-2-{{ item[1].veth_peer | default('eth1') }}"
167
-          mode: "0755"
168
-        with_nested:
169
-          - [ "ifup-post", "ifdown-post" ]
170
-          - "{{ bridges }}"
171
-      - name: Configure ifcfg files to use the post-up script (SUSE)
172
-        lineinfile:
173
-          dest: "/etc/sysconfig/network/ifcfg-{{ item[1].name | default('br-mgmt') }}"
174
-          line: "POST_UP_SCRIPT=\"compat:suse:{{ item[0] }}-veth-{{ item[1].name | default('br-mgmt') }}-2-{{ item[1].veth_peer | default('eth1') }}\""
175
-        with_nested:
176
-          - ['ifup-post']
177
-          - "{{ bridges }}"
178
-      - name: Configure ifcfg files to use the post-down script (SUSE)
179
-        lineinfile:
180
-          dest: "/etc/sysconfig/network/ifcfg-{{ item[1].name | default('br-mgmt') }}"
181
-          line: "POST_DOWN_SCRIPT=\"compat:suse:{{ item[0] }}-veth-{{ item[1].name | default('br-mgmt') }}-2-{{ item[1].veth_peer | default('eth1') }}\""
182
-        with_nested:
183
-          - ['ifdown-post']
184
-          - "{{ bridges }}"
185
-      when:
186
-        - item[1].veth_peer is defined
187
-        - ansible_pkg_mgr == 'zypper'
188
-
189
-    - name: Ensure our interfaces.d configuration files are loaded automatically
190
-      lineinfile:
191
-        dest: /etc/network/interfaces
192
-        line: "source /etc/network/interfaces.d/*.cfg"
193
-      when:
194
-        - ansible_pkg_mgr == 'apt'
101
+
102
+- name: Playbook for configuring test host networking
103
+  hosts: localhost
104
+  # This set of tasks runs against localhost
105
+  # and requires root access, but tests run as
106
+  # the user running the playbook (zuul). As
107
+  # such, we use a local connection and become.
108
+  connection: local
109
+  become: yes
110
+  vars_files:
111
+    - test-vars.yml
112
+
113
+  tasks:
114
+    - name: Run the systemd-networkd role
115
+      include_role:
116
+        name: systemd_networkd
117
+        private: true
118
+      vars:
119
+        systemd_interface_cleanup: true
120
+        systemd_run_networkd: true
121
+        systemd_netdevs: |-
122
+          {% set systemd_network_devices = [] %}
123
+          {% for interface in (bridges | default([])) %}
124
+          {%   if interface is string %}
125
+          {%     set _ = systemd_network_devices.append({'NetDev': {'Name': 'dummy-' + interface, 'Kind': 'dummy'}}) %}
126
+          {%     set _ = systemd_network_devices.append({'NetDev': {'Name': interface, 'Kind': 'bridge'}}) %}
127
+          {%   else %}
128
+          {%     set interface_name = (interface.name | default('br-mgmt')) %}
129
+          {%     set _ = systemd_network_devices.append({'NetDev': {'Name': 'dummy-' + interface_name, 'Kind': 'dummy'}}) %}
130
+          {%     set _ = systemd_network_devices.append({'NetDev': {'Name': interface_name, 'Kind': 'bridge'}}) %}
131
+          {%     if interface.veth_peer is defined %}
132
+          {%       set _ = systemd_network_devices.append({'NetDev': {'Name': interface_name + '-veth', 'Kind': 'veth'}, 'Peer': {'Name': interface.veth_peer}}) %}
133
+          {%     endif %}
134
+          {%   endif %}
135
+          {% endfor %}
136
+          {{ systemd_network_devices }}
137
+        systemd_networks: |-
138
+          {# If the interface is a string or no ip address is defined and the default address "10.1.0.1/24" will be used #}
139
+          {% set systemd_network_networks = [] %}
140
+          {% for interface in (bridges | default([])) %}
141
+          {%   if interface is string %}
142
+          {%     set _ = systemd_network_networks.append({'interface': 'dummy-' + interface, 'bridge': interface}) %}
143
+          {%     set _ = systemd_network_networks.append({'interface': interface, 'address': '10.1.0.1', 'netmask': '255.255.255.0'}) %}
144
+          {%   else %}
145
+          {%     set interface_name = (interface.name | default('br-mgmt')) %}
146
+          {%     if interface.alias is defined %}
147
+          {%       set _ = systemd_network_networks.append({'interface': 'dummy-' + interface_name, 'bridge': interface_name}) %}
148
+          {%       set _ = systemd_network_networks.append({'interface': interface_name, 'netmask': (interface.netmask | default('255.255.255.0')), 'config_overrides': {'Network': {'Address': {(interface.ip_addr | default('10.1.0.1')): null, (interface.alias | string): null}}}}) %}
149
+          {%     else %}
150
+          {%       set _ = systemd_network_networks.append({'interface': 'dummy-' + interface_name, 'bridge': interface_name}) %}
151
+          {%       set _ = systemd_network_networks.append({'interface': interface_name, 'address': (interface.ip_addr | default('10.1.0.1')), 'netmask': (interface.netmask | default('255.255.255.0'))}) %}
152
+          {%     endif %}
153
+          {%     if interface.veth_peer is defined %}
154
+          {%       set _ = systemd_network_networks.append({'interface': interface.veth_peer + '-veth', 'bridge': interface_name}) %}
155
+          {%     endif %}
156
+          {%   endif %}
157
+          {% endfor %}
158
+          {{ systemd_network_networks }}
159
+
160
+    - name: Run the systemd service role
161
+      include_role:
162
+        name: systemd_service
163
+        private: true
164
+      vars:
165
+        systemd_services:
166
+          - service_name: "networking-post-up"
167
+            config_overrides:
168
+              Unit:
169
+                Description: networking-post-up
170
+                After: network-online.target
171
+                Wants: network-online.target
172
+              Service:
173
+                RemainAfterExit: yes
174
+            service_type: oneshot
175
+            execstarts: |-
176
+              {% set veths = ['-/sbin/ethtool -K ' + (bootstrap_host_public_interface | default(ansible_default_ipv4['alias'])) + ' gso off sg off tso off tx off'] %}
177
+              {% for interface in (bridges | default([])) %}
178
+              {%   if interface is string %}
179
+              {%     set _ = veths.append('-/usr/sbin/ip link set ' + interface + ' up') %}
180
+              {%     set _ = veths.append('-/sbin/ethtool -K ' + interface + ' gso off sg off tso off tx off') %}
181
+              {%   else %}
182
+              {%     set interface_name = (interface.name | default('br-mgmt')) %}
183
+              {%     set _ = veths.append('-/usr/sbin/ip link set ' + interface_name + ' up') %}
184
+              {%     set _ = veths.append('-/sbin/ethtool -K ' + interface_name + ' gso off sg off tso off tx off') %}
185
+              {%     if interface.veth_peer is defined %}
186
+              {%       set _ = veths.append('-/usr/sbin/ip link set ' + interface_name + '-veth up') %}
187
+              {%       set _ = veths.append('-/usr/sbin/ip link set ' + interface.veth_peer + ' up') %}
188
+              {%       set _ = veths.append('-/sbin/ethtool -K ' + interface.veth_peer + ' gso off sg off tso off tx off') %}
189
+              {%     endif %}
190
+              {%   endif %}
191
+              {% endfor %}
192
+              {{ veths }}
193
+            enabled: yes
194
+            state: started
195
+        systemd_tempd_prefix: openstack
195 196
       tags:
196
-        - networking-interfaces-load
197
+        - network-config
197 198
 
198
-    - name: Ensure the postup/postdown scripts are loaded (RedHat)
199
-      lineinfile:
200
-        dest: "/etc/sysconfig/network-scripts/{{ item[0] }}"
201
-        line: ". /etc/sysconfig/network-scripts/{{ item[0] }}-veth-{{ item[1].name | default('br-mgmt') }}-2-{{ item[1].veth_peer | default('eth1') }}"
202
-        insertbefore: "^exit 0"
203
-      with_nested:
204
-        - [ "ifup-post", "ifdown-post" ]
205
-        - "{{ bridges }}"
206
-      when:
207
-        - item[1].veth_peer is defined
208
-        - ansible_pkg_mgr in ['yum', 'dnf']
209
-
210
-    - name: Shut down the network interfaces
211
-      command: "ifdown {{ item.name | default('br-mgmt') }}"
212
-      when:
213
-        - (network_interfaces_rhel | changed) or (network_interfaces_deb | changed) or
214
-          (network_interfaces_suse | changed)
215
-      with_items: "{{ bridges }}"
216
-
217
-    - name: Shut down the alias interface (RedHat)
218
-      command: "ifdown {{ item.name | default('br-mgmt') }}:0"
219
-      when:
220
-        - ansible_pkg_mgr in ['yum', 'dnf']
221
-        - network_interfaces_rhel  is changed
222
-        - item.alias is defined
223
-      with_items: "{{ bridges }}"
224
-
225
-    - name: Start the network interfaces
226
-      command: "ifup {{ item.name | default('br-mgmt') }}"
227
-      when:
228
-        - (network_interfaces_rhel | changed) or (network_interfaces_deb | changed) or
229
-          (network_interfaces_suse | changed)
230
-      with_items: "{{ bridges }}"
231
-
232
-    - name: Start the alias interface (RedHat)
233
-      command: "ifup {{ item.name | default('br-mgmt') }}:0"
234
-      when:
235
-        - ansible_pkg_mgr in ['yum', 'dnf']
236
-        - network_interfaces_rhel  is changed
237
-        - item.alias is defined
238
-      with_items: "{{ bridges }}"
199
+  post_tasks:
200
+    - name: (RE)Gather facts post setup
201
+      setup:
202
+        gather_subset: "network,hardware,virtual"
239 203
 
240 204
     - name: Trigger dnsmasq restart
241 205
       command: /bin/true
242 206
       changed_when:
243
-        - lxc_net_manage_iptables | bool
244
-        - iptables_clear is defined
245
-        - iptables_clear is changed
207
+        - (lxc_net_manage_iptables is defined) and (lxc_net_manage_iptables | bool)
208
+        - (iptables_clear is defined) and (iptables_clear is changed)
246 209
       notify:
247 210
         - Restart dnsmasq
211
+
212
+    - name: Set interfaces fact
213
+      set_fact:
214
+        active_interfaces: |-
215
+          {% set interfaces = [] %}
216
+          {% for interface in (bridges | default([])) %}
217
+          {%   if interface is string %}
218
+          {%     set interface_name = interface %}
219
+          {%   else %}
220
+          {%     set interface_name = (interface.name | default('br-mgmt')) %}
221
+          {%   endif %}
222
+          {%   set _ = interfaces.append(hostvars[inventory_hostname][('ansible_' + (interface_name | replace('-', '_')))]['active'] == true) %}
223
+          {% endfor %}
224
+          {{ interfaces }}
225
+
226
+    - name: Check that new network interfaces are up
227
+      assert:
228
+        that: "{{ active_interfaces }}"

+ 5
- 0
tests/host_vars/localhost.yml View File

@@ -15,5 +15,10 @@
15 15
 
16 16
 bridges:
17 17
   - "br-mgmt"
18
+  - name: "br-test1"
19
+    ip_addr: "10.1.1.1"
20
+  - name: "br-test2"
21
+    ip_addr: "10.1.2.1"
22
+    veth_peer: "veth-test"
18 23
 
19 24
 ansible_python_interpreter: "/usr/bin/python2"

Loading…
Cancel
Save