From 00534ccaf861acb0ebb3dabd6917ad3b82d9f8f1 Mon Sep 17 00:00:00 2001 From: Dmitriy Rabotyagov Date: Tue, 7 Jul 2020 14:36:39 +0300 Subject: [PATCH] Add second router for BGP configuration This patch adjusts CI test and adds support to configure FRR bgpd Change-Id: I451438a9c1a12025af3439895338829b7d5f178f --- .zuul.yaml | 20 +++++++++++++++++++- defaults/main.yml | 4 ++++ tasks/frr_post_install.yml | 9 +++++++++ tasks/main.yml | 5 +++++ templates/frr.conf.j2 | 4 ++++ tests/host_vars/primary | 16 ++++++++++++++++ tests/host_vars/secondary | 4 ++++ tests/test.yml | 21 ++++++++++++++++----- tests/test_vars.yml | 25 ------------------------- 9 files changed, 77 insertions(+), 31 deletions(-) create mode 100644 tests/host_vars/primary create mode 100644 tests/host_vars/secondary delete mode 100644 tests/test_vars.yml diff --git a/.zuul.yaml b/.zuul.yaml index 0f823d0..b0161d6 100644 --- a/.zuul.yaml +++ b/.zuul.yaml @@ -1,8 +1,26 @@ +--- + +- nodeset: + name: debian-buster-2-node + nodes: + - name: primary + label: debian-buster + - name: secondary + label: debian-buster + groups: + - name: switch + nodes: + - primary + - name: peers + nodes: + - primary + - secondary + - job: name: ffrouting-deploy parent: base run: tests/test.yml - nodeset: debian-buster + nodeset: debian-buster-2-node - project: check: diff --git a/defaults/main.yml b/defaults/main.yml index 573fb92..0b55962 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -29,3 +29,7 @@ frr_vlans: [] frr_integrated_config_path: /etc/frr/frr.conf frr_staticd_routes: [] +frr_bgpd_config: [] +frr_bgpd_enable: "{{ (frr_bgpd_config | length > 0) }}" +frr_daemons: + bgpd: "{{ frr_bgpd_enable }}" diff --git a/tasks/frr_post_install.yml b/tasks/frr_post_install.yml index 1d1727d..e6ecd1e 100644 --- a/tasks/frr_post_install.yml +++ b/tasks/frr_post_install.yml @@ -32,4 +32,13 @@ owner: frr group: frr mode: "0640" + validate: /usr/bin/vtysh -C -f %s + notify: Restart frr + + - name: Configure supported daemons + lineinfile: + path: /etc/frr/daemons + line: "{{ item.key }}={{ item.value | bool | ternary('yes', 'no') }}" + regexp: "^{{ item.key }}" + with_dict: "{{ frr_daemons }}" notify: Restart frr diff --git a/tasks/main.yml b/tasks/main.yml index 3c77a13..6f46a94 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -20,6 +20,11 @@ include_tasks: frr_vlans.yml when: frr_vlans | length > 0 +- name: Gather network facts + setup: + gather_subset: + - network + - name: Install frr include_tasks: frr_install.yml diff --git a/templates/frr.conf.j2 b/templates/frr.conf.j2 index c354993..3ebed53 100644 --- a/templates/frr.conf.j2 +++ b/templates/frr.conf.j2 @@ -9,5 +9,9 @@ log syslog informational ! staticd config {{ frr_staticd_routes | join('\n') }} ! +! +! bgpd config +{{ frr_bgpd_config | join('\n') }} +! line vty ! \ No newline at end of file diff --git a/tests/host_vars/primary b/tests/host_vars/primary new file mode 100644 index 0000000..8fbe9ad --- /dev/null +++ b/tests/host_vars/primary @@ -0,0 +1,16 @@ +frr_vlans: + - vlan-raw-device: "{{ ansible_default_ipv4.interface }}" + id: 100 + address: 192.168.1.100 + netmask: 255.255.255.0 + network: 192.168.1.0 + broadcast: 192.168.1.255 + +frr_staticd_routes: + - ip route 10.0.0.0/24 192.168.1.10 + +frr_bgpd_config: + - router bgp 1234 + - "bgp router-id {{ hostvars['primary']['ansible_br_infra']['ipv4']['address'] }}" + - "neighbor {{ hostvars['secondary']['ansible_br_infra']['ipv4']['address'] }} remote-as 5678" + - network 192.168.1.0/24 diff --git a/tests/host_vars/secondary b/tests/host_vars/secondary new file mode 100644 index 0000000..acaba8b --- /dev/null +++ b/tests/host_vars/secondary @@ -0,0 +1,4 @@ +frr_bgpd_config: + - router bgp 5678 + - "bgp router-id {{ hostvars['secondary']['ansible_br_infra']['ipv4']['address'] }}" + - "neighbor {{ hostvars['primary']['ansible_br_infra']['ipv4']['address'] }} remote-as 1234" diff --git a/tests/test.yml b/tests/test.yml index b4f731f..eeaf748 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -15,10 +15,10 @@ - name: Installing frr hosts: all - vars_files: - - test_vars.yml roles: + - multi-node-bridge + - clear-firewall - frrouting post_tasks: @@ -36,6 +36,7 @@ retries: 5 delay: 10 with_items: "{{ frr_vlans }}" + when: inventory_hostname == 'primary' - name: Check service state service_facts: @@ -45,15 +46,25 @@ msg: frr is not up when: ansible_facts.services['frr'].state != 'running' - - name: Get static routes + - name: Get routes become: true become_user: root command: "vtysh -c 'show ip route'" register: _frr_get_routes changed_when: false - - name: Fail if we're missing routes + + - name: Fail if we're missing static routes fail: msg: "We can't find route {{ item }}" with_items: "{{ frr_staticd_routes }}" - when: item.split(' ')[-1] not in _frr_get_routes.stdout + when: + - inventory_hostname == 'primary' + - item.split(' ')[-1] not in _frr_get_routes.stdout + + - name: Fail if we're missing bgp routes + fail: + msg: "We can't find route 192.168.1.0/24" + when: + - inventory_hostname == 'secondary' + - "'192.168.1.0/24' not in _frr_get_routes.stdout" diff --git a/tests/test_vars.yml b/tests/test_vars.yml deleted file mode 100644 index efe820f..0000000 --- a/tests/test_vars.yml +++ /dev/null @@ -1,25 +0,0 @@ ---- -# Copyright 2020, VEXXHOST, 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. - -frr_vlans: - - vlan-raw-device: "{{ ansible_default_ipv4.interface }}" - id: 100 - address: 192.168.1.100 - netmask: 255.255.255.0 - network: 192.168.1.0 - broadcast: 192.168.1.255 - -frr_staticd_routes: - - ip route 10.0.0.0/24 192.168.1.10