aboutsummaryrefslogtreecommitdiffstats
path: root/test/mocks/netconf-pnp-simulator/engine/tests/nctest.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/mocks/netconf-pnp-simulator/engine/tests/nctest.py')
-rw-r--r--test/mocks/netconf-pnp-simulator/engine/tests/nctest.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/test/mocks/netconf-pnp-simulator/engine/tests/nctest.py b/test/mocks/netconf-pnp-simulator/engine/tests/nctest.py
new file mode 100644
index 000000000..c508ca47a
--- /dev/null
+++ b/test/mocks/netconf-pnp-simulator/engine/tests/nctest.py
@@ -0,0 +1,50 @@
+import logging
+
+from ncclient import manager, operations
+
+import settings
+
+LOGGER = logging.getLogger(__name__)
+
+
+def check_reply_ok(reply):
+ assert reply is not None
+ _log_netconf_msg("Received", reply.xml)
+ assert reply.ok is True
+ assert reply.error is None
+
+
+def check_reply_err(reply):
+ assert reply is not None
+ _log_netconf_msg("Received", reply.xml)
+ assert reply.ok is False
+ assert reply.error is not None
+
+
+def check_reply_data(reply):
+ check_reply_ok(reply)
+
+
+def _log_netconf_msg(header: str, body: str):
+ """Log a message using a format inspired by NETCONF 1.1 """
+ LOGGER.info("%s:\n\n#%d\n%s\n##", header, len(body), body)
+
+
+class NCTestCase:
+ """ Base class for NETCONF test cases. Provides a NETCONF connection and some helper methods. """
+
+ nc: manager.Manager
+
+ def setup(self):
+ self.nc = manager.connect(
+ host=settings.HOST,
+ port=settings.SSH_PORT,
+ username=settings.USERNAME,
+ key_filename=settings.SSH_KEY_FILENAME,
+ allow_agent=False,
+ look_for_keys=False,
+ hostkey_verify=False)
+ self.nc.raise_mode = operations.RaiseMode.NONE
+
+ def teardown(self):
+ self.nc.close_session()