sysrepo/sysrepo-python

apply_changes() done under lock not working

tbsuht opened this issue · 2 comments

tbsuht commented

Hi,

consider this piece of code:

with sysrepo.SysrepoConnection() as conn:
        with conn.start_session("candidate") as sess:
            with sess.locked():
                sess.set_item(f"/{xpath}", request.data)
                sess.apply_changes()
        with conn.start_session("running") as sess: 
            sess.copy_config("candidate")

This is not working, the resulting running datastore will be empty. If I move the apply_changes outside the lock, its working:

with sysrepo.SysrepoConnection() as conn:
        with conn.start_session("candidate") as sess:
            with sess.locked():
                sess.set_item(f"/{xpath}", request.data)
            sess.apply_changes()
        with conn.start_session("running") as sess: 
            sess.copy_config("candidate")

Is this expected? Bug? In my opinion this should work, otherwise between giving up the lock and applying the changes someone can write to the candidate datastore again.

tbsuht commented

Additionally: keeping the candidate datastore locked until the copy to running is done seems not to be possible?

with sysrepo.SysrepoConnection() as conn:
        with conn.start_session("candidate") as sess:
            with sess.locked():
                sess.set_item(f"/{xpath}", request.data)
                sess.apply_changes()
                with conn.start_session("running") as sess_running: 
                    sess_running.copy_config("candidate")

Results in sysrepo.errors.SysrepoLockedError: Module "ietf-netconf-acm" is DS-locked by session 76.: Requested resource already locked

How to prevent another session from writing to the candidate datastore until copied to running is done?

tbsuht commented

Hi,

consider this piece of code:

with sysrepo.SysrepoConnection() as conn:
        with conn.start_session("candidate") as sess:
            with sess.locked():
                sess.set_item(f"/{xpath}", request.data)
                sess.apply_changes()
        with conn.start_session("running") as sess: 
            sess.copy_config("candidate")

This is not working, the resulting running datastore will be empty. If I move the apply_changes outside the lock, its working:

with sysrepo.SysrepoConnection() as conn:
        with conn.start_session("candidate") as sess:
            with sess.locked():
                sess.set_item(f"/{xpath}", request.data)
            sess.apply_changes()
        with conn.start_session("running") as sess: 
            sess.copy_config("candidate")

Is this expected? Bug? In my opinion this should work, otherwise between giving up the lock and applying the changes someone can write to the candidate datastore again.

This seems to be specific to the candidate datastore. Apply_changes() under a lock with running is working.

with sysrepo.SysrepoConnection() as conn:
        with conn.start_session("running") as sess_running:
            with sess_running.locked():
                sess_running.set_item(f"/{xpath}", request.data)
                sess_running.validate()
                sess_running.apply_changes()

So I guess this is not related to the python-wrapper. Any idea why the candidate datastore behaves different?