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 0000000000000000000000000000000000000000..a9cc2fd9c9256c1f7261005bfb7517ce6a92a8d8 --- /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 ff4f3aadccf1fccc2aa7da75643ebc8f13f5eaa5..f39dcb8e9cd135d71f9e1c23664b2c088279e393 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 c60826747f1bb1491685416ccaaab0276348743c..338df15f7cf37056a8f8e7cdfa1ca0f96c6ba2b6 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 04f048f7b48a1b039a42ab074648f2f964cee3cb..a05605e0eb9c502d683f72ad62b6ef70ce4ba489 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 ac46f829591872fdfb6e027f382f985f185bdb35..38742aaf93b01b5307a6d5243dbc932e7c03749b 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"