Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

open tmp_cfgfil with w+ and fix seek #55

Merged
merged 3 commits into from
Jul 15, 2024

Conversation

lucasalvatore
Copy link

@lucasalvatore lucasalvatore commented Jul 11, 2024

my environment:
python: 3.10.14
napalm: 5.0.0
napalm-srl: 1.0.5

Was testing basic config changes using this simple script:

from napalm import get_network_driver
import json
driver = get_network_driver("srl")
optional_args = {"gnmi_port": 6030,"skip_verify": True, "insecure": True,"encoding": "JSON_IETF"}
router = driver(hostname="mydevice",username="admin",password="xxxx",optional_args=optional_args)
router.open()
config = {
  "interface": [
    {
      "name": "ethernet-1/4/1",
      "admin-state": "enable",
      "vlan-tagging": True,
      "transceiver": {
        "forward-error-correction": "base-r"
      },
      "subinterface": [
        {
          "index": 0,
          "type": "bridged",
          "vlan": {
            "encap": {
              "untagged": {
              }
            }
          }
        }
      ]
    }
  ]
}

test = json.dumps(config)


print("trying to merge")
router.load_merge_candidate(config=test)
print("compare")
diff = router.compare_config()
print(f"diff is {diff}")
input("do you want to commit? ")
router.commit_config()
print("commit")
router.close()

Which results in these error:

ERROR:root:Error occurred in compare_config: not readable
Traceback (most recent call last):
  File "/Users/lsalvatore/git/napalm-srlinux/napalm_srl/srl.py", line 2187, in compare_config
    cand_config = json.load(self.tmp_cfgfile)
  File "/opt/homebrew/Cellar/[email protected]/3.10.14/Frameworks/Python.framework/Versions/3.10/lib/python3.10/json/__init__.py", line 293, in load
    return loads(fp.read(),
io.UnsupportedOperation: not readable

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/lsalvatore/git/network-automation/utilities/srl-napalm.py", line 38, in <module>
    diff = router.compare_config()
  File "/Users/lsalvatore/git/napalm-srlinux/napalm_srl/srl.py", line 2194, in compare_config
    raise CommandErrorException(e) from e
napalm.base.exceptions.CommandErrorException: not readable

i was able to fix this by opening tmp_cfgfile with w+ permissions

Also ran into a problem when doing the compare_config() before a commit. When that happens we need to reset the pointer back to the start of tmp_cfgfile so it can be read again, so thats what line 2299 is doing

Maybe better ways of solving this but it seems to work fine for me

@jbemmel jbemmel merged commit 8af98b2 into napalm-automation-community:main Jul 15, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants