Telecominfraproject / oopt-gnpy

Optical Route Planning Library, Based on a Gaussian Noise Model
http://telecominfraproject.com
BSD 3-Clause "New" or "Revised" License
209 stars 88 forks source link

Inconsistent validation of JSON loading #250

Open jktjkt opened 5 years ago

jktjkt commented 5 years ago

When loading equipment from the equipment library JSON serialization, much of the validation is currently open-coded, and therefore inconsistent. For example, here's a real backtrace when some unchecked options are missing:

  File "oopt-gnpy/gnpy/core/equipment.py", line 155, in from_json
    gain_min, gain_max = kwargs['gain_min'], kwargs['gain_flatmax']

Ideally, I would like to use "something" which performs all these checks at a single place. Bonus points if we can auto-generate documentation out of that definition.

See-also: #132

jktjkt commented 1 year ago

We're going to use YANG for this, but the bug is a real one, and it complicates life for real users. As an example, a vendor reported that an EDFA which is described via the advacned_model statement currently does not enforce existence of gain_min. The code dies with an exception trace that does not clearly mark what is going on (and as a bonus, it shows a line of code which accesses a different variable with operator + whereas the real bug is with -):

  File "TIP/oopt-gnpy/gnpy/tools/cli_examples.py", line 216, in transmission_main_example
    build_network(network, equipment, pref_ch_db, pref_total_db, args.no_insert_edfas)
  File "TIP/oopt-gnpy/gnpy/core/network.py", line 556, in build_network
    set_egress_amplifier(network, roadm, equipment, pref_ch_db, pref_total_db)
  File "TIP/oopt-gnpy/gnpy/core/network.py", line 308, in set_egress_amplifier
    edfa_variety, power_reduction = select_edfa(raman_allowed, gain_target, power_target, equipment, node.uid, restrictions)
  File "TIP/oopt-gnpy/gnpy/core/network.py", line 60, in select_edfa
    edfa_list = [Edfa_list(
  File "TIP/oopt-gnpy/gnpy/core/network.py", line 69, in <listcomp>
    gain_min=gain_target + 3
TypeError: unsupported operand type(s) for -: 'float' and 'NoneType'