diff --git a/napalm/junos/junos.py b/napalm/junos/junos.py index 08f80221d..b7a90adc0 100644 --- a/napalm/junos/junos.py +++ b/napalm/junos/junos.py @@ -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 @@ -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)