-
Notifications
You must be signed in to change notification settings - Fork 40
move auto detetec to merge and replace only #171
move auto detetec to merge and replace only #171
Conversation
itdependsnetworks
commented
Jul 3, 2017
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks on the surface, makes sense to me.
I think we should just convert this to a Python setter/getter format which @dbarrosop mentioned previously. Basically, whenever anyone accesses this attribute, it will go and do the autodetect if it is not currently sent. This will prevent the current solution from breaking if we expand the use of this attribute. |
2 similar comments
napalm_ios/ios.py
Outdated
def _discover_file_system(self): | ||
try: | ||
return self.device._autodetect_fs() | ||
except AttributeError: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know you are copying the previous pattern here, but we probably should do:
except Exception:
If it fails at this point catch it and re-raise the exception with our message.
I would put our message as:
"Netmiko _autodetect_fs failed to workaround specify dest_file_system in optional_args"
In other words, what I put above was for the case when _autodetect_fs didn't exist in Netmiko (which won't happen now). I think we should convert this to something more general.
napalm_ios/ios.py
Outdated
@@ -235,6 +236,7 @@ def load_replace_candidate(self, filename=None, config=None): | |||
Return None or raise exception | |||
""" | |||
self.config_replace = True | |||
self.dest_file_system = self.file_system |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't be necessary (see comment below)
napalm_ios/ios.py
Outdated
|
||
@property | ||
def file_system(self): | ||
return self.dest_file_system or self._discover_file_system() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we just do:
# In __init__, line 86:
# Note extra underscore.
self._dest_file_system = optional_args.get('dest_file_system', None)
@property
def dest_file_system(self):
if self._dest_file_system is None:
self._dest_file_system = self._discover_file_system()
return self._dest_file_system
Then anytime object.dest_file_system gets accessed it will use the current value (if there is one) or will call the _discover_file_system() method.
Then we don't have to do the artificial calls in replace
and merge
.
I think this will fix the testing error:
|
The is_alive fix was because I saw this when I ran the tests:
and a similar error for |
The is_alive method should look like this:
If you want me to submit this into a separate PR that is fine also. Basically make sure it doesn't run this if self.device hasn't even been initialized. |
What I posted above doesn't work. I will correct. |
Made an updated PR (built upon @itdependsnetworks work here): Closing this one. |