From 9283fcb07e3fef7afbc34b71c2f2e56306f15f8b Mon Sep 17 00:00:00 2001
From: merle <sebastien.merle@stritzinger.com>
Date: Wed, 8 Feb 2023 11:58:16 -0800
Subject: [PATCH] Update TE service configuration format

---
 src/te/apps/tfte/src/tfte_topology.erl | 21 +++++++++++++--------
 src/te/config/sys.config.src           |  2 +-
 src/te/tests/topology-descriptors.json | 20 +++++++-------------
 3 files changed, 21 insertions(+), 22 deletions(-)

diff --git a/src/te/apps/tfte/src/tfte_topology.erl b/src/te/apps/tfte/src/tfte_topology.erl
index 886fd926d..d9505e914 100644
--- a/src/te/apps/tfte/src/tfte_topology.erl
+++ b/src/te/apps/tfte/src/tfte_topology.erl
@@ -281,18 +281,23 @@ device_status(#{device_operational_status := 'DEVICEOPERATIONALSTATUS_ENABLED'})
     enabled.
 
 device_mpls_label(Device) ->
-    try device_config_value(<<"/te_data/mpls_label">>, Device)
+    try device_config_value(<<"/te_data">>, Device) of
+        Map when is_map(Map) -> maps:get(<<"mpls_label">>, Map, undefined);
+        _ -> undefined
     catch error:badarg -> undefined
     end.
 
 device_pcc_address(Device) ->
-    try device_config_value(<<"/te_data/pcc_address">>, Device) of
-        undefined -> undefined;
-        AddressBin ->
-            case inet_parse:address(binary_to_list(AddressBin)) of
-                {ok, Address} -> Address;
-                {error,einval} -> undefined
-            end
+    try device_config_value(<<"/te_data">>, Device) of
+        Map when is_map(Map) ->
+            case maps:get(<<"pcc_address">>, Map, undefined) of
+                AddressBin ->
+                    case inet_parse:address(binary_to_list(AddressBin)) of
+                        {ok, Address} -> Address;
+                        {error,einval} -> undefined
+                    end
+            end;
+        _ -> undefined
     catch
         error:badarg -> undefined
     end.
diff --git a/src/te/config/sys.config.src b/src/te/config/sys.config.src
index f3c185641..b1640c109 100644
--- a/src/te/config/sys.config.src
+++ b/src/te/config/sys.config.src
@@ -2,7 +2,7 @@
 
     {tfte, [
         {context, <<"admin">>},
-        {topology, <<"tetestbed">>},
+        {topology, <<"admin">>},
         {services, [
             {te, [
                 {http, {env, "TESERVICE_SERVICE_HOST"}, {env, "TESERVICE_SERVICE_PORT_GRPC"}, []}
diff --git a/src/te/tests/topology-descriptors.json b/src/te/tests/topology-descriptors.json
index 82f37ce29..a34d8ce09 100644
--- a/src/te/tests/topology-descriptors.json
+++ b/src/te/tests/topology-descriptors.json
@@ -8,7 +8,7 @@
     ],
     "topologies": [
         {
-            "topology_id": {"topology_uuid": {"uuid": "tetestbed"}, "context_id": {"context_uuid": {"uuid": "admin"}}},
+            "topology_id": {"topology_uuid": {"uuid": "admin"}, "context_id": {"context_uuid": {"uuid": "admin"}}},
             "device_ids": [
                 {"device_uuid": {"uuid": "SW1"}},
                 {"device_uuid": {"uuid": "RT1"}},
@@ -54,8 +54,7 @@
                     {"sample_types": [], "type": "copper", "uuid": "eth-src"},
                     {"sample_types": [], "type": "copper", "uuid": "eth-sw1"}
                 ]}}},
-                {"action": 1, "custom": {"resource_key": "/te_data/mpls_label", "resource_value": "16010"}},
-                {"action": 1, "custom": {"resource_key": "/te_data/pcc_address", "resource_value": "1.1.1.1"}}
+                {"action": 1, "custom": {"resource_key": "/te_data", "resource_value": {"mpls_label": 16010, "pcc_address": "1.1.1.1"}}}
             ]}
         },
         {
@@ -69,8 +68,7 @@
                     {"sample_types": [], "type": "copper", "uuid": "eth-rt4-1"},
                     {"sample_types": [], "type": "copper", "uuid": "eth-rt4-2"}
                 ]}}},
-                {"action": 1, "custom": {"resource_key": "/te_data/mpls_label", "resource_value": "16020"}},
-                {"action": 1, "custom": {"resource_key": "/te_data/pcc_address", "resource_value": "2.2.2.2"}}
+                {"action": 1, "custom": {"resource_key": "/te_data", "resource_value": {"mpls_label": 16020, "pcc_address": "2.2.2.2"}}}
             ]}
         },
         {
@@ -84,8 +82,7 @@
                     {"sample_types": [], "type": "copper", "uuid": "eth-rt5-1"},
                     {"sample_types": [], "type": "copper", "uuid": "eth-rt5-2"}
                 ]}}},
-                {"action": 1, "custom": {"resource_key": "/te_data/mpls_label", "resource_value": "16030"}},
-                {"action": 1, "custom": {"resource_key": "/te_data/pcc_address", "resource_value": "3.3.3.3"}}
+                {"action": 1, "custom": {"resource_key": "/te_data", "resource_value": {"mpls_label": 16030, "pcc_address": "3.3.3.3"}}}
             ]}
         },
         {
@@ -100,8 +97,7 @@
                     {"sample_types": [], "type": "copper", "uuid": "eth-rt5"},
                     {"sample_types": [], "type": "copper", "uuid": "eth-rt6"}
                 ]}}},
-                {"action": 1, "custom": {"resource_key": "/te_data/mpls_label", "resource_value": "16040"}},
-                {"action": 1, "custom": {"resource_key": "/te_data/pcc_address", "resource_value": "4.4.4.4"}}
+                {"action": 1, "custom": {"resource_key": "/te_data", "resource_value": {"mpls_label": 16040, "pcc_address": "4.4.4.4"}}}
             ]}
         },
         {
@@ -116,8 +112,7 @@
                     {"sample_types": [], "type": "copper", "uuid": "eth-rt4"},
                     {"sample_types": [], "type": "copper", "uuid": "eth-rt6"}
                 ]}}},
-                {"action": 1, "custom": {"resource_key": "/te_data/mpls_label", "resource_value": "16050"}},
-                {"action": 1, "custom": {"resource_key": "/te_data/pcc_address", "resource_value": "5.5.5.5"}}
+                {"action": 1, "custom": {"resource_key": "/te_data", "resource_value": {"mpls_label": 16050, "pcc_address": "5.5.5.5"}}}
             ]}
         },
         {
@@ -131,8 +126,7 @@
                     {"sample_types": [], "type": "copper", "uuid": "eth-rt5"},
                     {"sample_types": [], "type": "copper", "uuid": "eth-dst"}
                 ]}}},
-                {"action": 1, "custom": {"resource_key": "/te_data/mpls_label", "resource_value": "16060"}},
-                {"action": 1, "custom": {"resource_key": "/te_data/pcc_address", "resource_value": "6.6.6.6"}}
+                {"action": 1, "custom": {"resource_key": "/te_data", "resource_value": {"mpls_label": 16060, "pcc_address": "6.6.6.6"}}}
             ]}
         }
     ],
-- 
GitLab