wobcom / cosmo

a fairly odd fairy to generate network configuration from Netbox
MIT License
6 stars 0 forks source link

Missing lo0 parent should have a better error message #23

Closed loulecrivain closed 2 weeks ago

loulecrivain commented 2 months ago

Currently we have this error when a device has no lo0 parent:

Info: Generating trma2061
Traceback (most recent call last):
  File "/nix/store/qfn07kpir8wbmcjykzi3xl6rlhh8rhhh-python3.11-cosmo-0.8.4/bin/.cosmo-wrapped", line 9, in <module>
    sys.exit(main())
             ^^^^^^
  File "/nix/store/qfn07kpir8wbmcjykzi3xl6rlhh8rhhh-python3.11-cosmo-0.8.4/lib/python3.11/site-packages/cosmo/__main__.py", line 80, in main
    serializer = RouterSerializer(device, cosmo_data['l2vpn_list'], cosmo_data["vrf_list"])
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/qfn07kpir8wbmcjykzi3xl6rlhh8rhhh-python3.11-cosmo-0.8.4/lib/python3.11/site-packages/cosmo/serializer.py", line 36, in __init__
    match device["platform"]["manufacturer"]["slug"]:
          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
TypeError: 'NoneType' object is not subscriptable

we should introduce a better error message for this specific case, such as the operator can quickly identify the issue and correct it from the datasource

also, a test case would be needed to make sure future refactoring does not omit this.

johannwagner commented 2 months ago

I am thinking about refactoring Errors all along. Introducing a DeviceError which can get caught on device loop level and gets the device ignored and the error message printed, a InterfaceError for the interface loop which gets the interface ignored and a FatalError which stops execution and does not create artifacts.

loulecrivain commented 2 months ago

Do we want to wait until we start refactoring everything, or do you want to implement it now ?

There's only one portion of the RouterSerializer for which we still have to write tests (QoS stuff iirc), but idk how urgent this change is, and if we can wait for the refactor to be completed.

johannwagner commented 2 months ago

Include a print error message for now and we will rework it later.