Skip to content

Commit

Permalink
Merge pull request #484 from fernandoroyosanchez/frr_test
Browse files Browse the repository at this point in the history
Add molecule tests to frr component
  • Loading branch information
openshift-merge-bot[bot] authored Nov 24, 2023
2 parents 8205f7f + 1f8d2f0 commit f5dbf30
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 11 deletions.
7 changes: 7 additions & 0 deletions roles/edpm_frr/molecule/default/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@

- name: Converge
hosts: all
become: true
pre_tasks:
- name: set basic user fact
set_fact:
ansible_user: "{{ lookup('env', 'USER') }}"
when:
- ansible_user is undefined
tasks:
- name: "Download required role packages"
ansible.builtin.include_role:
Expand Down
5 changes: 1 addition & 4 deletions roles/edpm_frr/molecule/default/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,8 @@ provisioner:

scenario:
test_sequence:
- dependency
- destroy
- create
- prepare
- converge
- destroy
- verify
verifier:
name: ansible
18 changes: 18 additions & 0 deletions roles/edpm_frr/molecule/default/prepare.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
- openvswitch
- python3-pip
- os-net-config
pre_tasks:
- name: set basic user fact
set_fact:
ansible_user: "{{ lookup('env', 'USER') }}"
when:
- ansible_user is undefined
tasks:
# needed due to regression in 1.11.1
# see https://github.com/containers/crun/issues/1338
Expand All @@ -42,6 +48,18 @@
name: os-net-config
become: true

- name: Create persistent directories
become: true
ansible.builtin.file:
path: "{{ item.path }}"
state: directory
setype: "{{ item.setype | default('container_file_t') }}"
owner: "{{ item.owner }}"
group: "{{ item.group }}"
mode: "{{ item.mode }}"
loop:
- {'path': /etc/tmpfiles.d/, 'owner': 'root', 'group': 'root', 'mode': '0755'}

- name: Setup for FRR
become: true
block:
Expand Down
95 changes: 95 additions & 0 deletions roles/edpm_frr/molecule/default/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
---
- name: Verify frr
gather_facts: false
hosts: compute-1
vars:
test_helper_dir: "../../../../molecule/test-helpers"
tasks:
- name: ensure expected directories exist
ansible.builtin.include_tasks: "{{test_helper_dir}}/verify_dir.yaml"
loop:
- "/var/lib/edpm-config/container-startup-config/frr"
- "/var/lib/config-data/ansible-generated/frr"
- "/var/log/containers/frr"
- "/etc/tmpfiles.d/"
- "/var/lib/config-data/ansible-generated/frr/etc/frr"

- name: ensure that /etc/tmpfiles.d/run-frr.conf file for frr exist
become: true
block:
- name: Check if file /etc/tmpfiles.d/run-frr.conf exist
ansible.builtin.stat:
path: /etc/tmpfiles.d/run-frr.conf
register: check_frr_file
- name: Assert file /etc/tmpfiles.d/run-frr.conf exist
ansible.builtin.assert:
that:
- check_frr_file.stat.exists
fail_msg: "File /etc/tmpfiles.d/run-frr.conf does not exist"

- name: ensure that /var/lib/config-data/ansible-generated/frr/etc/frr/frr.conf file exist
become: true
block:
- name: Check if file /var/lib/config-data/ansible-generated/frr/etc/frr/frr.conf exist
ansible.builtin.stat:
path: /var/lib/config-data/ansible-generated/frr/etc/frr/frr.conf
register: check_frr_conf_file
- name: Assert file /var/lib/config-data/ansible-generated/frr/etc/frr/frr.conf exist
ansible.builtin.assert:
that:
- check_frr_conf_file.stat.exists
fail_msg: "File /var/lib/config-data/ansible-generated/frr/etc/frr/frr.conf does not exist"

- name: ensure that /var/lib/config-data/ansible-generated/frr/etc/frr/daemons file exist
become: true
block:
- name: Check if file /var/lib/config-data/ansible-generated/frr/etc/frr/daemons exist
ansible.builtin.stat:
path: /var/lib/config-data/ansible-generated/frr/etc/frr/daemons
register: check_frr_daemons_file
- name: Assert file /var/lib/config-data/ansible-generated/frr/etc/frr/daemons exist
ansible.builtin.assert:
that:
- check_frr_daemons_file.stat.exists
fail_msg: "File /var/lib/config-data/ansible-generated/frr/etc/frr/daemons does not exist"

- name: "Use lookup to get container frr log"
vars:
local_file: /var/log/containers/frr/frr.log
remote_file: /home/zuul/frr_container.log
when: lookup( 'file', local_file, errors='ignore' )
copy:
src: "{{ local_file}}"
dest: "{{ remote_file }}"

- name: "Use lookup to get stdout frr.log"
vars:
local_file: /var/log/containers/stdouts/frr.log
remote_file: /home/zuul/frr_stdouts.log
when: lookup( 'file', local_file, errors='ignore' )
copy:
src: "{{ local_file}}"
dest: "{{ remote_file }}"

- name: ensure podman container exists and are running
ansible.builtin.include_tasks: "{{test_helper_dir}}/verify_podman.yaml"
loop:
- "frr"

- name: ensure systemd services are defined and functional
ansible.builtin.include_tasks: "{{test_helper_dir}}/verify_systemd_unit.yaml"
loop:
- {"name": "edpm_frr.service"}

- name: ensure that log file for frr exist
become: true
block:
- name: Check if file /var/log/containers/frr/frr.log exist
ansible.builtin.stat:
path: /var/log/containers/frr/frr.log
register: log_file
- name: Assert file /var/log/containers/frr/frr.log exist
ansible.builtin.assert:
that:
- log_file.stat.exists
fail_msg: "File /var/log/containers/frr/frr.log does not exist"
5 changes: 3 additions & 2 deletions roles/edpm_frr/tasks/configure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# under the License.

- name: Identify the real interfaces via os-net-config
become: true
ansible.builtin.command: os-net-config -i
register: os_net_config_result
changed_when: os_net_config_result.rc == 0
Expand Down Expand Up @@ -42,7 +43,7 @@
ansible.builtin.template:
src: frr.conf.j2
dest: "{{ edpm_frr_config_basedir }}/etc/frr/frr.conf"
mode: '640'
mode: '644'
selevel: s0
setype: container_file_t
register: _frr_config_result
Expand All @@ -52,7 +53,7 @@
ansible.builtin.template:
src: daemons.j2
dest: "{{ edpm_frr_config_basedir }}/etc/frr/daemons"
mode: '640'
mode: '644'
selevel: s0
setype: container_file_t
register: _frr_daemons_result
2 changes: 2 additions & 0 deletions roles/edpm_frr/tasks/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# under the License.

- name: Create persistent directories
become: true
ansible.builtin.file:
path: "{{ item.path }}"
state: directory
Expand All @@ -26,6 +27,7 @@
- {'path': /run/frr, 'setype': container_file_t, 'mode': '0755'}

- name: Ensure /run/frr is present upon reboot
become: true
ansible.builtin.copy:
dest: /etc/tmpfiles.d/run-frr.conf
mode: "0755"
Expand Down
7 changes: 2 additions & 5 deletions roles/edpm_frr/templates/kolla_config/frr.yaml.j2
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
command: bash -c $* -- eval if [ -f /usr/libexec/frr/frrinit.sh ]; then /usr/libexec/frr/frrinit.sh start; else /usr/lib/frr/frr start; fi && exec /bin/sleep infinity
config_files:
- source: "/var/lib/kolla/config_files/src/*"
dest: "/"
- source: "/var/lib/kolla/config_files/src/etc/frr/*"
dest: /etc/frr/
merge: true
preserve_properties: true
permissions:
- path: /etc/frr
owner: frr:frr
recurse: true
- path: /var/log/frr
owner: frr:frr
recurse: true
Expand Down

0 comments on commit f5dbf30

Please sign in to comment.