From 8eb3462c8e2ac30e516a832bc01c17cd312a86a2 Mon Sep 17 00:00:00 2001 From: lily Date: Fri, 22 Sep 2017 14:21:29 -0700 Subject: [PATCH] updated netconf service provider with timeout parameter (#492 #424) --- .../api/ydk/providers/netconf_provider.rst | 8 +++- sdk/cpp/core/src/netconf_provider.cpp | 14 ++++--- sdk/cpp/core/src/netconf_provider.hpp | 6 ++- sdk/cpp/core/src/path_api.hpp | 1 - .../api/providers/netconf_provider.rst | 3 +- sdk/python/core/python.cpp | 35 ++++++++++------- .../core/tests/test_netconf_operations.py | 19 +++++++-- .../core/tests/test_netconf_provider.py | 19 +++++++-- sdk/python/core/tests/test_on_demand.py | 29 ++++++++++++-- .../core/tests/test_sanity_augmentation.py | 19 +++++++-- sdk/python/core/tests/test_sanity_delete.py | 19 +++++++-- .../core/tests/test_sanity_deviation.py | 19 +++++++-- sdk/python/core/tests/test_sanity_errors.py | 19 +++++++-- .../core/tests/test_sanity_executor_rpc.py | 19 +++++++-- .../core/tests/test_sanity_filter_read.py | 19 +++++++-- sdk/python/core/tests/test_sanity_filters.py | 19 +++++++-- sdk/python/core/tests/test_sanity_levels.py | 19 +++++++-- sdk/python/core/tests/test_sanity_netconf.py | 19 +++++++-- sdk/python/core/tests/test_sanity_path.py | 19 +++++++-- .../core/tests/test_sanity_service_errors.py | 39 ++++++++++++++++--- .../tests/test_sanity_type_mismatch_errors.py | 19 +++++++-- sdk/python/core/tests/test_sanity_types.py | 19 +++++++-- sdk/python/core/tests/test_utils.py | 7 +++- 23 files changed, 328 insertions(+), 80 deletions(-) diff --git a/sdk/cpp/core/docsgen/api/ydk/providers/netconf_provider.rst b/sdk/cpp/core/docsgen/api/ydk/providers/netconf_provider.rst index 03eb03ab7..84e99ada0 100644 --- a/sdk/cpp/core/docsgen/api/ydk/providers/netconf_provider.rst +++ b/sdk/cpp/core/docsgen/api/ydk/providers/netconf_provider.rst @@ -13,7 +13,8 @@ NetconfServiceProvider int port = 830, \ const std::string& protocol = "ssh", \ bool on_demand = true, \ - bool common_cache = false) + bool common_cache = false, + int timeout = -1) Constructs an instance of ``NetconfServiceProvider`` connect to a server which **has** to support model download @@ -24,6 +25,7 @@ NetconfServiceProvider :param protocol: ``ssh`` or ``tcp``. :param on_demand: On demand downloading by default. :param common_cache: Use common caching directory if enabled. + :param timeout: The timeout in microseconds, -1 for infinite timeout, 0 for non-blocking .. cpp:function:: NetconfServiceProvider(\ const path::Repository& repo, \ @@ -32,7 +34,8 @@ NetconfServiceProvider std::string password, \ int port = 830, \ const std::string& protocol = "ssh", \ - bool on_demand = true) + bool on_demand = true, + int timeout = -1) Constructs an instance of ``NetconfServiceProvider`` using the provided :cpp:class:`repository` @@ -41,6 +44,7 @@ NetconfServiceProvider :param username: Username to log in to the device :param password: Password to log in to the device :param port: Device port used to access the netconf interface. Default value is 830 + :param timeout: The timeout in microseconds, -1 for infinite timeout, 0 for non-blocking .. cpp:function:: EncodingFormat get_encoding() const diff --git a/sdk/cpp/core/src/netconf_provider.cpp b/sdk/cpp/core/src/netconf_provider.cpp index ad33b3e9e..d077c6c05 100644 --- a/sdk/cpp/core/src/netconf_provider.cpp +++ b/sdk/cpp/core/src/netconf_provider.cpp @@ -48,10 +48,11 @@ NetconfServiceProvider::NetconfServiceProvider(const string& address, int port, const string& protocol, bool on_demand, - bool common_cache) - : session{address, username, password, port, protocol, on_demand, common_cache} + bool common_cache, + int timeout) + : session{address, username, password, port, protocol, on_demand, common_cache, timeout} { - YLOG_INFO("Connected to {} on port {} using {}", address, port, protocol); + YLOG_INFO("Connected to {} on port {} using {} with timeout of {}", address, port, protocol, timeout); } NetconfServiceProvider::NetconfServiceProvider(path::Repository & repo, @@ -60,10 +61,11 @@ NetconfServiceProvider::NetconfServiceProvider(path::Repository & repo, const string& password, int port, const string& protocol, - bool on_demand) - : session{repo, address, username, password, port, protocol, on_demand} + bool on_demand, + int timeout) + : session{repo, address, username, password, port, protocol, on_demand, timeout} { - YLOG_INFO("Connected to {} on port {} using {}", address, port, protocol); + YLOG_INFO("Connected to {} on port {} using {} with timeout of ", address, port, protocol, timeout); } NetconfServiceProvider::~NetconfServiceProvider() diff --git a/sdk/cpp/core/src/netconf_provider.hpp b/sdk/cpp/core/src/netconf_provider.hpp index 64d10847b..15bd85f59 100644 --- a/sdk/cpp/core/src/netconf_provider.hpp +++ b/sdk/cpp/core/src/netconf_provider.hpp @@ -34,14 +34,16 @@ class NetconfServiceProvider : public ServiceProvider { const std::string& password, int port = 830, const std::string& protocol = "ssh", - bool on_demand = true); + bool on_demand = true, + int timeout = -1); NetconfServiceProvider(const std::string& address, const std::string& username, const std::string& password, int port = 830, const std::string& protocol = "ssh", bool on_demand = true, - bool common_cache = false); + bool common_cache = false, + int timeout = -1); ~NetconfServiceProvider(); EncodingFormat get_encoding() const; const path::Session& get_session() const; diff --git a/sdk/cpp/core/src/path_api.hpp b/sdk/cpp/core/src/path_api.hpp index 2b5308413..e5f410bc9 100644 --- a/sdk/cpp/core/src/path_api.hpp +++ b/sdk/cpp/core/src/path_api.hpp @@ -1043,7 +1043,6 @@ class NetconfSession : public Session { int timeout); std::string execute_payload(const std::string & payload) const; private: - int session_timeout; std::unique_ptr client; std::unique_ptr model_provider; std::shared_ptr root_schema; diff --git a/sdk/python/core/docsgen/api/providers/netconf_provider.rst b/sdk/python/core/docsgen/api/providers/netconf_provider.rst index ebdb2936c..91226671f 100644 --- a/sdk/python/core/docsgen/api/providers/netconf_provider.rst +++ b/sdk/python/core/docsgen/api/providers/netconf_provider.rst @@ -2,7 +2,7 @@ NETCONF Service Provider ======================== -.. py:class:: ydk.providers.NetconfServiceProvider(address, username, password, port=830, protocol='ssh', repo=None) +.. py:class:: ydk.providers.NetconfServiceProvider(address, username, password, port=830, protocol='ssh', timeout=-1, repo=None) Constructs an instance of the ``NetconfServiceProvider`` to connect to a server which **has** to support model download. Since the class is a Python wrapper for C++ ``NetconfServiceProvider`` class, which has clean up methods implemented in its destructor. The user does not need to worry about close NETCONF session. @@ -11,6 +11,7 @@ NETCONF Service Provider :param username: (``str``) Username to log in to the device :param password: (``str``) Password to log in to the device :param protocol: (``str``) Defaults to ``ssh``, currently support ``ssh`` + :param timeout: (``int``) The timeout in microseconds, -1 for infinite timeout, 0 for non-blocking :param repo: User provided repository stores cached models :type repo: :py:class:`Repository` diff --git a/sdk/python/core/python.cpp b/sdk/python/core/python.cpp index cf02585f8..e3df63ec5 100644 --- a/sdk/python/core/python.cpp +++ b/sdk/python/core/python.cpp @@ -593,8 +593,8 @@ PYBIND11_MODULE(ydk_, ydk) class_(providers, "NetconfServiceProvider") .def("__init__", - [](ydk::NetconfServiceProvider &nc_provider, ydk::path::Repository& repo, const string& address, const string& username, const string& password, int port, const string& protocol, bool on_demand) { - new(&nc_provider) ydk::NetconfServiceProvider(repo, address, username, password, port, protocol, on_demand); + [](ydk::NetconfServiceProvider &nc_provider, ydk::path::Repository& repo, const string& address, const string& username, const string& password, int port, const string& protocol, bool on_demand, int timeout) { + new(&nc_provider) ydk::NetconfServiceProvider(repo, address, username, password, port, protocol, on_demand, timeout); }, arg("repo"), arg("address"), @@ -602,10 +602,11 @@ PYBIND11_MODULE(ydk_, ydk) arg("password"), arg("port")=830, arg("protocol")=string("ssh"), - arg("on_demand")=true) + arg("on_demand")=true, + arg("timeout")=-1) .def("__init__", - [](ydk::NetconfServiceProvider &nc_provider, const string& address, const string& username, const string& password, int port, const string& protocol, bool on_demand, bool common_cache) { - new(&nc_provider) ydk::NetconfServiceProvider(address, username, password, port, protocol, on_demand, common_cache); + [](ydk::NetconfServiceProvider &nc_provider, const string& address, const string& username, const string& password, int port, const string& protocol, bool on_demand, bool common_cache, int timeout) { + new(&nc_provider) ydk::NetconfServiceProvider(address, username, password, port, protocol, on_demand, common_cache, timeout); }, arg("address"), arg("username"), @@ -613,10 +614,11 @@ PYBIND11_MODULE(ydk_, ydk) arg("port")=830, arg("protocol")=string("ssh"), arg("on_demand")=true, - arg("common_cache")=false) + arg("common_cache")=false, + arg("timeout")=-1) .def("__init__", - [](ydk::NetconfServiceProvider &nc_provider, const string& address, const string& username, const string& password, void* port, const string& protocol, bool on_demand, bool common_cache) { - new(&nc_provider) ydk::NetconfServiceProvider(address, username, password, 830, protocol, on_demand, common_cache); + [](ydk::NetconfServiceProvider &nc_provider, const string& address, const string& username, const string& password, void* port, const string& protocol, bool on_demand, bool common_cache, int timeout) { + new(&nc_provider) ydk::NetconfServiceProvider(address, username, password, 830, protocol, on_demand, common_cache, timeout); }, arg("address"), arg("username"), @@ -624,26 +626,29 @@ PYBIND11_MODULE(ydk_, ydk) arg("port")=nullptr, arg("protocol")=string("ssh"), arg("on_demand")=true, - arg("common_cache")=false) + arg("common_cache")=false, + arg("timeout")=-1) .def("__init__", - [](ydk::NetconfServiceProvider &nc_provider, const string& address, const string& username, const string& password, int port, bool on_demand, bool common_cache) { - new(&nc_provider) ydk::NetconfServiceProvider(address, username, password, port, "ssh", on_demand, common_cache); + [](ydk::NetconfServiceProvider &nc_provider, const string& address, const string& username, const string& password, int port, bool on_demand, bool common_cache, int timeout) { + new(&nc_provider) ydk::NetconfServiceProvider(address, username, password, port, "ssh", on_demand, common_cache, timeout); }, arg("address"), arg("username"), arg("password"), arg("port")=830, arg("on_demand")=true, - arg("common_cache")=false) + arg("common_cache")=false, + arg("timeout")=-1) .def("__init__", - [](ydk::NetconfServiceProvider &nc_provider, const string& address, const string& username, const string& password, bool on_demand, bool common_cache) { - new(&nc_provider) ydk::NetconfServiceProvider(address, username, password, 830, "ssh", on_demand, common_cache); + [](ydk::NetconfServiceProvider &nc_provider, const string& address, const string& username, const string& password, bool on_demand, bool common_cache, int timeout) { + new(&nc_provider) ydk::NetconfServiceProvider(address, username, password, 830, "ssh", on_demand, common_cache, timeout); }, arg("address"), arg("username"), arg("password"), arg("on_demand")=true, - arg("common_cache")=false) + arg("common_cache")=false, + arg("timeout")=-1) .def("get_encoding", &ydk::NetconfServiceProvider::get_encoding, return_value_policy::reference) .def("get_session", &ydk::NetconfServiceProvider::get_session, return_value_policy::reference) .def("get_capabilities", &ydk::NetconfServiceProvider::get_capabilities, return_value_policy::reference); diff --git a/sdk/python/core/tests/test_netconf_operations.py b/sdk/python/core/tests/test_netconf_operations.py index 94f1da769..98549f84b 100644 --- a/sdk/python/core/tests/test_netconf_operations.py +++ b/sdk/python/core/tests/test_netconf_operations.py @@ -95,7 +95,15 @@ class SanityTest(unittest.TestCase): @classmethod def setUpClass(cls): - cls.ncc = NetconfServiceProvider(cls.hostname, cls.username, cls.password, cls.port, cls.protocol, cls.on_demand, cls.common_cache) + cls.ncc = NetconfServiceProvider( + cls.hostname, + cls.username, + cls.password, + cls.port, + cls.protocol, + cls.on_demand, + cls.common_cache, + cls.timeout) cls.crud = CRUDService() def setUp(self): @@ -220,9 +228,14 @@ def test_delete_leaflist(self): if __name__ == '__main__': - device, non_demand, common_cache = get_device_info() + device, non_demand, common_cache, timeout = get_device_info() suite = unittest.TestSuite() - suite.addTest(ParametrizedTestCase.parametrize(SanityTest, device=device, non_demand=non_demand, common_cache=common_cache)) + suite.addTest(ParametrizedTestCase.parametrize( + SanityTest, + device=device, + non_demand=non_demand, + common_cache=common_cache, + timeout=timeout)) ret = not unittest.TextTestRunner(verbosity=2).run(suite).wasSuccessful() sys.exit(ret) diff --git a/sdk/python/core/tests/test_netconf_provider.py b/sdk/python/core/tests/test_netconf_provider.py index 45e8b9888..1a5e8bc80 100644 --- a/sdk/python/core/tests/test_netconf_provider.py +++ b/sdk/python/core/tests/test_netconf_provider.py @@ -31,7 +31,15 @@ class SanityTest(unittest.TestCase): @classmethod def setUpClass(cls): - cls.ncc = NetconfServiceProvider(cls.hostname, cls.username, cls.password, cls.port, cls.protocol, cls.on_demand, cls.common_cache) + cls.ncc = NetconfServiceProvider( + cls.hostname, + cls.username, + cls.password, + cls.port, + cls.protocol, + cls.on_demand, + cls.common_cache, + cls.timeout) def test_get_session(self): session = self.ncc.get_session() @@ -47,9 +55,14 @@ def test_get_capabilities(self): if __name__ == '__main__': - device, non_demand, common_cache = get_device_info() + device, non_demand, common_cache, timeout = get_device_info() suite = unittest.TestSuite() - suite.addTest(ParametrizedTestCase.parametrize(SanityTest, device=device, non_demand=non_demand, common_cache=common_cache)) + suite.addTest(ParametrizedTestCase.parametrize( + SanityTest, + device=device, + non_demand=non_demand, + common_cache=common_cache, + timeout=timeout)) ret = not unittest.TextTestRunner(verbosity=2).run(suite).wasSuccessful() sys.exit(ret) diff --git a/sdk/python/core/tests/test_on_demand.py b/sdk/python/core/tests/test_on_demand.py index 3aef4d5a0..15b0b457b 100644 --- a/sdk/python/core/tests/test_on_demand.py +++ b/sdk/python/core/tests/test_on_demand.py @@ -121,8 +121,24 @@ def setUpClass(cls): tmp_dir = tempfile.mkdtemp() repo = Repository(tmp_dir) - cls.ncc_empty_repo = NetconfServiceProvider(repo, cls.hostname, cls.username, cls.password, cls.port, cls.protocol, cls.on_demand) - cls.ncc = NetconfServiceProvider(cls.hostname, cls.username, cls.password, cls.port, cls.protocol, cls.on_demand, cls.common_cache) + cls.ncc_empty_repo = NetconfServiceProvider( + repo, + cls.hostname, + cls.username, + cls.password, + cls.port, + cls.protocol, + cls.on_demand, + cls.timeout) + cls.ncc = NetconfServiceProvider( + cls.hostname, + cls.username, + cls.password, + cls.port, + cls.protocol, + cls.on_demand, + cls.common_cache, + cls.timeout) cls.crud = CRUDService() cls.codec_provider = CodecServiceProvider() @@ -159,9 +175,14 @@ def test_on_demand_loading_json(self): if __name__ == '__main__': - device, non_demand, common_cache = get_device_info() + device, non_demand, common_cache, timeout = get_device_info() suite = unittest.TestSuite() - suite.addTest(ParametrizedTestCase.parametrize(SanityYang, device=device, non_demand=non_demand, common_cache=common_cache)) + suite.addTest(ParametrizedTestCase.parametrize( + SanityYang, + device=device, + non_demand=non_demand, + common_cache=common_cache, + timeout=timeout)) ret = not unittest.TextTestRunner(verbosity=2).run(suite).wasSuccessful() sys.exit(ret) diff --git a/sdk/python/core/tests/test_sanity_augmentation.py b/sdk/python/core/tests/test_sanity_augmentation.py index 66e371654..5ec76f7b2 100644 --- a/sdk/python/core/tests/test_sanity_augmentation.py +++ b/sdk/python/core/tests/test_sanity_augmentation.py @@ -36,7 +36,15 @@ class SanityYang(unittest.TestCase): @classmethod def setUpClass(cls): - cls.ncc = NetconfServiceProvider(cls.hostname, cls.username, cls.password, cls.port, cls.protocol, cls.on_demand, cls.common_cache) + cls.ncc = NetconfServiceProvider( + cls.hostname, + cls.username, + cls.password, + cls.port, + cls.protocol, + cls.on_demand, + cls.common_cache, + cls.timeout) cls.crud = CRUDService() def setUp(self): @@ -79,9 +87,14 @@ def test_aug_base_2(self): if __name__ == '__main__': - device, non_demand, common_cache = get_device_info() + device, non_demand, common_cache, timeout = get_device_info() suite = unittest.TestSuite() - suite.addTest(ParametrizedTestCase.parametrize(SanityYang, device=device, non_demand=non_demand, common_cache=common_cache)) + suite.addTest(ParametrizedTestCase.parametrize( + SanityYang, + device=device, + non_demand=non_demand, + common_cache=common_cache, + timeout=timeout)) ret = not unittest.TextTestRunner(verbosity=2).run(suite).wasSuccessful() sys.exit(ret) diff --git a/sdk/python/core/tests/test_sanity_delete.py b/sdk/python/core/tests/test_sanity_delete.py index 24aff471d..40acf85ef 100644 --- a/sdk/python/core/tests/test_sanity_delete.py +++ b/sdk/python/core/tests/test_sanity_delete.py @@ -36,7 +36,15 @@ class SanityYang(unittest.TestCase): @classmethod def setUpClass(cls): - cls.ncc = NetconfServiceProvider(cls.hostname, cls.username, cls.password, cls.port, cls.protocol, cls.on_demand, cls.common_cache) + cls.ncc = NetconfServiceProvider( + cls.hostname, + cls.username, + cls.password, + cls.port, + cls.protocol, + cls.on_demand, + cls.common_cache, + cls.timeout) cls.crud = CRUDService() @classmethod @@ -302,9 +310,14 @@ def test_delete_on_list(self): if __name__ == '__main__': - device, non_demand, common_cache = get_device_info() + device, non_demand, common_cache, timeout = get_device_info() suite = unittest.TestSuite() - suite.addTest(ParametrizedTestCase.parametrize(SanityYang, device=device, non_demand=non_demand, common_cache=common_cache)) + suite.addTest(ParametrizedTestCase.parametrize( + SanityYang, + device = device, + non_demand = non_demand, + common_cache = common_cache, + timeout = timeout)) ret = not unittest.TextTestRunner(verbosity=2).run(suite).wasSuccessful() sys.exit(ret) diff --git a/sdk/python/core/tests/test_sanity_deviation.py b/sdk/python/core/tests/test_sanity_deviation.py index c008fdeec..10f74409c 100644 --- a/sdk/python/core/tests/test_sanity_deviation.py +++ b/sdk/python/core/tests/test_sanity_deviation.py @@ -35,7 +35,15 @@ class SanityTest(unittest.TestCase): @classmethod def setUpClass(cls): - cls.ncc = NetconfServiceProvider(cls.hostname, cls.username, cls.password, 12023, cls.protocol, cls.on_demand, cls.common_cache) + cls.ncc = NetconfServiceProvider( + cls.hostname, + cls.username, + cls.password, + 12023, + cls.protocol, + cls.on_demand, + cls.common_cache, + cls.timeout) cls.crud = CRUDService() def tearDown(self): @@ -204,9 +212,14 @@ def test_leaflist_max_elements(self): if __name__ == '__main__': - device, non_demand, common_cache = get_device_info() + device, non_demand, common_cache, timeout = get_device_info() suite = unittest.TestSuite() - suite.addTest(ParametrizedTestCase.parametrize(SanityTest, device=device, non_demand=non_demand, common_cache=common_cache)) + suite.addTest(ParametrizedTestCase.parametrize( + SanityTest, + device=device, + non_demand=non_demand, + common_cache=common_cache, + timeout=timeout)) ret = not unittest.TextTestRunner(verbosity=2).run(suite).wasSuccessful() sys.exit(ret) diff --git a/sdk/python/core/tests/test_sanity_errors.py b/sdk/python/core/tests/test_sanity_errors.py index f93c456c3..d9ba83497 100644 --- a/sdk/python/core/tests/test_sanity_errors.py +++ b/sdk/python/core/tests/test_sanity_errors.py @@ -107,7 +107,15 @@ class SanityTest(unittest.TestCase): @classmethod def setUpClass(cls): - cls.ncc = NetconfServiceProvider(cls.hostname, cls.username, cls.password, cls.port, cls.protocol, cls.on_demand, cls.common_cache) + cls.ncc = NetconfServiceProvider( + cls.hostname, + cls.username, + cls.password, + cls.port, + cls.protocol, + cls.on_demand, + cls.common_cache, + cls.timeout) cls.crud = CRUDService() def setUp(self): @@ -210,9 +218,14 @@ def test_ylist_assignment(self): if __name__ == '__main__': - device, non_demand, common_cache = get_device_info() + device, non_demand, common_cache, timeout = get_device_info() suite = unittest.TestSuite() - suite.addTest(ParametrizedTestCase.parametrize(SanityTest, device=device, non_demand=non_demand, common_cache=common_cache)) + suite.addTest(ParametrizedTestCase.parametrize( + SanityTest, + device=device, + non_demand=non_demand, + common_cache=common_cache, + timeout=timeout)) ret = not unittest.TextTestRunner(verbosity=2).run(suite).wasSuccessful() sys.exit(ret) diff --git a/sdk/python/core/tests/test_sanity_executor_rpc.py b/sdk/python/core/tests/test_sanity_executor_rpc.py index 28e032f02..50ead8681 100644 --- a/sdk/python/core/tests/test_sanity_executor_rpc.py +++ b/sdk/python/core/tests/test_sanity_executor_rpc.py @@ -45,7 +45,15 @@ def setUp(self): # start a brand new session for every single test case # so test_close_session_rpc will not interfere with other test cases # self.ncc = NetconfServiceProvider('127.0.0.1', 'admin', 'admin', 12022) - self.ncc = NetconfServiceProvider(self.hostname, self.username, self.password, self.port, self.protocol, self.on_demand, self.common_cache) + self.ncc = NetconfServiceProvider( + self.hostname, + self.username, + self.password, + self.port, + self.protocol, + self.on_demand, + self.common_cache, + cls.timeout) from ydk.services import CRUDService crud = CRUDService() runner = ysanity.Runner() @@ -197,10 +205,15 @@ def test_execute_get_schema(self): self.executor.execute_rpc(self.ncc, get_schema_rpc) if __name__ == '__main__': - device, non_demand, common_cache = get_device_info() + device, non_demand, common_cache, timeout = get_device_info() suite = unittest.TestSuite() - suite.addTest(ParametrizedTestCase.parametrize(SanityTest, device=device, non_demand=non_demand, common_cache=common_cache)) + suite.addTest(ParametrizedTestCase.parametrize( + SanityTest, + device=device, + non_demand=non_demand, + common_cache=common_cache, + timeout=timeout)) ret = not unittest.TextTestRunner(verbosity=2).run(suite).wasSuccessful() sys.exit(ret) diff --git a/sdk/python/core/tests/test_sanity_filter_read.py b/sdk/python/core/tests/test_sanity_filter_read.py index 5a2e194c6..ec435366e 100644 --- a/sdk/python/core/tests/test_sanity_filter_read.py +++ b/sdk/python/core/tests/test_sanity_filter_read.py @@ -36,7 +36,15 @@ class SanityYang(unittest.TestCase): @classmethod def setUpClass(cls): - cls.ncc = NetconfServiceProvider(cls.hostname, cls.username, cls.password, cls.port, cls.protocol, cls.on_demand, cls.common_cache) + cls.ncc = NetconfServiceProvider( + cls.hostname, + cls.username, + cls.password, + cls.port, + cls.protocol, + cls.on_demand, + cls.common_cache, + cls.timeout) cls.crud = CRUDService() # config device with entity a a = cls.getInitEntity() @@ -208,9 +216,14 @@ def test_read_oc_pattern(self): if __name__ == '__main__': - device, non_demand, common_cache = get_device_info() + device, non_demand, common_cache, timeout = get_device_info() suite = unittest.TestSuite() - suite.addTest(ParametrizedTestCase.parametrize(SanityYang, device=device, non_demand=non_demand, common_cache=common_cache)) + suite.addTest(ParametrizedTestCase.parametrize( + SanityYang, + device=device, + non_demand=non_demand, + common_cache=common_cache, + timeout=timeout)) ret = not unittest.TextTestRunner(verbosity=2).run(suite).wasSuccessful() sys.exit(ret) diff --git a/sdk/python/core/tests/test_sanity_filters.py b/sdk/python/core/tests/test_sanity_filters.py index 55c1da807..bf5959c9c 100644 --- a/sdk/python/core/tests/test_sanity_filters.py +++ b/sdk/python/core/tests/test_sanity_filters.py @@ -35,7 +35,15 @@ class SanityYang(unittest.TestCase): @classmethod def setUpClass(cls): - cls.ncc = NetconfServiceProvider(cls.hostname, cls.username, cls.password, cls.port, cls.protocol, cls.on_demand, cls.common_cache) + cls.ncc = NetconfServiceProvider( + cls.hostname, + cls.username, + cls.password, + cls.port, + cls.protocol, + cls.on_demand, + cls.common_cache, + cls.timeout) cls.crud = CRUDService() def setUp(self): @@ -179,9 +187,14 @@ def test_decoder(self): if __name__ == '__main__': - device, non_demand, common_cache = get_device_info() + device, non_demand, common_cache, timeout = get_device_info() suite = unittest.TestSuite() - suite.addTest(ParametrizedTestCase.parametrize(SanityYang, device=device, non_demand=non_demand, common_cache=common_cache)) + suite.addTest(ParametrizedTestCase.parametrize( + SanityYang, + device=device, + non_demand=non_demand, + common_cache=common_cache, + timeout=timeout)) ret = not unittest.TextTestRunner(verbosity=2).run(suite).wasSuccessful() sys.exit(ret) diff --git a/sdk/python/core/tests/test_sanity_levels.py b/sdk/python/core/tests/test_sanity_levels.py index 5e2f25a77..c64585ea1 100644 --- a/sdk/python/core/tests/test_sanity_levels.py +++ b/sdk/python/core/tests/test_sanity_levels.py @@ -36,7 +36,15 @@ class SanityYang(unittest.TestCase): @classmethod def setUpClass(cls): - cls.ncc = NetconfServiceProvider(cls.hostname, cls.username, cls.password, cls.port, cls.protocol, cls.on_demand, cls.common_cache) + cls.ncc = NetconfServiceProvider( + cls.hostname, + cls.username, + cls.password, + cls.port, + cls.protocol, + cls.on_demand, + cls.common_cache, + cls.timeout) cls.crud = CRUDService() def setUp(self): @@ -640,9 +648,14 @@ def test_parent_empty(self): if __name__ == '__main__': - device, non_demand, common_cache = get_device_info() + device, non_demand, common_cache, timeout = get_device_info() suite = unittest.TestSuite() - suite.addTest(ParametrizedTestCase.parametrize(SanityYang, device=device, non_demand=non_demand, common_cache=common_cache)) + suite.addTest(ParametrizedTestCase.parametrize( + SanityYang, + device=device, + non_demand=non_demand, + common_cache=common_cache, + timeout=timeout)) ret = not unittest.TextTestRunner(verbosity=2).run(suite).wasSuccessful() sys.exit(ret) diff --git a/sdk/python/core/tests/test_sanity_netconf.py b/sdk/python/core/tests/test_sanity_netconf.py index 197de7c0d..46b6c3da2 100644 --- a/sdk/python/core/tests/test_sanity_netconf.py +++ b/sdk/python/core/tests/test_sanity_netconf.py @@ -35,7 +35,15 @@ class SanityNetconf(ParametrizedTestCase): @classmethod def setUpClass(cls): - cls.ncc = NetconfServiceProvider(cls.hostname, cls.username, cls.password, cls.port, cls.protocol, not cls.on_demand, cls.common_cache) + cls.ncc = NetconfServiceProvider( + cls.hostname, + cls.username, + cls.password, + cls.port, + cls.protocol, + not cls.on_demand, + cls.common_cache, + cls.timeout) cls.netconf_service = NetconfService() def setUp(self): @@ -219,9 +227,14 @@ def test_unlock_fail(self): if __name__ == '__main__': - device, non_demand, common_cache = get_device_info() + device, non_demand, common_cache, timeout = get_device_info() suite = unittest.TestSuite() - suite.addTest(ParametrizedTestCase.parametrize(SanityNetconf, device=device, non_demand=non_demand, common_cache=common_cache)) + suite.addTest(ParametrizedTestCase.parametrize( + SanityNetconf, + device=device, + non_demand=non_demand, + common_cache=common_cache, + timeout=timeout)) ret = not unittest.TextTestRunner(verbosity=2).run(suite).wasSuccessful() sys.exit(ret) diff --git a/sdk/python/core/tests/test_sanity_path.py b/sdk/python/core/tests/test_sanity_path.py index e0805a85a..bb18afc1f 100644 --- a/sdk/python/core/tests/test_sanity_path.py +++ b/sdk/python/core/tests/test_sanity_path.py @@ -31,7 +31,15 @@ class SanityTest(unittest.TestCase): @classmethod def setUpClass(cls): - cls.nc_session = NetconfSession(cls.hostname, cls.username, cls.password, cls.port, cls.protocol, cls.on_demand, cls.common_cache) + cls.nc_session = NetconfSession( + cls.hostname, + cls.username, + cls.password, + cls.port, + cls.protocol, + cls.on_demand, + cls.common_cache, + cls.timeout) cls.root_schema = cls.nc_session.get_root_schema() cls.codec = Codec() @@ -122,9 +130,14 @@ def test_get_schema(self): if __name__ == '__main__': - device, non_demand, common_cache = get_device_info() + device, non_demand, common_cache, timeout = get_device_info() suite = unittest.TestSuite() - suite.addTest(ParametrizedTestCase.parametrize(SanityTest, device=device, non_demand=non_demand, common_cache=common_cache)) + suite.addTest(ParametrizedTestCase.parametrize( + SanityTest, + device = device, + non_demand = non_demand, + common_cache = common_cache, + timeout = timeout)) ret = not unittest.TextTestRunner(verbosity=2).run(suite).wasSuccessful() sys.exit(ret) diff --git a/sdk/python/core/tests/test_sanity_service_errors.py b/sdk/python/core/tests/test_sanity_service_errors.py index 26b1fc8e8..f0a754507 100644 --- a/sdk/python/core/tests/test_sanity_service_errors.py +++ b/sdk/python/core/tests/test_sanity_service_errors.py @@ -136,7 +136,15 @@ class SanityCRUD(unittest.TestCase): @classmethod def setUpClass(cls): - cls.ncc = NetconfServiceProvider(cls.hostname, cls.username, cls.password, cls.port, cls.protocol, cls.on_demand, cls.common_cache) + cls.ncc = NetconfServiceProvider( + cls.hostname, + cls.username, + cls.password, + cls.port, + cls.protocol, + cls.on_demand, + cls.common_cache, + cls.timeout) cls.crud = CRUDService() def setUp(self): @@ -209,7 +217,15 @@ class SanityExecutor(unittest.TestCase): @classmethod def setUpClass(cls): - cls.ncc = NetconfServiceProvider(cls.hostname, cls.username, cls.password, cls.port, cls.protocol, cls.on_demand, cls.common_cache) + cls.ncc = NetconfServiceProvider( + cls.hostname, + cls.username, + cls.password, + cls.port, + cls.protocol, + cls.on_demand, + cls.common_cache, + cls.timeout) cls.executor = ExecutorService() cls.codec = CodecService() cls.codec_provider = CodecServiceProvider(type=EncodingFormat.XML) @@ -258,7 +274,15 @@ class SanityNetconf(unittest.TestCase): @classmethod def setUpClass(cls): - cls.ncc = NetconfServiceProvider(cls.hostname, cls.username, cls.password, cls.port, cls.protocol, cls.on_demand, cls.common_cache) + cls.ncc = NetconfServiceProvider( + cls.hostname, + cls.username, + cls.password, + cls.port, + cls.protocol, + cls.on_demand, + cls.common_cache, + cls.timeout) cls.netconf_service = NetconfService() def setUp(self): @@ -469,12 +493,17 @@ def test_validate_invalid(self): if __name__ == '__main__': - device, non_demand, common_cache = get_device_info() + device, non_demand, common_cache, timeout = get_device_info() loader = unittest.TestLoader() suite = unittest.TestSuite() for testCase in [SanityCRUD, SanityExecutor, SanityNetconf, SanityCodec]: - suite.addTest(ParametrizedTestCase.parametrize(testCase, device=device, non_demand=non_demand, common_cache=common_cache)) + suite.addTest(ParametrizedTestCase.parametrize( + testCase, + device=device, + non_demand=non_demand, + common_cache=common_cache, + timeout=timeout)) res=unittest.TextTestRunner(verbosity=2).run(suite) # sys.exit expects an integer, will throw libc++ abi error if use: # ret = res.wasSuccessful() # <-- ret is a bool diff --git a/sdk/python/core/tests/test_sanity_type_mismatch_errors.py b/sdk/python/core/tests/test_sanity_type_mismatch_errors.py index c95ae3b5d..e9a9e15fb 100644 --- a/sdk/python/core/tests/test_sanity_type_mismatch_errors.py +++ b/sdk/python/core/tests/test_sanity_type_mismatch_errors.py @@ -51,7 +51,15 @@ class SanityYang(unittest.TestCase): @classmethod def setUpClass(cls): - cls.ncc = NetconfServiceProvider(cls.hostname, cls.username, cls.password, cls.port, cls.protocol, cls.on_demand, cls.common_cache) + cls.ncc = NetconfServiceProvider( + cls.hostname, + cls.username, + cls.password, + cls.port, + cls.protocol, + cls.on_demand, + cls.common_cache, + cls.timeout) cls.crud = CRUDService() def setUp(self): @@ -137,9 +145,14 @@ def test_invalid_llist_assignment_list(self): if __name__ == '__main__': - device, non_demand, common_cache = get_device_info() + device, non_demand, common_cache, timeout = get_device_info() suite = unittest.TestSuite() - suite.addTest(ParametrizedTestCase.parametrize(SanityYang, device=device, non_demand=non_demand, common_cache=common_cache)) + suite.addTest(ParametrizedTestCase.parametrize( + SanityYang, + device=device, + non_demand=non_demand, + common_cache=common_cache, + timeout=timeout)) ret = not unittest.TextTestRunner(verbosity=2).run(suite).wasSuccessful() sys.exit(ret) diff --git a/sdk/python/core/tests/test_sanity_types.py b/sdk/python/core/tests/test_sanity_types.py index b0a6f7917..09b9c572e 100644 --- a/sdk/python/core/tests/test_sanity_types.py +++ b/sdk/python/core/tests/test_sanity_types.py @@ -38,7 +38,15 @@ class SanityTest(unittest.TestCase): @classmethod def setUpClass(cls): - cls.ncc = NetconfServiceProvider(cls.hostname, cls.username, cls.password, cls.port, cls.protocol, cls.on_demand, cls.common_cache) + cls.ncc = NetconfServiceProvider( + cls.hostname, + cls.username, + cls.password, + cls.port, + cls.protocol, + cls.on_demand, + cls.common_cache, + cls.timeout) cls.crud = CRUDService() def setUp(self): @@ -456,10 +464,15 @@ def test_identity_from_other_module(self): # pass if __name__ == '__main__': - device, non_demand, common_cache = get_device_info() + device, non_demand, common_cache, timeout = get_device_info() suite = unittest.TestSuite() - suite.addTest(ParametrizedTestCase.parametrize(SanityTest, device=device, non_demand=non_demand, common_cache=common_cache)) + suite.addTest(ParametrizedTestCase.parametrize( + SanityTest, + device=device, + non_demand=non_demand, + common_cache=common_cache, + timeout=timeout)) ret = not unittest.TextTestRunner(verbosity=2).run(suite).wasSuccessful() sys.exit(ret) diff --git a/sdk/python/core/tests/test_utils.py b/sdk/python/core/tests/test_utils.py index 7b328191f..9cd81408b 100644 --- a/sdk/python/core/tests/test_utils.py +++ b/sdk/python/core/tests/test_utils.py @@ -49,7 +49,7 @@ def __init__(self, methodName='runTest'): super(ParametrizedTestCase, self).__init__(methodName) @staticmethod - def parametrize(testcase_klass, device, non_demand, common_cache): + def parametrize(testcase_klass, device, non_demand, common_cache, timeout): """ Create a suite containing all tests taken from the given subclass, passing them the parameter 'param'. """ @@ -61,6 +61,7 @@ def parametrize(testcase_klass, device, non_demand, common_cache): testcase_klass.protocol = device.scheme testcase_klass.on_demand = not non_demand testcase_klass.common_cache = common_cache + testcase_kclass.timeout = timeout testnames = testloader.getTestCaseNames(testcase_klass) suite = unittest.TestSuite() for name in testnames: @@ -78,11 +79,13 @@ def get_device_info(): dest="common_cache", action="store_true") parser.add_argument("device", nargs='?', help="NETCONF device (ssh://user:password@host:port)") + parser.add_argument("--timeout", help="timeout in microseconds, -1 for infinite timeout, 0 for non-blocking", + dest="timeout", action='store', type=int, default=-1) args = parser.parse_args() if not args.device: args.device = "ssh://admin:admin@127.0.0.1:12022" device = urlparse(args.device) - return device, args.non_demand, args.common_cache + return device, args.non_demand, args.common_cache, args.timeout