cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From h...@apache.org
Subject [1/2] git commit: updated refs/heads/master to 90cd64c
Date Mon, 06 May 2013 09:49:18 GMT
Updated Branches:
  refs/heads/master e56d2a401 -> 90cd64cf5


Prevent Nicira NVP tags from exceeding the 40 character limit.


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

Branch: refs/heads/master
Commit: 59cc382f20ad01e47524ca865ffe4b0847a76dfd
Parents: e56d2a4
Author: Hugo Trippaers <htrippaers@schubergphilis.com>
Authored: Thu May 2 17:38:27 2013 +0200
Committer: Hugo Trippaers <htrippaers@schubergphilis.com>
Committed: Mon May 6 11:48:49 2013 +0200

----------------------------------------------------------------------
 .../src/com/cloud/network/nicira/NiciraNvpTag.java |   17 ++++-
 .../com/cloud/network/nicira/NiciraTagTest.java    |   54 +++++++++++++++
 2 files changed, 69 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/59cc382f/plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/NiciraNvpTag.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/NiciraNvpTag.java
b/plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/NiciraNvpTag.java
index f8282b8..157c3b5 100644
--- a/plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/NiciraNvpTag.java
+++ b/plugins/network-elements/nicira-nvp/src/com/cloud/network/nicira/NiciraNvpTag.java
@@ -16,7 +16,10 @@
 // under the License.
 package com.cloud.network.nicira;
 
+import org.apache.log4j.Logger;
+
 public class NiciraNvpTag {
+    private static final Logger s_logger = Logger.getLogger(NiciraNvpTag.class);
     private String scope;
     private String tag;
     
@@ -24,7 +27,12 @@ public class NiciraNvpTag {
     
     public NiciraNvpTag(String scope, String tag) {
         this.scope = scope;
-        this.tag = tag;
+        if (tag.length() > 40) {
+            s_logger.warn("tag \"" + tag + "\" too long, truncating to 40 characters");
+            this.tag = tag.substring(0, 40);
+        } else {
+            this.tag = tag;
+        }
     }
     
     public String getScope() {
@@ -40,7 +48,12 @@ public class NiciraNvpTag {
     }
     
     public void setTag(String tag) {
-        this.tag = tag;
+        if (tag.length() > 40) {
+            s_logger.warn("tag \"" + tag + "\" too long, truncating to 40 characters");
+            this.tag = tag.substring(0, 40);
+        } else {
+            this.tag = tag;
+        }
     }
     
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/59cc382f/plugins/network-elements/nicira-nvp/test/com/cloud/network/nicira/NiciraTagTest.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/test/com/cloud/network/nicira/NiciraTagTest.java
b/plugins/network-elements/nicira-nvp/test/com/cloud/network/nicira/NiciraTagTest.java
new file mode 100644
index 0000000..fd13e07
--- /dev/null
+++ b/plugins/network-elements/nicira-nvp/test/com/cloud/network/nicira/NiciraTagTest.java
@@ -0,0 +1,54 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.network.nicira;
+
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+public class NiciraTagTest {
+    @Test
+    public void testCreateTag() {
+        NiciraNvpTag tag = new NiciraNvpTag("scope","tag");
+        assertEquals("scope part set", "scope", tag.getScope());
+        assertEquals("tag part set", "tag", tag.getTag());
+    }
+
+    @Test
+    public void testCreateLongTag() {
+        NiciraNvpTag tag = new NiciraNvpTag("scope","verylongtagthatshouldattheminimumexceedthefortycharacterlenght");
+        assertEquals("scope part set", "scope", tag.getScope());
+        assertEquals("tag part set", "verylongtagthatshouldattheminimumexceedt", tag.getTag());
+    }
+
+    @Test
+    public void testSetTag() {
+        NiciraNvpTag tag = new NiciraNvpTag();
+        tag.setScope("scope");
+        tag.setTag("tag");
+        assertEquals("scope part set", "scope", tag.getScope());
+        assertEquals("tag part set", "tag", tag.getTag());
+    }
+
+    @Test
+    public void testSetLongTag() {
+        NiciraNvpTag tag = new NiciraNvpTag();
+        tag.setScope("scope");
+        tag.setTag("verylongtagthatshouldattheminimumexceedthefortycharacterlenght");
+        assertEquals("scope part set", "scope", tag.getScope());
+        assertEquals("tag part set", "verylongtagthatshouldattheminimumexceedt", tag.getTag());
+    }
+}
\ No newline at end of file


Mime
View raw message