in_network's consistency now verify that IP is not network or broadcast's IP + ip_netmask's consistency now verify that IP is not broadcast's IP
This commit is contained in:
parent
a801951a78
commit
4fde28a15e
3 changed files with 16 additions and 10 deletions
|
@ -3,6 +3,9 @@ Mon Dec 1 22:58:13 2014 +0200 Emmanuel Garette <egarette@cadoles.com>
|
||||||
non-transitive consistency
|
non-transitive consistency
|
||||||
* if consistency with multiple option return if transitive
|
* if consistency with multiple option return if transitive
|
||||||
* can reset slave value in all case when deleting master value
|
* can reset slave value in all case when deleting master value
|
||||||
|
* in_network's consistency now verify that IP is not network or
|
||||||
|
broadcast's IP + ip_netmask's consistency now verify that IP is not
|
||||||
|
broadcast's IP
|
||||||
|
|
||||||
Sun Oct 26 08:50:38 2014 +0200 Emmanuel Garette <egarette@cadoles.com>
|
Sun Oct 26 08:50:38 2014 +0200 Emmanuel Garette <egarette@cadoles.com>
|
||||||
* if option is frozen with force_default_on_freeze property, owner
|
* if option is frozen with force_default_on_freeze property, owner
|
||||||
|
|
|
@ -198,6 +198,7 @@ def test_consistency_ip_netmask():
|
||||||
c.b = '255.255.255.255'
|
c.b = '255.255.255.255'
|
||||||
c.b = '255.255.255.0'
|
c.b = '255.255.255.0'
|
||||||
raises(ValueError, "c.a = '192.168.1.0'")
|
raises(ValueError, "c.a = '192.168.1.0'")
|
||||||
|
raises(ValueError, "c.a = '192.168.1.255'")
|
||||||
|
|
||||||
|
|
||||||
def test_consistency_network_netmask():
|
def test_consistency_network_netmask():
|
||||||
|
@ -225,6 +226,8 @@ def test_consistency_ip_in_network():
|
||||||
cfg.b = '255.255.255.0'
|
cfg.b = '255.255.255.0'
|
||||||
cfg.c = '192.168.1.1'
|
cfg.c = '192.168.1.1'
|
||||||
raises(ValueError, "cfg.c = '192.168.2.1'")
|
raises(ValueError, "cfg.c = '192.168.2.1'")
|
||||||
|
raises(ValueError, "cfg.c = '192.168.1.0'")
|
||||||
|
raises(ValueError, "cfg.c = '192.168.1.255'")
|
||||||
|
|
||||||
|
|
||||||
def test_consistency_ip_in_network_len_error():
|
def test_consistency_ip_in_network_len_error():
|
||||||
|
|
|
@ -215,6 +215,8 @@ class IPOption(Option):
|
||||||
'netmask {4} ({5})')
|
'netmask {4} ({5})')
|
||||||
raise ValueError(msg.format(ip, opts[0].impl_getname(), network,
|
raise ValueError(msg.format(ip, opts[0].impl_getname(), network,
|
||||||
opts[1].impl_getname(), netmask, opts[2].impl_getname()))
|
opts[1].impl_getname(), netmask, opts[2].impl_getname()))
|
||||||
|
# test if ip is not network/broadcast IP
|
||||||
|
opts[2]._cons_ip_netmask((opts[2], opts[0]), (netmask, ip), warnings_only)
|
||||||
|
|
||||||
|
|
||||||
class PortOption(Option):
|
class PortOption(Option):
|
||||||
|
@ -344,16 +346,14 @@ class NetmaskOption(Option):
|
||||||
ip = IP('{0}/{1}'.format(val_ipnetwork, val_netmask),
|
ip = IP('{0}/{1}'.format(val_ipnetwork, val_netmask),
|
||||||
make_net=make_net)
|
make_net=make_net)
|
||||||
#if cidr == 32, ip same has network
|
#if cidr == 32, ip same has network
|
||||||
if ip.prefixlen() != 32:
|
if make_net and ip.prefixlen() != 32:
|
||||||
try:
|
val_ip = IP(val_ipnetwork)
|
||||||
IP('{0}/{1}'.format(val_ipnetwork, val_netmask),
|
if ip.net() == val_ip:
|
||||||
make_net=not make_net)
|
|
||||||
except ValueError:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
if make_net: # pragma: optional cover
|
|
||||||
msg = _("invalid IP {0} ({1}) with netmask {2},"
|
msg = _("invalid IP {0} ({1}) with netmask {2},"
|
||||||
" this IP is a network")
|
" this IP is a network")
|
||||||
|
if ip.broadcast() == val_ip:
|
||||||
|
msg = _("invalid IP {0} ({1}) with netmask {2},"
|
||||||
|
" this IP is a broadcast")
|
||||||
|
|
||||||
except ValueError: # pragma: optional cover
|
except ValueError: # pragma: optional cover
|
||||||
if not make_net:
|
if not make_net:
|
||||||
|
|
Loading…
Reference in a new issue