openstack-ansible-tests/test-prepare-host.yml
Michael Vollman 4931471eee Ensure ipforward is set on all test bridges
Statically set ipforward: true for all test bridges to fix centos7 gate
where forwarding is disabled by default.  Ubuntu is defaulting
forwarding enabled for all bridges so this will align the forwarding
configuration of centos and ubuntu.

Change-Id: Idbf2bbbdfb0d2c5c3b440ad37004f5768328e7a6
2019-02-11 10:52:00 -05:00

234 lines
10 KiB
YAML

---
# 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
private: yes
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
private: yes
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"
- 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
private: true
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
private: true
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: 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: 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 }}"