Skip to content

Commit 6d30435

Browse files
committed
test/infamy: improve feedback on netconf/restconf error a bit
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
1 parent 6735cbc commit 6d30435

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

test/infamy/netconf.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,15 +319,25 @@ def put_config_dicts(self, models):
319319
infer_put_dict(self.name, models)
320320

321321
for model in models.keys():
322-
mod = self.ly.get_module(model)
322+
try:
323+
mod = self.ly.get_module(model)
324+
except libyang.util.LibyangError:
325+
raise Exception(f"YANG model '{model}' not found on device. "
326+
f"Model may not be installed or enabled. "
327+
f"Available models can be checked with get_schema_list()") from None
323328
lyd = mod.parse_data_dict(models[model], no_state=True, validate=False)
324329
config += lyd.print_mem("xml", with_siblings=True, pretty=False) + "\n"
325330
# print(f"Send new XML config: {config}")
326331
return self.put_config(config)
327332

328333
def put_config_dict(self, modname, edit):
329334
"""Convert Python dictionary to XMl and send as configuration"""
330-
mod = self.ly.get_module(modname)
335+
try:
336+
mod = self.ly.get_module(modname)
337+
except libyang.util.LibyangError:
338+
raise Exception(f"YANG model '{modname}' not found on device. "
339+
f"Model may not be installed or enabled. "
340+
f"Available models can be checked with get_schema_list()") from None
331341
lyd = mod.parse_data_dict(edit, no_state=True, validate=False)
332342
config = lyd.print_mem("xml", with_siblings=True, pretty=False)
333343
# print(f"Send new XML config: {config}")
@@ -339,7 +349,12 @@ def call(self, call):
339349

340350
def call_dict(self, modname, call):
341351
"""Call RPC, Python dictionary version"""
342-
mod = self.ly.get_module(modname)
352+
try:
353+
mod = self.ly.get_module(modname)
354+
except libyang.util.LibyangError:
355+
raise Exception(f"YANG model '{modname}' not found on device. "
356+
f"Model may not be installed or enabled. "
357+
f"Available models can be checked with get_schema_list()") from None
343358
lyd = mod.parse_data_dict(call, rpc=True)
344359
return self.call(lyd.print_mem("xml", with_siblings=True, pretty=False))
345360

test/infamy/restconf.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,12 @@ def put_config_dicts(self, models):
266266
running = self.get_running()
267267

268268
for model in models.keys():
269-
mod = self.lyctx.get_module(model)
269+
try:
270+
mod = self.lyctx.get_module(model)
271+
except libyang.util.LibyangError:
272+
raise Exception(f"YANG model '{model}' not found on device. "
273+
f"Model may not be installed or enabled. "
274+
f"Available models can be checked with get_schema_list()") from None
270275
lyd = mod.parse_data_dict(models[model], no_state=True, validate=False)
271276
running.merge(lyd)
272277

@@ -279,7 +284,12 @@ def put_config_dict(self, modname, edit):
279284

280285
# This is hacky, refactor when rousette have PATCH support.
281286
running = self.get_running()
282-
mod = self.lyctx.get_module(modname)
287+
try:
288+
mod = self.lyctx.get_module(modname)
289+
except libyang.util.LibyangError:
290+
raise Exception(f"YANG model '{modname}' not found on device. "
291+
f"Model may not be installed or enabled. "
292+
f"Available models can be checked with get_schema_list()") from None
283293

284294
for k, _ in edit.items():
285295
module = modname + ":" + k

0 commit comments

Comments
 (0)