Skip to content

Sr3 #80

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 6, 2025
Merged

Sr3 #80

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
22 changes: 14 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@
---
name: CI

on: [push, pull_request]
on:
pull_request:
branches:
- master
push:
branches:
- master

jobs:
lint:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
Expand All @@ -23,20 +29,20 @@ jobs:
- run: python -m tox -e lint

check-commits:
if: github.event_name == 'pull_request'
if: ${{ github.event.pull_request.commits }}
runs-on: ubuntu-latest
env:
SRPY_START_COMMIT: "${{ github.event.pull_request.base.sha }}"
SRPY_END_COMMIT: "${{ github.event.pull_request.head.sha }}"
SRPY_COMMIT_RANGE: "HEAD~${{ github.event.pull_request.commits }}.."
steps:
- run: sudo apt-get install git make
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha || github.ref }}
- run: make check-commits

test:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
strategy:
matrix:
include:
Expand Down Expand Up @@ -67,7 +73,7 @@ jobs:
- run: python -m tox -e ${{ matrix.toxenv }}

coverage:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
Expand All @@ -86,7 +92,7 @@ jobs:
deploy:
needs: [lint, test]
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
Expand Down
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ tests:
format:
tox -e format

SRPY_START_COMMIT ?= origin/master
SRPY_END_COMMIT ?= HEAD
SRPY_COMMIT_RANGE ?= origin/master..

check-commits:
./check-commits.sh $(SRPY_START_COMMIT)..$(SRPY_END_COMMIT)
./check-commits.sh $(SRPY_COMMIT_RANGE)

.PHONY: lint tests format check-commits
2 changes: 1 addition & 1 deletion cffi/cdefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ int sr_session_switch_ds(sr_session_ctx_t *, sr_datastore_t);
sr_datastore_t sr_session_get_ds(sr_session_ctx_t *);
sr_conn_ctx_t *sr_session_get_connection(sr_session_ctx_t *);
int sr_session_get_error(sr_session_ctx_t *, const sr_error_info_t **);
int sr_session_set_error_message(sr_session_ctx_t *, const char *, ...);
int sr_session_set_error(sr_session_ctx_t *, const char *, sr_error_t, const char *, ...);
const char *sr_session_get_orig_name(sr_session_ctx_t *session);
int sr_session_set_orig_name(sr_session_ctx_t *session, const char *);
int sr_session_get_orig_data(sr_session_ctx_t *session, uint32_t idx, uint32_t *size, const void **data);
Expand Down
1 change: 1 addition & 0 deletions pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ disable=
missing-docstring,
suppressed-message,
too-many-lines,
too-many-positional-arguments,
unnecessary-pass,
unused-argument,
use-implicit-booleaness-not-comparison-to-string,
Expand Down
20 changes: 16 additions & 4 deletions sysrepo/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from _sysrepo import ffi, lib
from .change import Change
from .errors import (
SysrepoError,
SysrepoInternalError,
SysrepoNotFoundError,
SysrepoUnsupportedError,
Expand Down Expand Up @@ -164,7 +165,7 @@ def switch_datastore(self, datastore: str) -> None:
ds = datastore_value(datastore)
check_call(lib.sr_session_switch_ds, self.cdata, ds)

def set_error(self, message: str):
def set_error(self, err: BaseException):
"""
Set detailed error information into provided session. Used to notify the client
library about errors that occurred in the application code. Does not print the
Expand All @@ -173,13 +174,24 @@ def set_error(self, message: str):
Intended for change, RPC/action, or operational callbacks to be used on the
provided session.

:arg str message:
The detailed error message.
:arg BaseException err:
The python exception object that carries the error information.
"""
if not self.is_implicit:
raise SysrepoUnsupportedError("can only report errors on implicit sessions")
if isinstance(err, SysrepoError):
code = err.rc
message = err.msg
else:
code = lib.SR_ERR_CALLBACK_FAILED
message = str(err)
check_call(
lib.sr_session_set_error_message, self.cdata, str2c("%s"), str2c(message)
lib.sr_session_set_error,
self.cdata,
ffi.NULL,
code,
str2c("%s"),
str2c(message),
)

def get_originator_name(self) -> str:
Expand Down
12 changes: 6 additions & 6 deletions sysrepo/subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ def module_change_callback(session, sub_id, module, xpath, event, req_id, priv):
and isinstance(session, SysrepoSession)
and isinstance(xpath, str)
):
session.set_error(e.msg)
session.set_error(e)
return e.rc

except BaseException as e:
Expand All @@ -317,7 +317,7 @@ def module_change_callback(session, sub_id, module, xpath, event, req_id, priv):
and isinstance(session, SysrepoSession)
and isinstance(xpath, str)
):
session.set_error(str(e))
session.set_error(e)
return lib.SR_ERR_CALLBACK_FAILED


Expand Down Expand Up @@ -421,7 +421,7 @@ def oper_data_callback(session, sub_id, module, xpath, req_xpath, req_id, parent

except SysrepoError as e:
if e.msg and isinstance(session, SysrepoSession) and isinstance(xpath, str):
session.set_error(e.msg)
session.set_error(e)
return e.rc

except BaseException as e:
Expand All @@ -430,7 +430,7 @@ def oper_data_callback(session, sub_id, module, xpath, req_xpath, req_id, parent
# We are in a C callback, we cannot let any error pass
LOG.exception("%r callback failed", locals().get("callback", priv))
if isinstance(session, SysrepoSession) and isinstance(xpath, str):
session.set_error(str(e))
session.set_error(e)
return lib.SR_ERR_CALLBACK_FAILED


Expand Down Expand Up @@ -548,7 +548,7 @@ def rpc_callback(session, sub_id, xpath, input_node, event, req_id, output_node,

except SysrepoError as e:
if e.msg and isinstance(session, SysrepoSession) and isinstance(xpath, str):
session.set_error(e.msg)
session.set_error(e)
return e.rc

except BaseException as e:
Expand All @@ -557,7 +557,7 @@ def rpc_callback(session, sub_id, xpath, input_node, event, req_id, output_node,
# We are in a C callback, we cannot let any error pass
LOG.exception("%r callback failed", locals().get("callback", priv))
if isinstance(session, SysrepoSession) and isinstance(xpath, str):
session.set_error(str(e))
session.set_error(e)
return lib.SR_ERR_CALLBACK_FAILED


Expand Down
4 changes: 2 additions & 2 deletions tests/test_subs_module_change.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def module_change_cb(event, req_id, changes, private_data):
# 2.
sent_config = {"conf": {"system": {"hostname": "INVALID"}}}
expected_changes = []
with self.assertRaises(sysrepo.SysrepoCallbackFailedError):
with self.assertRaises(sysrepo.SysrepoValidationFailedError):
ch_sess.replace_config(sent_config, "sysrepo-example", strict=True)
# 3.
sent_config = {
Expand Down Expand Up @@ -347,7 +347,7 @@ def module_change_cb(session, event, req_id, private_data):
# 2.
sent_config = {"conf": {"system": {"hostname": "INVALID"}}}
expected_changes = []
with self.assertRaises(sysrepo.SysrepoCallbackFailedError):
with self.assertRaises(sysrepo.SysrepoValidationFailedError):
ch_sess.replace_config(sent_config, "sysrepo-example", strict=True)
# 3.
sent_config = {
Expand Down
18 changes: 9 additions & 9 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ basepython = python3
description = Format python code using isort and black.
changedir = .
deps =
black~=23.12.1
isort~=5.13.2
black~=25.1.0
isort~=6.0.0
skip_install = true
install_command = python3 -m pip install {opts} {packages}
allowlist_externals =
Expand All @@ -73,14 +73,14 @@ description = Run coding style checks.
install_command = {toxinidir}/tox-install.sh {toxworkdir} {opts} {packages}
changedir = .
deps =
astroid~=3.0.2
black~=23.12.1
flake8~=7.0.0
isort~=5.13.2
pycodestyle~=2.11.1
astroid~=3.3.8
black~=25.1.0
flake8~=7.1.1
isort~=6.0.0
pycodestyle~=2.12.1
pyflakes~=3.2.0
pylint~=3.0.3
setuptools~=69.0.3
pylint~=3.3.4
setuptools~=75.8.0
allowlist_externals =
/bin/sh
/usr/bin/sh
Expand Down