mirror of https://github.com/apache/cloudstack.git
Prevent Nicira NVP tags from exceeding the 40 character limit.
This commit is contained in:
parent
e56d2a401c
commit
59cc382f20
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue