napalm-automation / napalm-junos

Apache License 2.0
22 stars 42 forks source link

Pass better error from pyez to napalm #185

Closed dbarrosop closed 7 years ago

dbarrosop commented 7 years ago

Fixes #184

This basically improves the returned error message by returning something like this:

In [1]: from napalm_base import get_network_driver
   ...: junos_configuration = {
   ...:     'hostname': '127.0.0.1',
   ...:     'username': 'vagrant',
   ...:     'password': '',
   ...:     'optional_args': {'port': 12203, 'config_lock': False}
   ...: }
   ...: junos = get_network_driver("junos")
   ...: junos_device = junos(**junos_configuration)
   ...:
   ...: with junos_device as d:
   ...:     d.load_merge_candidate(config="asdasd")
   ...:
---------------------------------------------------------------------------
MergeConfigException                      Traceback (most recent call last)
<ipython-input-1-6c5a0483b535> in <module>()
     10
     11 with junos_device as d:
---> 12     d.load_merge_candidate(config="asdasd")

/Users/dbarroso/workspace/napalm/napalm-junos/napalm_junos/junos.pyc in load_merge_candidate(self, filename, config)
    215         """Open the candidate config and replace."""
    216         self.config_replace = False
--> 217         self._load_candidate(filename, config, False)
    218
    219     def compare_config(self):

/Users/dbarroso/workspace/napalm/napalm-junos/napalm_junos/junos.pyc in _load_candidate(self, filename, config, overwrite)
    205                 raise ReplaceConfigException(e.errs)
    206             else:
--> 207                 raise MergeConfigException(e.errs)
    208
    209     def load_replace_candidate(self, filename=None, config=None):

MergeConfigException: [{'source': None, 'message': 'syntax error', 'bad_element': 'asdasd', 'severity': 'error', 'edit_path': None}]
coveralls commented 7 years ago

Coverage Status

Coverage remained the same at 83.612% when pulling 7a0858d339f89a7a59da59a04d4dfd6c6d7a23d5 on error into 4ae56e9b8cb61f63babcb6d2c53519ea097cfab9 on develop.

dbarrosop commented 7 years ago

I think tox is fucking things up

mirceaulinic commented 7 years ago

Hrm, how strange...

dbarrosop commented 7 years ago

This is weird, do you know if there has been some code change that could have broken this?

https://travis-ci.org/napalm-automation/napalm-junos/jobs/253929613#L504