Skip to content

Commit e0a8246

Browse files
author
gitlab
committed
Merge branch 'shixin-ZSTAC-83300' into '5.5.12'
<fix>[l2network]: validate physicalInterface for LinuxBridge See merge request zstackio/zstack!9375
2 parents 69ae62a + 44aec19 commit e0a8246

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
@@ -1022,6 +1022,8 @@ public class CloudOperationsErrorCode {
10221022

10231023
public static final String ORG_ZSTACK_NETWORK_L2_10020 = "ORG_ZSTACK_NETWORK_L2_10020";
10241024

1025+
public static final String ORG_ZSTACK_NETWORK_L2_10021 = "ORG_ZSTACK_NETWORK_L2_10021";
1026+
10251027
public static final String ORG_ZSTACK_CONSOLE_10000 = "ORG_ZSTACK_CONSOLE_10000";
10261028

10271029
public static final String ORG_ZSTACK_CONSOLE_10001 = "ORG_ZSTACK_CONSOLE_10001";

0 commit comments

Comments
 (0)