sysrepo-python icon indicating copy to clipboard operation
sysrepo-python copied to clipboard

set_item on operational datastore

Open zfvs opened this issue 4 years ago • 12 comments

Hi,

I try to modify data in operational datastore and encounter issues. My modifications are applied but getting data fails after this operation. The modified module comes from running datastore. I execute the following steps:

>>> import sysrepo
>>> 
>>> conn = sysrepo.SysrepoConnection()
>>> op_sess = conn.start_session("operational")
>>> op_sess.get_data('/ccap-docsis40:ccap')
{'ccap': {'vendor-extension-version': {'major-version': 1, 'minor-version': 2}, 'chassis': {'slot': [{'slot-number': 0, 'rf-card': {'line-card-name': '00:01:02:03:04:05', 'admin-state': 'up'}}]}}}
>>> a = "/ccap-docsis40:ccap/vendor-extension-version/major-version"
>>> op_sess.set_item(a, 8)
>>> op_sess.apply_changes()
>>> op_sess.get_data('/ccap-docsis40:ccap')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.8/dist-packages/sysrepo/session.py", line 699, in get_data
    data = self.get_data_ly(
  File "/usr/local/lib/python3.8/dist-packages/sysrepo/session.py", line 657, in get_data_ly
    check_call(
  File "/usr/local/lib/python3.8/dist-packages/sysrepo/errors.py", line 178, in check_call
    raise SysrepoError.new(msg, ret)
sysrepo.errors.SysrepoLyError: Invalid arguments - no keys for a list (lyd_find_sibling_val())., Invalid arguments - no keys for a list (lyd_find_sibling_val())., Invalid arguments - no keys for a list (lyd_find_sibling_val())., Data for more than one case branch of "line-card-type" choice present., Insert request refers node ((null)) that is going to be auto-deleted.: libyang error

Is modifying items in operational datastore supported?

zfvs avatar Aug 25 '21 11:08 zfvs

Hi @zfvs

I never tried editing data in the operational datastore but I think there are some pitfalls. @michalvasko do you see any issue here?

rjarry avatar Sep 20 '21 18:09 rjarry

The use-case seems fine to me briefly looking at it but the error seems like an invalid one. What sysrepo and libyang is being used, to the bindings have any requirements in this respect?

michalvasko avatar Sep 21 '21 06:09 michalvasko

Only the libyang bindings have versions requirements:

https://github.com/CESNET/libyang-python/blob/v1.7.0/cffi/source.c#L8-L13

But for sysrepo (1.x) there is no version info available in the headers in order to fail at build time. As a workaround, I could add SO version requirements at link time.

rjarry avatar Sep 21 '21 07:09 rjarry

But for sysrepo (1.x) there is no version info available in the headers

Yes, fixed in v2.

I was just asking, @zfvs what version of sysrepo are you then using?

michalvasko avatar Sep 21 '21 07:09 michalvasko

I was using the netopeer2 docker image available here: https://hub.docker.com/r/sysrepo/sysrepo-netopeer2. There's sysrepo v1.4.103.

zfvs avatar Sep 21 '21 08:09 zfvs

That may easily be the problem, you should use at least 1.4.140.

michalvasko avatar Sep 21 '21 08:09 michalvasko

Did you think about updating the docker image in the docker hub?

zfvs avatar Sep 21 '21 08:09 zfvs

I am not the maintainer so I cannot tell you but you should be gradually switching to sysrepo v2, anyway.

michalvasko avatar Sep 21 '21 08:09 michalvasko

I'd like to but there's a lack of sysrepo and libyang bindings for v2. Do you maybe know if the work on those bindings is in progress?

zfvs avatar Sep 21 '21 08:09 zfvs

That is a question back to @rjarry but AFAIK they are in progress, as you said.

michalvasko avatar Sep 21 '21 08:09 michalvasko

Yes I am working on v2 support on my free time, which is limited, unfortunately :)

rjarry avatar Sep 21 '21 08:09 rjarry

I am facing the same issue with sysrepo v2.2.72 Did you find any work around?

Salah3beed avatar May 30 '23 15:05 Salah3beed