Skip to content
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

add Commit() and CommitCancel() operations #26

Merged
merged 2 commits into from
Feb 21, 2023
Merged

add Commit() and CommitCancel() operations #26

merged 2 commits into from
Feb 21, 2023

Conversation

nemith
Copy link
Owner

@nemith nemith commented Feb 17, 2023

Adds a Session.Commit() and Session.CommitCancel() operations to issue <commit> and <cancel-commit> RPC calls.

Fixes #23

@nemith nemith changed the title add Commit() and CommitCancel() operations WIP: add Commit() and CommitCancel() operations Feb 17, 2023
@nemith nemith changed the title WIP: add Commit() and CommitCancel() operations add Commit() and CommitCancel() operations Feb 17, 2023
@nemith nemith marked this pull request as ready for review February 17, 2023 16:25
@nemith nemith self-assigned this Feb 17, 2023
@rumenvasilev
Copy link

Commit(), WithConfirmed(), WithConfirmedTimeout(), WithPersist() and WithPersistID() later also works on cSRX.
CancelCommit() only works when persist ID is used. If no arguments are passed, it does not work. Shouldn't that also work, e.g. within the limits of the current session? Example - I commit a configuration, it kicks in, but at some point I realise it's a mistake, so I want to immediately revoke it. If I don't have the ID, I have to wait for the timeout, which might be too long.

Commit() with WithPersist() (and subsequent confirmation commit) and destroyed session in the middle don't work. I destroy the session with KillSession(), which terminates the SSH connection as well. Then after reconnecting, it doesn't work.

@nemith
Copy link
Owner Author

nemith commented Feb 18, 2023

Sounds like Junos bugs to be honest. There is nothing in the library to control that behavior.

@nemith
Copy link
Owner Author

nemith commented Feb 18, 2023

Actually on the cancel commit side the XML parser in Junos is absolute trash and the sometimes treat <cancel-commit/> and <cancel-commit></cancel-commit> differently.

However the encoding/xml library that this library uses cannot do self-closing tags. See golang/go#21399

It's funny that NETCONF was spearheaded buy Junosconf before it and NETCONF wouldn't exist without Juniper however Junper's support for the actual RFC is completely lacking (they don't even support RFC6242 ssh encoding)

@rumenvasilev
Copy link

What's your take on the second issue? Is it supposed to work?

Commit() with WithPersist() (and subsequent confirmation commit) and destroyed session in the middle don't work. I destroy the session with KillSession(), which terminates the SSH connection as well. Then after reconnecting, it doesn't work.

@nemith
Copy link
Owner Author

nemith commented Feb 18, 2023

Commit() with WithPersist() (and subsequent confirmation commit) and destroyed session in the middle don't work. I destroy the session with KillSession(), which terminates the SSH connection as well. Then after reconnecting, it doesn't work.

The spec says it should work. Can you confirm it works with other netconf implementations (ncclient?) You are using WithPersistID() on the second one, right?

My guess is juniper just doesn't support this.

@rumenvasilev
Copy link

rumenvasilev commented Feb 18, 2023

The spec says it should work. Can you confirm it works with other netconf implementations (ncclient?) You are using WithPersistID() on the second one, right?

My guess is juniper just doesn't support this.

Here's the operation sequence:

// get ssh client and netconf session, omitted
ctx := context.Background()
session.Lock(ctx, netconf.Candidate)
eco := []netconf.EditConfigOption{
		netconf.WithDefaultMergeStrategy(operation),
		netconf.WithErrorStrategy(netconf.StopOnError),
		netconf.WithTestStrategy(netconf.TestThenSet)}
session.EditConfig(ctx, netconf.Candidate, patchString, eco...)
session.Validate(ctx, netconf.Candidate)
session.Commit(ctx, netconf.WithPersist("123456"))
session.KillSession(ctx, uint32(session.SessionID()))
// ssh + netconf reconnect, omitted
session.Commit(ctx, netconf.WithPersistID("123456"))
session.Unlock(ctx, netconf.Candidate)

WithPersist() works if I commit within the same session, e.g.

session.Commit(ctx, netconf.WithPersist("123456"))
session.Commit(ctx, netconf.WithPersistID("123456"))

On a unrelated note:
session.KillSession() expects uint32, but session.SessionID() returns uint64. Perhaps these two should align?

Also, session closing operation.. nevermind, it's in session.go.

@nemith
Copy link
Owner Author

nemith commented Feb 18, 2023 via email

@rumenvasilev
Copy link

I've been searching for persist in JunOS netconf configuration and I couldn't find it. I don't think persist is even implemented. I guess you can merge your PR as is, as it implements the RFC.

// I did try with session.Close() too, same outcome.

@nemith nemith merged commit 3b39989 into main Feb 21, 2023
@nemith nemith deleted the nemith/commit-op branch February 21, 2023 22:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a Commit() method, or generic one?
2 participants