edoput / netjsonconfig

Network configuration management library based on NetJSON DeviceConfiguration
http://netjsonconfig.openwisp.org/
Other
1 stars 0 forks source link

Instance is valid under all in `OneOf` #14

Closed edoput closed 7 years ago

edoput commented 7 years ago

Steps to reproduce

Use this netjson as input with airos as backend


{
    "type": "DeviceConfiguration",
    "interfaces": [
        {
            "type": "wireless",
            "name": "wlan0",
            "wireless": {
                "radio": "ath0",
                "mode": "access_point",
                "ssid": "test"
            },
            "addresses": [
                {
                    "address": "192.168.1.20",
                    "mask": 24,
                    "family": "ipv4",
                    "proto": "static"
                }
            ]
        },
        {
            "type": "ethernet",
            "name": "eth0",
            "addresses": [
                {
                    "address": "176.9.211.214",
                    "mask": 28,
                    "family": "ipv4",
                    "proto": "static"
                }
            ]
        },
        {
            "name": "ninux",
            "type": "bridge",
            "bridge_members": [ "wlan0", "eth0"]
        }
    ],
    "radios": [
        {
            "protocol": "802.11n",
            "phy": "phy0",
            "name": "ath0",
            "channel": 0,
            "channel_width": 20,
            "driver": "mac80211",
            "tx_power": 20,
            "country": "IT",
            "hwmode": "11g"
        }
    ]
}

Expected result

The resulting airos configuration will be written on STDOUT

Actual result

The program throws an exception because the radio section is valid under any of the given schema

netjsonconfig: JSON Schema violation
ValidationError {u'protocol': u'802.11n', u'name': u'ath0', u'country': u'IT', u'driver': u'mac80211', u'phy': u'phy0', u'tx_power': 20, u'hwmode': u'11g', u'channel': 0, u'channel_width': 20} is valid under each of {'$ref': '#/definitions/radio_80211an_settings'}, {'$ref': '#/definitions/radio_80211gn_settings'} {u'protocol': u'802.11n', u'name': u'ath0', u'country': u'IT', u'driver': u'mac80211', u'phy': u'phy0', u'tx_power': 20, u'hwmode': u'11g', u'channel': 0, u'channel_width': 20} is valid under each of {'$ref': '#/definitions/radio_80211an_settings'}, {'$ref': '#/definitions/radio_80211gn_settings'}

Failed validating 'oneOf' in schema['properties']['radios']['items']:
    {'oneOf': [{'$ref': '#/definitions/radio_80211gn_settings'},
               {'$ref': '#/definitions/radio_80211an_settings'},
               {'$ref': '#/definitions/radio_80211ac_2ghz_settings'},
               {'$ref': '#/definitions/radio_80211ac_5ghz_settings'},
               {'$ref': '#/definitions/radio_80211bg_settings'},
               {'$ref': '#/definitions/radio_80211a_settings'}],
     'title': 'Radio'}

On instance['radios'][0]:
    {u'channel': 0,
     u'channel_width': 20,
     u'country': u'IT',
     u'driver': u'mac80211',
     u'hwmode': u'11g',
     u'name': u'ath0',
     u'phy': u'phy0',
     u'protocol': u'802.11n',
     u'tx_power': 20} 

Others

works fine with openwrt backend

edoput commented 7 years ago

As of the work done in 95f5d9bcfd1f5c10b8fc13907b6383b9ff4d9c87 I still can't tell the user what the problem is