Skip to content

Commit

Permalink
updated netconf service provider with timeout parameter (CiscoDevNet#492
Browse files Browse the repository at this point in the history
  • Loading branch information
ylil93 committed Sep 22, 2017
1 parent 1eabedc commit 8eb3462
Show file tree
Hide file tree
Showing 23 changed files with 328 additions and 80 deletions.
8 changes: 6 additions & 2 deletions sdk/cpp/core/docsgen/api/ydk/providers/netconf_provider.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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, \
Expand All @@ -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<path::Repository>`

Expand All @@ -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

Expand Down
14 changes: 8 additions & 6 deletions sdk/cpp/core/src/netconf_provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()
Expand Down
6 changes: 4 additions & 2 deletions sdk/cpp/core/src/netconf_provider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion sdk/cpp/core/src/path_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<NetconfClient> client;
std::unique_ptr<ModelProvider> model_provider;
std::shared_ptr<RootSchemaNode> root_schema;
Expand Down
3 changes: 2 additions & 1 deletion sdk/python/core/docsgen/api/providers/netconf_provider.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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<ydk.path.Repository>`

Expand Down
35 changes: 20 additions & 15 deletions sdk/python/core/python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -593,57 +593,62 @@ PYBIND11_MODULE(ydk_, ydk)

class_<ydk::NetconfServiceProvider, ydk::ServiceProvider>(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"),
arg("username"),
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"),
arg("password"),
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"),
arg("password"),
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);
Expand Down
19 changes: 16 additions & 3 deletions sdk/python/core/tests/test_netconf_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
19 changes: 16 additions & 3 deletions sdk/python/core/tests/test_netconf_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
29 changes: 25 additions & 4 deletions sdk/python/core/tests/test_on_demand.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
19 changes: 16 additions & 3 deletions sdk/python/core/tests/test_sanity_augmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
19 changes: 16 additions & 3 deletions sdk/python/core/tests/test_sanity_delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Loading

0 comments on commit 8eb3462

Please sign in to comment.