cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject [06/11] git commit: updated refs/heads/master to afe1130
Date Sun, 06 Dec 2015 19:11:34 GMT
CID-1116484 cast to long and use long as cidrsize type
 and simpel test


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/2fadfe93
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/2fadfe93
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/2fadfe93

Branch: refs/heads/master
Commit: 2fadfe93dcb63693485fb44a7c5146024e232c3c
Parents: 637afb9
Author: Daan Hoogland <daan@onecht.net>
Authored: Tue Nov 10 14:40:24 2015 +0100
Committer: Daan Hoogland <daan@onecht.net>
Committed: Mon Nov 16 18:25:32 2015 +0100

----------------------------------------------------------------------
 utils/src/main/java/com/cloud/utils/net/NetUtils.java     | 9 +++++----
 utils/src/test/java/com/cloud/utils/net/NetUtilsTest.java | 8 ++++++++
 2 files changed, 13 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2fadfe93/utils/src/main/java/com/cloud/utils/net/NetUtils.java
----------------------------------------------------------------------
diff --git a/utils/src/main/java/com/cloud/utils/net/NetUtils.java b/utils/src/main/java/com/cloud/utils/net/NetUtils.java
index e48cf29..6da867d 100644
--- a/utils/src/main/java/com/cloud/utils/net/NetUtils.java
+++ b/utils/src/main/java/com/cloud/utils/net/NetUtils.java
@@ -47,6 +47,7 @@ import org.apache.log4j.Logger;
 
 import com.cloud.utils.IteratorUtil;
 import com.cloud.utils.Pair;
+import com.cloud.utils.exception.CloudRuntimeException;
 import com.cloud.utils.script.Script;
 import com.googlecode.ipv6.IPv6Address;
 import com.googlecode.ipv6.IPv6AddressRange;
@@ -907,14 +908,14 @@ public class NetUtils {
         if (!isValidIp(cidrAddress)) {
             return null;
         }
-        int cidrSizeNum = -1;
+        long cidrSizeNum = -1;
 
         try {
             cidrSizeNum = Integer.parseInt(cidrSize);
-        } catch (final Exception e) {
-            return null;
+        } catch (final NumberFormatException e) {
+            throw new CloudRuntimeException("cidrsize is not valid", e);
         }
-        final long numericNetmask = 0xffffffff >> MAX_CIDR - cidrSizeNum << MAX_CIDR
- cidrSizeNum;
+        final long numericNetmask = (long)0xffffffff >> MAX_CIDR - cidrSizeNum <<
MAX_CIDR - cidrSizeNum;
         final String netmask = NetUtils.long2Ip(numericNetmask);
         return getSubNet(cidrAddress, netmask);
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/2fadfe93/utils/src/test/java/com/cloud/utils/net/NetUtilsTest.java
----------------------------------------------------------------------
diff --git a/utils/src/test/java/com/cloud/utils/net/NetUtilsTest.java b/utils/src/test/java/com/cloud/utils/net/NetUtilsTest.java
index d4d23b3..1f948d2 100644
--- a/utils/src/test/java/com/cloud/utils/net/NetUtilsTest.java
+++ b/utils/src/test/java/com/cloud/utils/net/NetUtilsTest.java
@@ -418,9 +418,17 @@ public class NetUtilsTest {
 
         assertTrue("It should pass! 31 bit prefix.", is31PrefixCidr);
     }
+
     @Test
     public void testGetCidrSubNet() {
         final String cidr = "10.10.0.0/16";
+        String subnet = NetUtils.getCidrSubNet("10.10.10.10/16");
+        assertTrue(cidr + " does not contain " + subnet,NetUtils.isIpWithtInCidrRange(subnet,
cidr));
+    }
+
+    @Test
+    public void testGetCidrSubNetWithWidth() {
+        final String cidr = "10.10.0.0/16";
         String subnet = NetUtils.getCidrSubNet("10.10.10.10", 16);
         assertTrue(NetUtils.isIpWithtInCidrRange(subnet, cidr));
     }


Mime
View raw message