From a1e5999a7ad56d00f744c5ca70d397c3ffd66653 Mon Sep 17 00:00:00 2001
From: Erik Reid <erik.reid@geant.org>
Date: Sun, 21 Aug 2022 10:31:28 +0200
Subject: [PATCH] added status /msr/ip-services and extra tests

---
 inventory_provider/routes/msr.py |  4 +++-
 test/test_msr_routes.py          | 14 ++++++++++++++
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/inventory_provider/routes/msr.py b/inventory_provider/routes/msr.py
index 4f81e71e..a3d47057 100644
--- a/inventory_provider/routes/msr.py
+++ b/inventory_provider/routes/msr.py
@@ -388,6 +388,7 @@ IP_SERVICES_LIST_SCHEMA = {
                 'name': {'type': 'string'},
                 'customer': {'type': 'string'},
                 'type': {'type': 'string'},
+                'status': {'type': 'string'},
                 'pop': {
                     'type': 'object',
                     'properties': {
@@ -398,7 +399,7 @@ IP_SERVICES_LIST_SCHEMA = {
                     'additionalProperties': False
                 }
             },
-            'required': ['name', 'customer', 'type', 'pop'],
+            'required': ['name', 'customer', 'type', 'pop', 'status'],
             'additionalProperties': False
         },
         'interface-address': {
@@ -1508,6 +1509,7 @@ def _load_ip_services():
             'name': _s['name'],
             'customer': _s['customer'],
             'type': _s['service_type'],
+            'status': _s['status'],
             'pop': {
                 'name': _s['pop_name'],
                 'abbrev': _s['pop_abbreviation']
diff --git a/test/test_msr_routes.py b/test/test_msr_routes.py
index 80fef05f..157dfd28 100644
--- a/test/test_msr_routes.py
+++ b/test/test_msr_routes.py
@@ -1,3 +1,4 @@
+import ipaddress
 import json
 import jsonschema
 
@@ -418,3 +419,16 @@ def test_ip_services(client):
     # sanity that there are some non-trivial elements in test data
     assert any(len(_x['peerings']) > 0 for _x in response_data)
     assert any(len(_x['services']) > 0 for _x in response_data)
+
+    # sanity confirmation that peerings are with the correct host
+    for _s in response_data:
+        net = ipaddress.ip_interface(_s['address']).network
+        for _p in _s['peerings']:
+            assert ipaddress.ip_address(_p['address']) in net
+
+    # sanity confirmation that no interface addresses are duplicated
+    ifc_keys = set()
+    for _s in response_data:
+        key = f'{_s["hostname"]}:{_s["port"]}:{_s["address"]}'
+        assert key not in ifc_keys
+        ifc_keys.add(key)
-- 
GitLab