Skip to content

Fix resource leaking and make the code more testable #41

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 1 commit into from
Oct 21, 2020

Conversation

Vladislav-Kisliy
Copy link
Contributor

isConnected method doesn't cover all cases. For example:
If a device has opened the ssh port however doesn't have netconf subsystem, a connection gets stuck for a long period of time.

@ydnath
Copy link
Member

ydnath commented Oct 19, 2020

@peterjhill please review

Copy link
Contributor

@peterjhill peterjhill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is great. I added some comments. The main one is whether or not we should make the createNetconfSession a no-op, since it no longer seems to do anything interesting.

private int port;
private int connectionTimeout;
private int commandTimeout;
private final JSch sshClient;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good call making all these final


this.sshClient = new JSch();
this.sshClient = (sshClient != null) ? sshClient : new JSch();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

love using ternary expressions..

@@ -189,8 +187,6 @@ private String createHelloRPC(List<String> capabilities) {
*/
private NetconfSession createNetconfSession() throws NetconfException {
if (!isConnected()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it looks like we don't do anything interesting in this method anymore, now that you in line 138 do the
this.sshClient = (sshClient != null) ? sshClient : new JSch();

should we make the createNeconfSession a no-op and deprecate it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use createNetconfSession in connect() method and sshClient initialization is a different thing than session creation. no-op means no-operations, correct?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah ha! when i was looking at the github ui, it looked like the create netconf session method code ended below line 192.

got it!. 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, yeah. GitHub sometimes is very confusing

Copy link
Contributor

@peterjhill peterjhill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!
@ydnath looks good to me..

Thanks @Vladislav-Kisliy

@@ -189,8 +187,6 @@ private String createHelloRPC(List<String> capabilities) {
*/
private NetconfSession createNetconfSession() throws NetconfException {
if (!isConnected()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah ha! when i was looking at the github ui, it looked like the create netconf session method code ended below line 192.

got it!. 👍

@ydnath ydnath merged commit 98c34b7 into Juniper:master Oct 21, 2020
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.

3 participants