diff options
author | 2020-04-11 01:34:47 +0100 | |
---|---|---|
committer | 2020-04-15 10:46:07 +0000 | |
commit | 398c9b251dc910c4cffc4fc5a3c2b8b221980c91 (patch) | |
tree | fa7df466e1a0f4a028445f58992686005e5c80f9 /test/mocks/netconf-pnp-simulator/engine/tests/nctest.py | |
parent | 09e87eeadf879bbaa5237a34db1583861097925c (diff) |
netconf-pnp-simulator: enable NETCONF send/recv message logging
to aid troubleshooting integration with OpenDaylight
- Add more integration tests
- Defaults to generic subscriber
Issue-ID: INT-1516
Change-Id: Ib5bbf4cdbba6cdfee901f6c07dfa195a21cd8bbb
Signed-off-by: ebo <eliezio.oliveira@est.tech>
Diffstat (limited to 'test/mocks/netconf-pnp-simulator/engine/tests/nctest.py')
-rw-r--r-- | test/mocks/netconf-pnp-simulator/engine/tests/nctest.py | 55 |
1 files changed, 34 insertions, 21 deletions
diff --git a/test/mocks/netconf-pnp-simulator/engine/tests/nctest.py b/test/mocks/netconf-pnp-simulator/engine/tests/nctest.py index 2f848c361..11ff6ffc4 100644 --- a/test/mocks/netconf-pnp-simulator/engine/tests/nctest.py +++ b/test/mocks/netconf-pnp-simulator/engine/tests/nctest.py @@ -1,11 +1,41 @@ +import logging.config + from ncclient import manager, operations + import settings -import unittest -class NCTestCase(unittest.TestCase): +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. """ - def setUp(self): + nc: manager.Manager + + def setup(self): self.nc = manager.connect( host=settings.HOST, port=settings.PORT, @@ -16,22 +46,5 @@ class NCTestCase(unittest.TestCase): hostkey_verify=False) self.nc.raise_mode = operations.RaiseMode.NONE - def tearDown(self): + def teardown(self): self.nc.close_session() - - def check_reply_ok(self, reply): - self.assertIsNotNone(reply) - if settings.DEBUG: - print(reply.xml) - self.assertTrue(reply.ok) - self.assertIsNone(reply.error) - - def check_reply_err(self, reply): - self.assertIsNotNone(reply) - if settings.DEBUG: - print(reply.xml) - self.assertFalse(reply.ok) - self.assertIsNotNone(reply.error) - - def check_reply_data(self, reply): - self.check_reply_ok(reply) |