Skip to content
This repository has been archived by the owner on Sep 17, 2019. It is now read-only.

load_template searchpaths, take 2 #294

Merged
merged 9 commits into from
Aug 22, 2017
Merged

Conversation

bewing
Copy link
Member

@bewing bewing commented Aug 4, 2017

Build pathlists inside the helper function, pass them all to Jinja2.

Explicitly throw an error if the template_path specified is not found (Discussion needed. Silently ignore and append normal search paths instead?)

@dbarrosop
Copy link
Member

dbarrosop commented Aug 5, 2017

Would you mind adding a test testing the MRO, please? You can probably build a subclass of the MockDriver which is bundled with napalm-base.

Thanks!

@dbarrosop
Copy link
Member

How are you testing the MRO for the templates?

@mirceaulinic mirceaulinic added this to the 0.25.0 milestone Aug 8, 2017
@bewing
Copy link
Member Author

bewing commented Aug 8, 2017

https://github.com/napalm-automation/napalm-base/pull/294/files#diff-8d00f135ea6d344c135ab86b55599e18R129

We're checking the search path assembled, and ensuring that both FakeNetworkDriver and NetworkDriver's path strings are present, which implies that they were built correctly from the MRO

@coveralls
Copy link

coveralls commented Aug 8, 2017

Coverage Status

Coverage increased (+0.4%) to 72.494% when pulling d234593 on bewing:lt_walk into 42729d5 on napalm-automation:develop.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.4%) to 72.494% when pulling 8959976 on bewing:lt_walk into 42729d5 on napalm-automation:develop.

2 similar comments
@coveralls
Copy link

Coverage Status

Coverage increased (+0.4%) to 72.494% when pulling 8959976 on bewing:lt_walk into 42729d5 on napalm-automation:develop.

@coveralls
Copy link

coveralls commented Aug 8, 2017

Coverage Status

Coverage increased (+0.4%) to 72.494% when pulling 8959976 on bewing:lt_walk into 42729d5 on napalm-automation:develop.

if (isinstance(template_path, py23_compat.string_types) and
os.path.isdir(template_path) and os.path.isabs(template_path)):
# append driver name at the end of the custom path
print(template_path)
Copy link
Member

Choose a reason for hiding this comment

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

leftover?

raise IOError("Template path does not exist: {}".format(template_path))
else:
# Search modules for template paths
for parent in cls.__class__.mro():
Copy link
Member

@dbarrosop dbarrosop Aug 9, 2017

Choose a reason for hiding this comment

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

search_path = [os.path.dirname(os.path.abspath(sys.modules[c.__module__].__file__))
               for c in cls.__class__.mro() if c is not object]

Feels more legible.

@dbarrosop
Copy link
Member

We should probably break down this into smaller functions at some point, this method is... confusing. Anyway, I left a couple of minor comments. Feel free to discard the comprehension list suggestion, I just find them easier to read.

@bewing
Copy link
Member Author

bewing commented Aug 9, 2017

Thanks for the catch and the suggestion. Before merge, I wanted one more call for comments on https://github.com/bewing/napalm-base/blob/13ecc398e70630dff337df14c57b69a0bde680ef/napalm_base/helpers.py#L44-L50, as it is a functionality change (Before we silently ignored bad paths, and looked in the driver's template directory. We could refactor now to just blindly trust the input, and have it be the first path passed into the FileLoader

@coveralls
Copy link

coveralls commented Aug 9, 2017

Coverage Status

Coverage increased (+0.8%) to 72.892% when pulling 13ecc39 on bewing:lt_walk into 42729d5 on napalm-automation:develop.

@dbarrosop
Copy link
Member

I don't like doing those sort of sanity checks, it pollutes the code and makes it harder to read and I am of the opinion that users should be responsible of using the library properly and sending a valid path if a valid path is what the function demands. However, your change at least throws an error instead of swallowing it so I am fine with the change.

@bewing bewing merged commit a249e1b into napalm-automation:develop Aug 22, 2017
@bewing bewing deleted the lt_walk branch August 22, 2017 01:36
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants