Add endpoint for config get 46/120046/1 honolulu
authorTomasz Pietruszkiewicz <tomasz.pietruszkiewicz@nokia.com>
Wed, 31 Mar 2021 10:23:33 +0000 (12:23 +0200)
committerTomasz Pietruszkiewicz <tomasz.pietruszkiewicz@nokia.com>
Wed, 31 Mar 2021 10:23:33 +0000 (12:23 +0200)
Change-Id: I3e58a2e0e60a71920460908ef20b322ff328154a
Issue-ID: INT-1869
Signed-off-by: Tomasz Pietruszkiewicz <tomasz.pietruszkiewicz@nokia.com>
src/python/netconf_server/netconf_rest_server.py
src/python/netconf_server/sysrepo_configuration/sysrepo_configuration_manager.py
src/python/tests/unit/sysrepo_configuration/test_sysrepo_configuration_manager_.py

index e90c104..8568454 100644 (file)
@@ -77,6 +77,13 @@ class NetconfRestServer:
         NetconfRestServer._configuration_manager.change_configuration(config_data, module_name)
         return NetconfRestServer.__create_http_response(202, "Accepted")
 
+    @staticmethod
+    @_rest_server.route("/get_config/<path:module_name>", methods=['GET'])
+    def _get_config(module_name):
+        data = NetconfRestServer._configuration_manager.get_configuration(module_name)
+        return NetconfRestServer.__create_http_response(200, data)
+
+
     @staticmethod
     def __create_http_response(code, message):
         return make_response(
index 0e8ad94..7e209e6 100644 (file)
@@ -14,7 +14,7 @@
 # limitations under the License.
 # ============LICENSE_END=========================================================
 ###
-
+import json
 import logging
 
 
@@ -39,3 +39,7 @@ class SysrepoConfigurationManager(object):
     def change_configuration(self, config_data: str, module_name: str):
         data = self.__parse_config_data(config_data)
         self._session.replace_config_ly(data, module_name)
+
+    def get_configuration(self, module_name: str):
+        data = self._session.get_data("/" + module_name + ":*")
+        return json.dumps(data, indent=4)
index 5194218..6c83f5f 100644 (file)
@@ -1,3 +1,4 @@
+import json
 import unittest
 from unittest.mock import MagicMock
 from netconf_server.sysrepo_configuration.sysrepo_configuration_manager import SysrepoConfigurationManager
@@ -29,3 +30,20 @@ class TestSysrepoConfigurationManager(unittest.TestCase):
         # then
         ctx.parse_data_mem.assert_called_with(config_data, "xml", config=True, strict=False)
         session.replace_config_ly.assert_called_with(expected_parse_data, module_name)
+
+    def test_should_get_configuration(self):
+        # given
+        expected_parse_data = '{"config": {"itemValue1": 42,"itemValue2": 35}}'
+
+        connection = MagicMock()
+        session = MagicMock()
+        session.get_data = MagicMock(return_value=expected_parse_data)
+        module_name = "pnf-simulator"
+
+        # when
+        config_manager = SysrepoConfigurationManager(session=session, connection=connection)
+        data = config_manager.get_configuration(module_name=module_name)
+
+        # then
+        session.get_data.assert_called_with("/" + module_name + ":*")
+        self.assertEqual(data, json.dumps(expected_parse_data))