forked from openstack/openstack-ansible-tests
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test-prepare-host.yml
230 lines (213 loc) · 10.1 KB
/
test-prepare-host.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
---
# Copyright 2015, Rackspace US, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
- import_playbook: test-repo-setup.yml
- name: Playbook for configuring hosts
hosts: localhost
# This set of tasks runs against localhost
# and requires root access, but tests run as
# the user running the playbook (zuul). As
# such, we use a local connection and become.
connection: local
become: yes
vars_files:
- test-vars.yml
tasks:
- include_tasks: "common-tasks/test-set-nodepool-vars.yml"
- name: Clear iptables rules
shell: "{{ playbook_dir }}/iptables-clear.sh"
register: iptables_clear
tags:
- skip_ansible_lint
- name: Set ssh key fact
set_fact:
lxc_container_ssh_key: "{{ hostvars['localhost']['lxc_container_ssh_key'] }}"
- name: Ensure roots new public ssh key is in authorized_keys
authorized_key:
user: root
key: "{{ hostvars['localhost']['lxc_container_ssh_key'] }}"
manage_dir: no
# This is a very dirty hack due to images.linuxcontainers.org
# constantly failing to resolve in openstack-infra.
- name: Implement hard-coded hosts entries for consistently failing name
lineinfile:
path: "/etc/hosts"
line: "{{ item }}"
state: present
with_items:
- "91.189.91.21 images.linuxcontainers.org us.images.linuxcontainers.org"
- "91.189.88.37 images.linuxcontainers.org uk.images.linuxcontainers.org"
# NOTE(mhayden): Using package_state=present on CentOS or openSUSE should allow for
# more gate jobs to complete properly and expose more problems that can
# be fixed (instead of timeouts).
- name: Use present for package_state on CentOS and openSUSE
set_fact:
package_state: "{{ (ansible_pkg_mgr in ['dnf', 'yum', 'zypper']) | ternary('present', 'latest') }}"
- name: Setup clouds.yaml for the test user
include_role:
name: openstack_openrc
vars:
openrc_file_dest: "{{ lookup('env', 'HOME') }}/openrc"
openrc_file_owner: "{{ lookup('env', 'USER') }}"
openrc_openstack_client_config_dir_dest: "{{ lookup('env', 'HOME') }}/.config/openstack"
openrc_openstack_client_config_dir_owner: "{{ lookup('env', 'USER') }}"
openrc_clouds_yml_file_owner: "{{ lookup('env', 'USER') }}"
- name: Setup clouds.yaml for the root user
include_role:
name: openstack_openrc
vars:
openrc_file_dest: "/root/openrc"
openrc_file_owner: "root"
openrc_openstack_client_config_dir_dest: "/root/.config/openstack"
openrc_openstack_client_config_dir_owner: "root"
openrc_clouds_yml_file_owner: "root"
- import_playbook: test-install-openstack-hosts.yml
- name: Playbook for configuring the LXC host
hosts: localhost
# This set of tasks runs against localhost
# and requires root access, but tests run as
# the user running the playbook (zuul). As
# such, we use a local connection and become.
connection: local
become: yes
vars_files:
- test-vars.yml
roles:
- role: "lxc_hosts"
post_tasks:
- name: Trigger dnsmasq restart
command: /bin/true
changed_when:
- (lxc_net_manage_iptables is defined) and (lxc_net_manage_iptables | bool)
- (iptables_clear is defined) and (iptables_clear is changed)
notify:
- Restart dnsmasq
- name: Playbook for configuring test host networking
hosts: localhost
# This set of tasks runs against localhost
# and requires root access, but tests run as
# the user running the playbook (zuul). As
# such, we use a local connection and become.
connection: local
become: yes
vars:
iptool_path:
debian: "/sbin/ip"
gentoo: "/bin/ip"
redhat: "/usr/sbin/ip"
suse: "/bin/ip"
vars_files:
- test-vars.yml
tasks:
- name: Run the systemd-networkd role
include_role:
name: systemd_networkd
vars:
systemd_interface_cleanup: true
systemd_run_networkd: true
systemd_netdevs: |-
{% set systemd_network_devices = [] %}
{% for interface in (bridges | default([])) %}
{% if interface is string %}
{% set _ = systemd_network_devices.append({'NetDev': {'Name': 'dummy-' + interface, 'Kind': 'dummy'}}) %}
{% set _ = systemd_network_devices.append({'NetDev': {'Name': interface, 'Kind': 'bridge'}}) %}
{% else %}
{% set interface_name = (interface.name | default('br-mgmt')) %}
{% set _ = systemd_network_devices.append({'NetDev': {'Name': 'dummy-' + interface_name, 'Kind': 'dummy'}}) %}
{% set _ = systemd_network_devices.append({'NetDev': {'Name': interface_name, 'Kind': 'bridge'}}) %}
{% if interface.veth_peer is defined %}
{% set _ = systemd_network_devices.append({'NetDev': {'Name': interface_name + '-veth', 'Kind': 'veth'}, 'Peer': {'Name': interface.veth_peer}}) %}
{% endif %}
{% endif %}
{% endfor %}
{{ systemd_network_devices }}
systemd_networks: |-
{# If the interface is a string or no ip address is defined and the default address "10.1.0.1/24" will be used #}
{% set systemd_network_networks = [] %}
{% for interface in (bridges | default([])) %}
{% if interface is string %}
{% set _ = systemd_network_networks.append({'interface': 'dummy-' + interface, 'bridge': interface}) %}
{% set _ = systemd_network_networks.append({'interface': interface, 'address': '10.1.0.1', 'netmask': '255.255.255.0'}) %}
{% else %}
{% set interface_name = (interface.name | default('br-mgmt')) %}
{% if interface.alias is defined %}
{% set _ = systemd_network_networks.append({'interface': 'dummy-' + interface_name, 'bridge': interface_name}) %}
{% 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}}}}) %}
{% else %}
{% set _ = systemd_network_networks.append({'interface': 'dummy-' + interface_name, 'bridge': interface_name}) %}
{% 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')), 'ipforward': true}) %}
{% endif %}
{% if interface.veth_peer is defined %}
{% set _ = systemd_network_networks.append({'interface': interface.veth_peer + '-veth', 'bridge': interface_name}) %}
{% endif %}
{% endif %}
{% endfor %}
{{ systemd_network_networks }}
- name: Run the systemd service role
include_role:
name: systemd_service
vars:
systemd_services:
- service_name: "networking-post-up"
config_overrides:
Unit:
Description: networking-post-up
After: network-online.target
Wants: network-online.target
Service:
RemainAfterExit: yes
service_type: oneshot
execstarts: |-
{% set veths = ['-/sbin/ethtool -K ' + (bootstrap_host_public_interface | default(ansible_default_ipv4['alias'])) + ' gso off sg off tso off tx off'] %}
{% for interface in (bridges | default([])) %}
{% if interface is string %}
{% set _ = veths.append('-' + iptool_path[ansible_os_family | lower] + ' link set ' + interface + ' up') %}
{% set _ = veths.append('-/sbin/ethtool -K ' + interface + ' gso off sg off tso off tx off') %}
{% else %}
{% set interface_name = (interface.name | default('br-mgmt')) %}
{% set _ = veths.append('-' + iptool_path[ansible_os_family | lower] + ' link set ' + interface_name + ' up') %}
{% set _ = veths.append('-/sbin/ethtool -K ' + interface_name + ' gso off sg off tso off tx off') %}
{% if interface.veth_peer is defined %}
{% set _ = veths.append('-' + iptool_path[ansible_os_family | lower] + ' link set ' + interface_name + '-veth up') %}
{% set _ = veths.append('-' + iptool_path[ansible_os_family | lower] + ' link set ' + interface.veth_peer + ' up') %}
{% set _ = veths.append('-/sbin/ethtool -K ' + interface.veth_peer + ' gso off sg off tso off tx off') %}
{% endif %}
{% endif %}
{% endfor %}
{{ veths }}
enabled: yes
state: started
systemd_tempd_prefix: openstack
tags:
- network-config
post_tasks:
- name: (RE)Gather facts post setup
setup:
gather_subset: "all"
- name: Set interfaces fact
set_fact:
active_interfaces: |-
{% set interfaces = [] %}
{% for interface in (bridges | default([])) %}
{% if interface is string %}
{% set interface_name = interface %}
{% else %}
{% set interface_name = (interface.name | default('br-mgmt')) %}
{% endif %}
{% set _ = interfaces.append(hostvars[inventory_hostname][('ansible_' + (interface_name | replace('-', '_')))]['active'] == true) %}
{% endfor %}
{{ interfaces }}
- name: Check that new network interfaces are up
assert:
that: "{{ active_interfaces }}"