networktocode / ntc-rosetta

The missing bridge between industry standard CLIs and YANG
https://ntc-rosetta.readthedocs.io/en/latest/index.html
Apache License 2.0
103 stars 23 forks source link

Junos merge error #27

Closed pravindamodaran closed 4 years ago

pravindamodaran commented 5 years ago

I'm trying to merge two junos configuration.

parsed_candidate = junos_driver.parse(native={"dev_conf": candidate_native})
parsed_running = junos_driver.parse(native={"dev_conf": running_native})

merged_config = junos_driver.merge(candidate=parsed_candidate.raw_value(), running=parsed_running.raw_value(), replace=True)

While doing so, I'm getting the following error:

Traceback (most recent call last):
  File "rosetta-trial.py", line 57, in <module>
    merged_config = junos_driver.merge(candidate=parsed_candidate.raw_value(), running=parsed_running.raw_value(), replace=True)
  File "/home/lumina/yangify-handson/venv/lib/python3.6/site-packages/ntc_rosetta/drivers/base.py", line 121, in merge
    return translator.process()
  File "/home/lumina/yangify-handson/venv/lib/python3.6/site-packages/yangify/translator/__init__.py", line 501, in process
    self._process_container()
  File "/home/lumina/yangify-handson/venv/lib/python3.6/site-packages/yangify/translator/__init__.py", line 367, in _process_container
    self._process_container_node(c)
  File "/home/lumina/yangify-handson/venv/lib/python3.6/site-packages/yangify/translator/__init__.py", line 348, in _process_container_node
    attr._process_container()
  File "/home/lumina/yangify-handson/venv/lib/python3.6/site-packages/yangify/translator/__init__.py", line 369, in _process_container
    self._process_container_node(child)
  File "/home/lumina/yangify-handson/venv/lib/python3.6/site-packages/yangify/translator/__init__.py", line 350, in _process_container_node
    attr._process_list()
  File "/home/lumina/yangify-handson/venv/lib/python3.6/site-packages/yangify/translator/__init__.py", line 410, in _process_list
    self.yy.pre_process_list()
  File "/home/lumina/yangify-handson/venv/lib/python3.6/site-packages/ntc_rosetta/translators/openconfig/junos/openconfig_interfaces/interfaces.py", line 73, in pre_process_list
    xh.find_or_create(self.root_result, xpath, delete="delete")
TypeError: find_or_create() got an unexpected keyword argument 'delete'

Looking into ntc_rosetta/translators/openconfig/junos/openconfig_interfaces/interfaces.py,

from ntc_rosetta.helpers import xml_helpers as xh

class Interface(Translator):
    class Yangify(TranslatorData):
        path = "/openconfig-interfaces:interfaces/interface"

        def pre_process_list(self) -> None:
            if self.to_remove:
                for element in self.to_remove:
                    xpath = f"interface[name={element.value['name']}]"
                    xh.find_or_create(self.root_result, xpath, delete="delete")

        def pre_process(self) -> None:
            self.result = etree.SubElement(self.result, "interface")
            etree.SubElement(self.result, "name").text = self.key

   ...
   ...

Xmlhelper ntc_rosetta/helpers/xml_helpers.py (there are only two arguments for find_or_create(root and xpath). It does not have delete argument:

def find_or_create(root: etree.Element, xpath: str) -> etree.Element:
...