]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Fix usage of netaddr '.broadcast'
authorKevin Benton <blak111@gmail.com>
Mon, 31 Aug 2015 02:15:27 +0000 (19:15 -0700)
committerMiguel Angel Ajo <mangelajo@redhat.com>
Mon, 31 Aug 2015 12:38:39 +0000 (12:38 +0000)
netaddr 0.7.16 changed the behavior of IPNetworks with /31 and /32
prefixes to make their 'broadcast' attribute return None. This patch
replaces the use of the attribute with a -1 index lookup to get the
last address instead.

Closes-Bug: #1490380
Change-Id: I97d71c4051882ddd9e496c78cfbce840ad7a2b67

neutron/agent/l3/link_local_allocator.py
neutron/agent/linux/ip_lib.py
neutron/ipam/utils.py
neutron/plugins/ml2/drivers/linuxbridge/agent/linuxbridge_neutron_agent.py
neutron/tests/common/net_helpers.py

index af7bca0839c6fdbe6aa062cfecf47789119b0f8b..f7fc84b56e5d586c52b33f29c03ed1d722cffa54 100644 (file)
@@ -23,8 +23,10 @@ class LinkLocalAddressPair(netaddr.IPNetwork):
 
     def get_pair(self):
         """Builds an address pair from the first and last addresses. """
+        # TODO(kevinbenton): the callers of this seem only interested in an IP,
+        # so we should just return two IPAddresses.
         return (netaddr.IPNetwork("%s/%s" % (self.network, self.prefixlen)),
-                netaddr.IPNetwork("%s/%s" % (self.broadcast, self.prefixlen)))
+                netaddr.IPNetwork("%s/%s" % (self[-1], self.prefixlen)))
 
 
 class LinkLocalAllocator(ItemAllocator):
index 7c4b4e37af949b90437d0f4517b393aef7c79729..a9c6f025deccd5a51911622de273b40f37dbbdbc 100644 (file)
@@ -422,7 +422,7 @@ class IpAddrCommand(IpDeviceCommandBase):
                 'scope', scope,
                 'dev', self.name]
         if net.version == 4:
-            args += ['brd', str(net.broadcast)]
+            args += ['brd', str(net[-1])]
         self._as_root([net.version], tuple(args))
 
     def delete(self, cidr):
index 6a4d96e8715aa5cb5e95f13d82343fb1b9d932ee..434cbcf558f7db5aaa275836ac262d3a130775f3 100644 (file)
@@ -23,7 +23,7 @@ def check_subnet_ip(cidr, ip_address):
     # Check that the IP is valid on subnet. This cannot be the
     # network or the broadcast address (which exists only in IPv4)
     return (ip != net.network
-            and (net.version == 6 or ip != net.broadcast)
+            and (net.version == 6 or ip != net[-1])
             and net.netmask & ip == net.network)
 
 
index f370b5f9ca280821200603076d67baf71d6c5577..dbbc4d39f086306de2e1f216988a5a99fd0435ee 100644 (file)
@@ -143,8 +143,7 @@ class LinuxBridgeManager(object):
         try:
             # Ensure the configured group address/range is valid and multicast
             net = netaddr.IPNetwork(cfg.CONF.VXLAN.vxlan_group)
-            if not (net.network.is_multicast() and
-                    net.broadcast.is_multicast()):
+            if not net.is_multicast():
                 raise ValueError()
             # Map the segmentation ID to (one of) the group address(es)
             return str(net.network +
index 577318146c38f63f69886d137bd3f469a25d56a7..a79c1ff20b0f4d92dcc8cc1c76ad7729a24ba257 100644 (file)
@@ -69,7 +69,7 @@ def increment_ip_cidr(ip_cidr, offset=1):
     net0 = netaddr.IPNetwork(ip_cidr)
     net = netaddr.IPNetwork(ip_cidr)
     net.value += offset
-    if not net0.network < net.ip < net0.broadcast:
+    if not net0.network < net.ip < net0[-1]:
         tools.fail(
             'Incorrect ip_cidr,offset tuple (%s,%s): "incremented" ip_cidr is '
             'outside ip_cidr' % (ip_cidr, offset))