From dd7a573a3d79804b15c9d6f703a269fa9f8ab74a Mon Sep 17 00:00:00 2001
From: Aleksandr Kurbatov <aleksandr.kurbatov@GL1342.local>
Date: Thu, 4 Jul 2024 12:29:16 +0100
Subject: [PATCH] iptrunk_checks: added LLDP checks

---
 geant/gap_ansible/CHANGELOG.md                |  3 ++
 .../iptrunk_checks/tasks/check_lldp.yaml      | 31 +++++++++++++++++++
 .../roles/iptrunk_checks/tasks/main.yml       |  4 +++
 .../roles/iptrunk_checks/vars/main.yml        |  1 +
 4 files changed, 39 insertions(+)
 create mode 100644 geant/gap_ansible/roles/iptrunk_checks/tasks/check_lldp.yaml

diff --git a/geant/gap_ansible/CHANGELOG.md b/geant/gap_ansible/CHANGELOG.md
index 22a15167..df19443b 100644
--- a/geant/gap_ansible/CHANGELOG.md
+++ b/geant/gap_ansible/CHANGELOG.md
@@ -1,4 +1,7 @@
 # GAP Ansible changelog
+1.0.77:
+- `iptrunk_migration`: if trunk is `Leased`, update the target BFD address (LO of the new node) after migration and check the BFD status.
+- `iptrunk_checks`: added LLDP check - simpple `show lldp neighbors`.
 1.0.76:
 - fixes in `iptrunk_migration` role (BFD, min-links, corrected interface descriptions)
 1.0.75:
diff --git a/geant/gap_ansible/roles/iptrunk_checks/tasks/check_lldp.yaml b/geant/gap_ansible/roles/iptrunk_checks/tasks/check_lldp.yaml
new file mode 100644
index 00000000..1e3b32b1
--- /dev/null
+++ b/geant/gap_ansible/roles/iptrunk_checks/tasks/check_lldp.yaml
@@ -0,0 +1,31 @@
+- name: Juniper LLDP check
+  when: local_side.iptrunk_side_node.vendor == "juniper"
+  block:
+    - name: Get LLDP neighbors
+      junipernetworks.junos.junos_command:
+        commands:
+          - show lldp neighbors
+      register: response
+
+    - name: Show LLDP neighbors
+      ansible.builtin.debug:
+        msg: "{{ response.stdout_lines[0] }}"
+
+- name: Nokia BFD check
+  when: local_side.iptrunk_side_node.vendor == "nokia"
+  block:
+    - name: Get LLDP neighbors
+      ansible.netcommon.netconf_rpc:
+        rpc: action
+        xmlns: "urn:ietf:params:xml:ns:yang:1"
+        content: |
+            <global-operations xmlns="urn:nokia.com:sros:ns:yang:sr:oper-global">
+              <md-cli-raw-command>
+                <md-cli-input-line>show system lldp neighbor</md-cli-input-line>
+              </md-cli-raw-command>
+            </global-operations>
+        display: json
+      register: out
+    - name: Show LLDP neighbors
+      ansible.builtin.debug:
+        msg: "{{out.output['rpc-reply']['nokiaoper:results']['nokiaoper:md-cli-output-block'].split('\n')}}"
diff --git a/geant/gap_ansible/roles/iptrunk_checks/tasks/main.yml b/geant/gap_ansible/roles/iptrunk_checks/tasks/main.yml
index ec17edd4..3a56c87f 100644
--- a/geant/gap_ansible/roles/iptrunk_checks/tasks/main.yml
+++ b/geant/gap_ansible/roles/iptrunk_checks/tasks/main.yml
@@ -85,6 +85,10 @@
   ansible.builtin.include_tasks: check_bfd.yaml
   when: check == "bfd"
 
+- name: Check LLDP
+  ansible.builtin.include_tasks: check_lldp.yaml
+  when: check == "lldp"
+
 - name: Set the optical checks results directory name
   when: check == "optical_pre" or check == "optical_post"
   ansible.builtin.set_fact:
diff --git a/geant/gap_ansible/roles/iptrunk_checks/vars/main.yml b/geant/gap_ansible/roles/iptrunk_checks/vars/main.yml
index 18a050f9..b7050df1 100644
--- a/geant/gap_ansible/roles/iptrunk_checks/vars/main.yml
+++ b/geant/gap_ansible/roles/iptrunk_checks/vars/main.yml
@@ -3,6 +3,7 @@
 #
 checks:
   - bfd
+  - lldp
   - isis
   - ping
   - lacp
-- 
GitLab