本文整理汇总了Python中netjsonconfig.OpenWrt.validate方法的典型用法代码示例。如果您正苦于以下问题:Python OpenWrt.validate方法的具体用法?Python OpenWrt.validate怎么用?Python OpenWrt.validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类netjsonconfig.OpenWrt
的用法示例。
在下文中一共展示了OpenWrt.validate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_mac_address_format
# 需要导入模块: from netjsonconfig import OpenWrt [as 别名]
# 或者: from netjsonconfig.OpenWrt import validate [as 别名]
def test_mac_address_format(self):
o = OpenWrt({
"interfaces": [
{
"name": "eth0",
"type": "ethernet",
"mac": "00:11:22:33:44:55"
}
]
})
o.validate()
# too short
o.config['interfaces'][0]['mac'] = '00:11:22:33:44'
with self.assertRaises(ValidationError):
o.validate()
# valid
o.config['interfaces'][0]['mac'] = '00-11-22-33-44-55'
o.validate()
# should not be valid
o.config['interfaces'][0]['mac'] = '00:11:22:33:44:ZY'
with self.assertRaises(ValidationError):
o.validate()
# empty is valid (will be ignored)
o.config['interfaces'][0]['mac'] = ''
o.validate()
示例2: test_bssid_format
# 需要导入模块: from netjsonconfig import OpenWrt [as 别名]
# 或者: from netjsonconfig.OpenWrt import validate [as 别名]
def test_bssid_format(self):
o = OpenWrt({
"interfaces": [
{
"name": "wlan0",
"type": "wireless",
"wireless": {
"radio": "radio1",
"mode": "adhoc",
"ssid": "adhoc-ssid",
"bssid": "00:11:22:33:44:55"
}
}
]
})
o.validate()
# too short
o.config['interfaces'][0]['wireless']['bssid'] = '00:11:22:33:44'
with self.assertRaises(ValidationError):
o.validate()
# valid
o.config['interfaces'][0]['wireless']['bssid'] = '00-11-22-33-44-55'
o.validate()
# should not be valid
o.config['interfaces'][0]['wireless']['bssid'] = '00:11:22:33:44:ZY'
with self.assertRaises(ValidationError):
o.validate()
# empty is not valid
o.config['interfaces'][0]['wireless']['bssid'] = ''
with self.assertRaises(ValidationError):
o.validate()
示例3: test_file_schema
# 需要导入模块: from netjsonconfig import OpenWrt [as 别名]
# 或者: from netjsonconfig.OpenWrt import validate [as 别名]
def test_file_schema(self):
c = {
"files": [
{
"path": "/tmp/hello.sh",
"mode": "0644",
"contents": "echo 'hello world'"
}
]
}
# valid
c['files'][0]['mode'] = '3555'
o = OpenWrt(c)
o.validate()
# valid
c['files'][0]['mode'] = '755'
o = OpenWrt(c)
o.validate()
# too long
c['files'][0]['mode'] = '00777'
o = OpenWrt(c)
with self.assertRaises(ValidationError):
o.validate()
# too short
c['files'][0]['mode'] = '75'
o = OpenWrt(c)
with self.assertRaises(ValidationError):
o.validate()
# invalid
c['files'][0]['mode'] = '0855'
o = OpenWrt(c)
with self.assertRaises(ValidationError):
o.validate()
示例4: test_maclist_format
# 需要导入模块: from netjsonconfig import OpenWrt [as 别名]
# 或者: from netjsonconfig.OpenWrt import validate [as 别名]
def test_maclist_format(self):
o = OpenWrt({
"interfaces": [
{
"name": "wlan0",
"type": "wireless",
"wireless": {
"radio": "radio0",
"mode": "access_point",
"ssid": "MyWifiAP",
"macfilter": "deny",
"maclist": [
"E8:94:F6:33:8C:1D",
]
}
}
]
})
o.validate()
# too short
o.config['interfaces'][0]['wireless']['maclist'][0] = '00:11:22:33:44'
with self.assertRaises(ValidationError):
o.validate()
# valid
o.config['interfaces'][0]['wireless']['maclist'][0] = '00-11-22-33-44-55'
o.validate()
# should not be valid
o.config['interfaces'][0]['wireless']['maclist'][0] = '00:11:22:33:44:ZY'
with self.assertRaises(ValidationError):
o.validate()
# empty is not valid
o.config['interfaces'][0]['wireless']['maclist'][0] = ''
with self.assertRaises(ValidationError):
o.validate()
示例5: test_dns_search_hostname
# 需要导入模块: from netjsonconfig import OpenWrt [as 别名]
# 或者: from netjsonconfig.OpenWrt import validate [as 别名]
def test_dns_search_hostname(self):
o = OpenWrt({
"dns_search": ['openwisp.org', 'test.netjson.org']
})
o.validate()
# invalid hostname
o.config['dns_search'].append('very/wrong')
with self.assertRaises(ValidationError):
o.validate()
示例6: test_system_invalid_timezone
# 需要导入模块: from netjsonconfig import OpenWrt [as 别名]
# 或者: from netjsonconfig.OpenWrt import validate [as 别名]
def test_system_invalid_timezone(self):
o = OpenWrt({
"general": {
"hostname": "test_system",
"timezone": "WRONG",
}
})
with self.assertRaises(ValidationError):
o.validate()
示例7: test_led_schema_validation
# 需要导入模块: from netjsonconfig import OpenWrt [as 别名]
# 或者: from netjsonconfig.OpenWrt import validate [as 别名]
def test_led_schema_validation(self):
o = OpenWrt({
"led": [
{
"invalid": True
}
]
})
with self.assertRaises(ValidationError):
o.validate()
示例8: test_ntp_servers_hostname
# 需要导入模块: from netjsonconfig import OpenWrt [as 别名]
# 或者: from netjsonconfig.OpenWrt import validate [as 别名]
def test_ntp_servers_hostname(self):
o = OpenWrt({
"ntp": {
"enabled": True,
"server": ["0.openwrt.pool.ntp.org"]
}
})
o.validate()
# invalid hostname
o.config['ntp']['server'][0] = 'totally/wrong'
with self.assertRaises(ValidationError):
o.validate()
示例9: test_ifname_length
# 需要导入模块: from netjsonconfig import OpenWrt [as 别名]
# 或者: from netjsonconfig.OpenWrt import validate [as 别名]
def test_ifname_length(self):
o = OpenWrt({
"interfaces": [
{
"name": "ifname0123456789",
"type": "ethernet"
}
]
})
with self.assertRaises(ValidationError):
o.validate()
# ensure fix works
o.config['interfaces'][0]['name'] = 'ifname0'
o.validate()
示例10: test_ifname_pattern
# 需要导入模块: from netjsonconfig import OpenWrt [as 别名]
# 或者: from netjsonconfig.OpenWrt import validate [as 别名]
def test_ifname_pattern(self):
o = OpenWrt({
"interfaces": [
{
"name": "eth 0",
"type": "ethernet"
}
]
})
with self.assertRaises(ValidationError):
o.validate()
# ensure fix works
o.config['interfaces'][0]['name'] = '[email protected]=0.1'
o.validate()
示例11: test_bridge_members_unique
# 需要导入模块: from netjsonconfig import OpenWrt [as 别名]
# 或者: from netjsonconfig.OpenWrt import validate [as 别名]
def test_bridge_members_unique(self):
o = OpenWrt({
"interfaces": [
{
"name": "lan",
"type": "bridge",
"bridge_members": ["eth0", "eth0"]
}
]
})
with self.assertRaises(ValidationError):
o.validate()
# ensure fix works
o.config['interfaces'][0]['bridge_members'][0] = 'eth1'
o.validate()
示例12: test_network_maxlength
# 需要导入模块: from netjsonconfig import OpenWrt [as 别名]
# 或者: from netjsonconfig.OpenWrt import validate [as 别名]
def test_network_maxlength(self):
o = OpenWrt({
"interfaces": [
{
"name": "eth0",
"network": "lan0123456789",
"type": "ethernet"
}
]
})
with self.assertRaises(ValidationError):
o.validate()
# ensure fix works
o.config['interfaces'][0]['network'] = 'lan'
o.validate()
示例13: test_schema_radio_wrong_protocol
# 需要导入模块: from netjsonconfig import OpenWrt [as 别名]
# 或者: from netjsonconfig.OpenWrt import validate [as 别名]
def test_schema_radio_wrong_protocol(self):
o = OpenWrt({
"radios": [
{
"name": "radio0",
"phy": "phy0",
"driver": "mac80211",
"protocol": "802.11ad", # ad is not supported by OpenWRT yet
"channel": 132,
"channel_width": 80,
"tx_power": 8
}
]
})
with self.assertRaises(ValidationError):
o.validate()
示例14: test_schema_radio_wrong_driver
# 需要导入模块: from netjsonconfig import OpenWrt [as 别名]
# 或者: from netjsonconfig.OpenWrt import validate [as 别名]
def test_schema_radio_wrong_driver(self):
o = OpenWrt({
"radios": [
{
"name": "radio0",
"phy": "phy0",
"driver": "iamwrong",
"protocol": "802.11ac",
"channel": 132,
"channel_width": 80,
"tx_power": 8
}
]
})
with self.assertRaises(ValidationError):
o.validate()
示例15: test_isolate
# 需要导入模块: from netjsonconfig import OpenWrt [as 别名]
# 或者: from netjsonconfig.OpenWrt import validate [as 别名]
def test_isolate(self):
o = OpenWrt({
"interfaces": [
{
"name": "wlan0",
"type": "wireless",
"wireless": {
"radio": "radio0",
"mode": "access_point",
"ssid": "open",
"isolate": True
}
}
]
})
self.assertIn("option isolate '1'", o.render())
# try entering an invalid value
o.config['interfaces'][0]['wireless']['isolate'] = 'wrong'
with self.assertRaises(ValidationError):
o.validate()