in_network's consistency now verify that IP is not network or broadcast's IP + ip_net...
authorEmmanuel Garette <egarette@cadoles.com>
Mon, 1 Dec 2014 22:16:00 +0000 (23:16 +0100)
committerEmmanuel Garette <egarette@cadoles.com>
Mon, 1 Dec 2014 22:16:00 +0000 (23:16 +0100)
ChangeLog
test/test_option_consistency.py
tiramisu/option/option.py

index 45e2762..845883c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,6 +3,9 @@ Mon Dec  1 22:58:13 2014 +0200 Emmanuel Garette <egarette@cadoles.com>
        non-transitive consistency
        * if consistency with multiple option return if transitive
        * 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>
        * if option is frozen with force_default_on_freeze property, owner
index ba3549c..ac396d2 100644 (file)
@@ -198,6 +198,7 @@ def test_consistency_ip_netmask():
     c.b = '255.255.255.255'
     c.b = '255.255.255.0'
     raises(ValueError, "c.a = '192.168.1.0'")
+    raises(ValueError, "c.a = '192.168.1.255'")
 
 
 def test_consistency_network_netmask():
@@ -225,6 +226,8 @@ def test_consistency_ip_in_network():
     cfg.b = '255.255.255.0'
     cfg.c = '192.168.1.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():
index 412553c..3974683 100644 (file)
@@ -215,6 +215,8 @@ class IPOption(Option):
                         'netmask {4} ({5})')
             raise ValueError(msg.format(ip, opts[0].impl_getname(), network,
                              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):
@@ -344,16 +346,14 @@ class NetmaskOption(Option):
             ip = IP('{0}/{1}'.format(val_ipnetwork, val_netmask),
                     make_net=make_net)
             #if cidr == 32, ip same has network
-            if ip.prefixlen() != 32:
-                try:
-                    IP('{0}/{1}'.format(val_ipnetwork, val_netmask),
-                        make_net=not make_net)
-                except ValueError:
-                    pass
-                else:
-                    if make_net:  # pragma: optional cover
-                        msg = _("invalid IP {0} ({1}) with netmask {2},"
-                                " this IP is a network")
+            if make_net and ip.prefixlen() != 32:
+                val_ip = IP(val_ipnetwork)
+                if ip.net() == val_ip:
+                    msg = _("invalid IP {0} ({1}) with netmask {2},"
+                            " 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
             if not make_net: