Skip to content

Commit

Permalink
[Junos] Make _load_candidate() support loading of XML files with head…
Browse files Browse the repository at this point in the history
…ers that have encoding information
  • Loading branch information
hkam40k committed Jun 15, 2022
1 parent dde6a59 commit 796350f
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions napalm/junos/junos.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,21 @@ def _detect_config_format(self, config):
return fmt

def _load_candidate(self, filename, config, overwrite):
fmt = None
if filename is None:
configuration = config
else:
with open(filename) as f:
configuration = f.read()
try:
configuration = etree.parse(f).getroot()
fmt = "xml"
except etree.XMLSyntaxError:
configuration = f.read()

if not fmt:
fmt = self._detect_config_format(configuration)
if fmt == "xml":
configuration = etree.XML(configuration)

if (
not self.lock_disable
Expand All @@ -248,11 +258,6 @@ def _load_candidate(self, filename, config, overwrite):
self._lock()

try:
fmt = self._detect_config_format(configuration)

if fmt == "xml":
configuration = etree.XML(configuration)

if self.config_private:
try:
self.device.rpc.open_configuration(private=True, normalize=True)
Expand Down

0 comments on commit 796350f

Please sign in to comment.