Skip to content
Snippets Groups Projects
Commit 46f29a34 authored by ME's avatar ME
Browse files

change by Alex comments

parent bf41faae
Branches
No related tags found
No related merge requests found
---
###############################################################################################################
# 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"
---
###############################################################################################################
# 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'
# NLRIs: The NLRIs exchanged must be the same
- name: Compare NLRIs
ansible.builtin.assert:
that:
- post_check.{{ check_id }}.nlri_peerconf is defined
- pre_check.{{ check_id }}.nlri_peerconf is defined
- post_check.{{ check_id }}.nlri_peer is defined
- pre_check.{{ check_id }}.nlri_peer is defined
- post_check.{{ check_id }}.nlri_peerconf is defined
- pre_check.{{ check_id }}.nlri_peerconf is defined
- post_check.{{ check_id }}.nlri_session is defined
- pre_check.{{ check_id }}.nlri_session is defined
- post_check.{{ check_id }}.nlri_rib is defined
- pre_check.{{ check_id }}.nlri_rib is defined
- "post_check.{{ check_id }}.nlri_peerconf == pre_check.{{ check_id }}.nlri_peerconf"
- "post_check.{{ check_id }}.nlri_peer == pre_check.{{ check_id }}.nlri_peer"
- "post_check.{{ check_id }}.nlri_session == pre_check.{{ check_id }}.nlri_session"
- "post_check.{{ check_id }}.nlri_peernego == pre_check.{{ check_id }}.nlri_peernego"
- "post_check.{{ check_id }}.nlri_rib == pre_check.{{ check_id }}.nlri_rib"
fail_msg: "FAIL: the nlri's exchanged aren't the same"
success_msg: "PASS: the nlri's exchanged are the same"
failed_when: false
# ROUTES: The number of advertised and received routes must be within 5% difference with the previous state
- name: Compare the number of advertised routes
ansible.builtin.assert:
that:
- post_check.bgp_adv_routes is defined
- pre_check.bgp_adv_routes is defined
- "((pre_check.{{ check_id }}.bgp_adv_routes - post_check.{{ check_id }}.bgp_adv_routes) / pre_check.{{ check_id }}.bgp_adv_routes) * 100 | abs <= 5"
fail_msg: "FAIL: the number of advertised routes isn't within 5% of difference"
success_msg: "PASS: the number of advertised routes is within 5% of difference"
failed_when: false
- name: Compare the number of received routes
ansible.builtin.assert:
that:
- post_check.bgp_adv_routes is defined
- pre_check.bgp_adv_routes is defined
- "((pre_check.{{ check_id }}.bgp_rec_routes - post_check.{{ check_id }}.bgp_rec_routes) / pre_check.{{ check_id }}.bgp_rec_routes) * 100 | abs <= 5"
fail_msg: "FAIL: the number of received routes isn't within 5% of difference"
success_msg: "PASS: the number of received routes is within 5% of difference"
failed_when: false
......@@ -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 + ':' }}
......
......@@ -40,7 +40,12 @@
- (verb is not defined) or (neighbor_address is not defined) or (vendor is not defined) or (check_id is not defined)
- name: Include task
ansible.builtin.include_tasks: get_bgpstatus.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 in verbs
......
---
# 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"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment