From 267b608437d39ea6d3570947cbe13b91f9d5ef25 Mon Sep 17 00:00:00 2001 From: "ak@geant.org" <ak@geant.org> Date: Tue, 1 Aug 2023 17:20:09 +0100 Subject: [PATCH] BGP pre-post checks: changes proposal --- roles/bgp_checks/tasks/check_bgp_status.yaml | 48 +++++++++++++++++++ .../{check.yaml => compare_pre_post.yaml} | 19 -------- roles/bgp_checks/tasks/create_file.yaml | 6 +-- roles/bgp_checks/tasks/main.yaml | 7 ++- roles/bgp_checks/vars/main.yaml | 3 ++ 5 files changed, 60 insertions(+), 23 deletions(-) create mode 100644 roles/bgp_checks/tasks/check_bgp_status.yaml rename roles/bgp_checks/tasks/{check.yaml => compare_pre_post.yaml} (86%) diff --git a/roles/bgp_checks/tasks/check_bgp_status.yaml b/roles/bgp_checks/tasks/check_bgp_status.yaml new file mode 100644 index 00000000..a9cc2fd9 --- /dev/null +++ b/roles/bgp_checks/tasks/check_bgp_status.yaml @@ -0,0 +1,48 @@ +--- + +############################################################################################################### +# The playbook does the following: +# +# - Loads variables from pre and post check results +# - Prints all the pre or post check BGP statistics that were retreived +# - Runs a number of assertions upon these metrics and prints weather a metric has been a 'PASS' or 'FAIL': +# - Checks if bgp_state (peer-state) is 'Established' = PASS +# - Checks if bfd_operstate (bfd-operational-state) is 'UP' = PASS +# - If there is a FAIL, the playbook stops +# +############################################################################################################### + +- name: Load variables from pre and post check results + ansible.builtin.include_vars: + dir: vars + files_matching: "{{ check_id }}.yaml" + +- name: TEST Print PRE interface statistics + ansible.builtin.debug: + var: pre_check + when: verb == 'pre_check' + +- name: TEST Print POST interface statistics + ansible.builtin.debug: + var: post_check + when: verb == 'post_check' + +# SESSION_UP: The BGP session must be up (both IPv4 and IPv6) + +- name: Get bgp state + ansible.builtin.assert: + that: + - "{{ verb }}.{{ check_id }}.bgp_state == 'Established'" + fail_msg: "FAIL: bgp isn't Established" + success_msg: "PASS: bgp state is Established" + failed_when: false + +# BFD: If BFD is configured, it should be UP + +- name: Get bfd state + ansible.builtin.assert: + that: + - "{{ verb }}.{{ check_id }}.bfd_operstate == 'Up'" + fail_msg: "FAIL: bfd isn't Up" + success_msg: "PASS: bfd state is Up" + failed_when: false diff --git a/roles/bgp_checks/tasks/check.yaml b/roles/bgp_checks/tasks/compare_pre_post.yaml similarity index 86% rename from roles/bgp_checks/tasks/check.yaml rename to roles/bgp_checks/tasks/compare_pre_post.yaml index ff4f3aad..f39dcb8e 100644 --- a/roles/bgp_checks/tasks/check.yaml +++ b/roles/bgp_checks/tasks/compare_pre_post.yaml @@ -27,25 +27,6 @@ var: post_check when: verb == 'post_check' -# SESSION_UP: The BGP session must be up (both IPv4 and IPv6) - -- name: Get bgp state - ansible.builtin.assert: - that: - - "{{ verb }}.{{ check_id }}.bgp_state == 'Established'" - fail_msg: "FAIL: bgp isn't Established" - success_msg: "PASS: bgp state is Established" - failed_when: false - -# BFD: If BFD is configured, it should be UP - -- name: Get bfd state - ansible.builtin.assert: - that: - - "{{ verb }}.{{ check_id }}.bfd_operstate == 'Up'" - fail_msg: "FAIL: bfd isn't Up" - success_msg: "PASS: bfd state is Up" - failed_when: false # NLRIs: The NLRIs exchanged must be the same diff --git a/roles/bgp_checks/tasks/create_file.yaml b/roles/bgp_checks/tasks/create_file.yaml index c6082674..338df15f 100644 --- a/roles/bgp_checks/tasks/create_file.yaml +++ b/roles/bgp_checks/tasks/create_file.yaml @@ -14,7 +14,7 @@ - name: Get output file information ansible.builtin.stat: - path: roles/bgp_checks/vars/{{ check_id }}.yaml + path: "{{ results_dir }}{{ check_id }}.yaml" register: file_status - name: Creating a file with results content @@ -46,14 +46,14 @@ {{ 'bgp_rec_active:' }} {{ bgp_rec_active }} {{ 'bgp_rec_holddown:' }} {{ bgp_rec_holddown }} {{ 'bgp_rec_hidden:' }} {{ bgp_rec_hidden }} - dest: "roles/bgp_checks/vars/{{ check_id }}.yaml" + dest: "{{ results_dir }}{{ check_id }}.yaml" mode: '0660' when: - not file_status.stat.exists - name: Add post_check parameters to yaml ansible.builtin.blockinfile: - path: "roles/bgp_checks/vars/{{ check_id }}.yaml" + path: "{{ results_dir }}{{ check_id }}.yaml" marker: "# {mark} -------------- POST CHECKS ----------------------------- #" block: | {{ verb + ':' }} diff --git a/roles/bgp_checks/tasks/main.yaml b/roles/bgp_checks/tasks/main.yaml index 04f048f7..a05605e0 100644 --- a/roles/bgp_checks/tasks/main.yaml +++ b/roles/bgp_checks/tasks/main.yaml @@ -65,6 +65,11 @@ - verb in verbs - name: Include task - ansible.builtin.include_tasks: check.yaml + ansible.builtin.include_tasks: check_bgp_status.yaml when: - verb in verbs + +- name: Include task + ansible.builtin.include_tasks: compare_pre_post.yaml + when: + - verb == 'post_check' diff --git a/roles/bgp_checks/vars/main.yaml b/roles/bgp_checks/vars/main.yaml index ac46f829..38742aaf 100644 --- a/roles/bgp_checks/vars/main.yaml +++ b/roles/bgp_checks/vars/main.yaml @@ -1,5 +1,8 @@ --- # vars file for L3-BGP-based-checks +results_dir: "/var/tmp/" +max_adv_routes_diff: 10 +max_rec_routes_diff: 10 dryrun: "True" verbs: - "pre_check" -- GitLab