Skip to content

Commit

Permalink
Add molecule tests to frr component
Browse files Browse the repository at this point in the history
Add molecule tests to frr component
  • Loading branch information
Fernando Royo committed Nov 20, 2023
1 parent ebe1621 commit de4658b
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 16 deletions.
2 changes: 1 addition & 1 deletion roles/edpm_frr/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ edpm_frr_volumes:
- /etc/pki/tls/certs/ca-bundle.trust.crt:/etc/pki/tls/certs/ca-bundle.trust.crt:ro
- /etc/pki/tls/cert.pem:/etc/pki/tls/cert.pem:ro
- /var/lib/kolla/config_files/frr.json:/var/lib/kolla/config_files/config.json:ro
- /var/lib/config-data/ansible-generated/frr:/var/lib/kolla/config_files/src:ro
- /var/lib/config-data/ansible-generated/frr/etc/frr:/etc/frr:z
- /var/log/containers/frr:/var/log/frr:z
- /run/frr:/run/frr:shared,z

Expand Down
2 changes: 1 addition & 1 deletion roles/edpm_frr/meta/argument_specs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ argument_specs:
- /etc/pki/tls/certs/ca-bundle.trust.crt:/etc/pki/tls/certs/ca-bundle.trust.crt:ro
- /etc/pki/tls/cert.pem:/etc/pki/tls/cert.pem:ro
- /var/lib/kolla/config_files/frr.json:/var/lib/kolla/config_files/config.json:ro
- /var/lib/config-data/ansible-generated/frr:/var/lib/kolla/config_files/src:ro
- /var/lib/config-data/ansible-generated/frr/etc/frr:/etc/frr:z
- /var/log/containers/frr:/var/log/frr:z
- /run/frr:/run/frr:shared,z
description: List of FRR volumes in a mountpoint form.
Expand Down
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
6 changes: 6 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:
- name: Install os-net-config
ansible.builtin.package:
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
14 changes: 14 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 @@ -25,7 +26,20 @@
- {'path': "{{ edpm_frr_config_basedir }}", 'setype': container_file_t, 'mode': '0750'}
- {'path': /run/frr, 'setype': container_file_t, 'mode': '0755'}

- name: Create persistent directories (just for testing purpose)
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: Ensure /run/frr is present upon reboot
become: true
ansible.builtin.copy:
dest: /etc/tmpfiles.d/run-frr.conf
mode: "0755"
Expand Down
8 changes: 0 additions & 8 deletions roles/edpm_frr/templates/kolla_config/frr.yaml.j2
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
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: "/"
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 de4658b

Please sign in to comment.