Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion cffi/cdefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ struct timespec {
int sr_connect(const uint32_t opts, sr_conn_ctx_t **);
int sr_disconnect(sr_conn_ctx_t *);
void sr_cache_running(int);
uint32_t sr_context_options(uint32_t, int, uint32_t *);
int sr_context_options(uint32_t, int, uint32_t *);
const char *sr_yang_module_dir(void);
int sr_set_yang_module_dir(const char *);
const char *sr_ly_yang_module_dir(void);
int sr_set_ly_yang_module_dir(const char *);
const struct ly_ctx *sr_acquire_context(sr_conn_ctx_t *);
void sr_release_context(sr_conn_ctx_t *);
int sr_install_module(sr_conn_ctx_t *, const char *, const char *, const char **);
Expand Down
12 changes: 11 additions & 1 deletion sysrepo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@
ChangeMoved,
update_config_cache,
)
from .connection import SysrepoConnection
from .connection import (
SysrepoConnection,
yang_module_dir,
set_yang_module_dir,
ly_yang_module_dir,
set_ly_yang_module_dir,
)
from .errors import (
SysrepoCallbackFailedError,
SysrepoCallbackShelveError,
Expand Down Expand Up @@ -106,4 +112,8 @@
"configure_logging",
"get_syslog_level",
"get_stderr_level",
"yang_module_dir",
"set_yang_module_dir",
"ly_yang_module_dir",
"set_ly_yang_module_dir",
]
38 changes: 38 additions & 0 deletions sysrepo/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,44 @@
LOG = logging.getLogger(__name__)


# ------------------------------------------------------------------------------
def yang_module_dir() -> str:
"""
Return the directory with internal sysrepo YANG modules.
"""
return c2str(lib.sr_yang_module_dir())


# ------------------------------------------------------------------------------
def set_yang_module_dir(path: Optional[str]) -> None:
"""
Set the directory with internal sysrepo YANG modules.

:arg path:
YANG module directory, or None to reset to the compiled default.
"""
check_call(lib.sr_set_yang_module_dir, str2c(path))


# ------------------------------------------------------------------------------
def ly_yang_module_dir() -> str:
"""
Return the directory with internal libyang YANG modules used by sysrepo.
"""
return c2str(lib.sr_ly_yang_module_dir())


# ------------------------------------------------------------------------------
def set_ly_yang_module_dir(path: Optional[str]) -> None:
"""
Set the directory with internal libyang YANG modules used by sysrepo.

:arg path:
YANG module directory, or None to reset to the libyang default.
"""
check_call(lib.sr_set_ly_yang_module_dir, str2c(path))


# ------------------------------------------------------------------------------
class SysrepoConnection:
"""
Expand Down
38 changes: 38 additions & 0 deletions tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,44 @@

# ------------------------------------------------------------------------------
class ConnectionTest(unittest.TestCase):
def test_yang_module_dir(self):
original = sysrepo.yang_module_dir()
self.assertIsInstance(original, str)
self.assertTrue(original)
try:
sysrepo.set_yang_module_dir(None)
default = sysrepo.yang_module_dir()
self.assertIsInstance(default, str)
self.assertTrue(default)

path = "/tmp/sysrepo-\u00e9/modules"
sysrepo.set_yang_module_dir(path)
self.assertEqual(sysrepo.yang_module_dir(), path)

sysrepo.set_yang_module_dir(None)
self.assertEqual(sysrepo.yang_module_dir(), default)
finally:
sysrepo.set_yang_module_dir(original)

def test_ly_yang_module_dir(self):
original = sysrepo.ly_yang_module_dir()
self.assertIsInstance(original, str)
self.assertTrue(original)
try:
sysrepo.set_ly_yang_module_dir(None)
default = sysrepo.ly_yang_module_dir()
self.assertIsInstance(default, str)
self.assertTrue(default)

path = "/tmp/libyang-\u00e9/modules"
sysrepo.set_ly_yang_module_dir(path)
self.assertEqual(sysrepo.ly_yang_module_dir(), path)

sysrepo.set_ly_yang_module_dir(None)
self.assertEqual(sysrepo.ly_yang_module_dir(), default)
finally:
sysrepo.set_ly_yang_module_dir(original)

def test_conn_connect(self):
conn = sysrepo.SysrepoConnection()
conn.disconnect()
Expand Down
Loading