Skip to content

Commit 44aec19

Browse files
ruansteveCopilot
andcommitted
<fix>[l2network]: validate physicalInterface for LinuxBridge
When vSwitchType is LinuxBridge, physicalInterface must not be null or empty. Add interceptor check in L2NetworkApiInterceptor and unit test in AttachL2NetworkCase. ZSTAC-83300 Change-Id: I333a5bac866354c366051fece84e447f089e2306 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 3b4d09e commit 44aec19

3 files changed

Lines changed: 39 additions & 0 deletions

File tree

network/src/main/java/org/zstack/network/l2/L2NetworkApiInterceptor.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,12 @@ private void validate(APICreateL2NetworkMsg msg) {
123123
} catch (Exception e) {
124124
throw new ApiMessageInterceptionException(argerr(ORG_ZSTACK_NETWORK_L2_10012, "unsupported vSwitch type[%s]", msg.getvSwitchType()));
125125
}
126+
127+
if (L2NetworkConstant.VSWITCH_TYPE_LINUX_BRIDGE.equals(msg.getvSwitchType())
128+
&& (msg.getPhysicalInterface() == null || msg.getPhysicalInterface().trim().isEmpty())) {
129+
throw new ApiMessageInterceptionException(argerr(ORG_ZSTACK_NETWORK_L2_10021,
130+
"physicalInterface is required when vSwitchType is [%s]", msg.getvSwitchType()));
131+
}
126132
}
127133

128134
private void validate(APIChangeL2NetworkVlanIdMsg msg) {

test/src/test/groovy/org/zstack/test/integration/network/l2network/AttachL2NetworkCase.groovy

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ public class AttachL2NetworkCase extends SubCase{
9494
@Override
9595
public void test() {
9696
env.create {
97+
testCreateL2NetworkWithoutPhysicalInterface()
9798
testAttachL2NoVlanNetwork()
9899
testAttachL2ValnNetwork()
99100
testAttachL2NoVlanNetworkSynchronously()
@@ -103,6 +104,36 @@ public class AttachL2NetworkCase extends SubCase{
103104

104105
}
105106

107+
void testCreateL2NetworkWithoutPhysicalInterface() {
108+
ZoneInventory zone = env.inventoryByName("zone")
109+
110+
// creating L2 NoVlan network without physicalInterface should fail when vSwitchType is LinuxBridge
111+
expect(AssertionError.class) {
112+
createL2NoVlanNetwork {
113+
name = "test-no-physical-interface"
114+
zoneUuid = zone.uuid
115+
}
116+
}
117+
118+
// creating L2 NoVlan network with empty physicalInterface should also fail
119+
expect(AssertionError.class) {
120+
createL2NoVlanNetwork {
121+
name = "test-empty-physical-interface"
122+
zoneUuid = zone.uuid
123+
physicalInterface = ""
124+
}
125+
}
126+
127+
// creating L2 Vlan network without physicalInterface should fail when vSwitchType is LinuxBridge
128+
expect(AssertionError.class) {
129+
createL2VlanNetwork {
130+
name = "test-vlan-no-physical-interface"
131+
zoneUuid = zone.uuid
132+
vlan = 100
133+
}
134+
}
135+
}
136+
106137
void testAttachL2NoVlanNetwork(){
107138
L2NetworkInventory l21 = env.inventoryByName("l2-1")
108139
L2NetworkInventory l22 = env.inventoryByName("l2-2")

utils/src/main/java/org/zstack/utils/clouderrorcode/CloudOperationsErrorCode.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,6 +1016,8 @@ public class CloudOperationsErrorCode {
10161016

10171017
public static final String ORG_ZSTACK_NETWORK_L2_10020 = "ORG_ZSTACK_NETWORK_L2_10020";
10181018

1019+
public static final String ORG_ZSTACK_NETWORK_L2_10021 = "ORG_ZSTACK_NETWORK_L2_10021";
1020+
10191021
public static final String ORG_ZSTACK_CONSOLE_10000 = "ORG_ZSTACK_CONSOLE_10000";
10201022

10211023
public static final String ORG_ZSTACK_CONSOLE_10001 = "ORG_ZSTACK_CONSOLE_10001";

0 commit comments

Comments
 (0)