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:
Emmanuel Garette 2014-12-01 23:16:00 +01:00
parent a801951a78
commit 4fde28a15e
3 changed files with 16 additions and 10 deletions

View file

@ -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

View file

@ -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():

View file

@ -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) msg = _("invalid IP {0} ({1}) with netmask {2},"
except ValueError: " this IP is a network")
pass if ip.broadcast() == val_ip:
else: msg = _("invalid IP {0} ({1}) with netmask {2},"
if make_net: # pragma: optional cover " this IP is a broadcast")
msg = _("invalid IP {0} ({1}) with netmask {2},"
" this IP is a network")
except ValueError: # pragma: optional cover except ValueError: # pragma: optional cover
if not make_net: if not make_net: