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

fix: force_no_enable enabled on ios and nx only #1240

Merged
merged 8 commits into from
Jul 13, 2020
9 changes: 7 additions & 2 deletions napalm/base/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,14 @@ def _netmiko_open(self, device_type, netmiko_optional_args=None):
except NetMikoTimeoutException:
raise ConnectionException("Cannot connect to {}".format(self.hostname))

# ensure in enable mode if not force disable
if not self.force_no_enable:
# Disable enable mode if force_no_enable is true (for NAPALM drivers
# that support force_no_enable)
try:
Copy link
Member

Choose a reason for hiding this comment

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

Now that I'm looking at this again, it does look a little strange, wondering if the following would be more readable:

if not getattr(self, 'force_no_enable', False):
    self._netmiko_device.enable()

Copy link
Member

Choose a reason for hiding this comment

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

Any thoughts on this @tynany / @ktbyers ?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the try/except is fine.

Copy link
Contributor

Choose a reason for hiding this comment

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

This PR looks good to me so I am fine with merging it.

if not self.force_no_enable:
self._netmiko_device.enable()
except AttributeError:
self._netmiko_device.enable()

return self._netmiko_device

def _netmiko_close(self):
Expand Down