16
16
// under the License.
17
17
package com .cloud .hypervisor .kvm .resource ;
18
18
19
+ import java .net .URI ;
20
+ import java .net .URISyntaxException ;
21
+
19
22
import org .junit .Assert ;
20
- import org .junit .Before ;
21
23
import org .junit .Test ;
24
+ import org .junit .runner .RunWith ;
25
+ import org .mockito .InjectMocks ;
26
+ import org .mockito .Mockito ;
27
+ import org .mockito .Spy ;
28
+ import org .mockito .junit .MockitoJUnitRunner ;
22
29
23
30
import com .cloud .agent .api .to .NicTO ;
31
+ import com .cloud .exception .InternalErrorException ;
24
32
import com .cloud .network .Networks ;
25
- import org .junit .runner .RunWith ;
26
- import org .mockito .junit .MockitoJUnitRunner ;
27
33
28
34
@ RunWith (MockitoJUnitRunner .class )
29
35
public class BridgeVifDriverTest {
30
36
31
- private BridgeVifDriver driver ;
37
+ private static final String BRIDGE_NAME = "cloudbr1" ;
32
38
33
- @ Before
34
- public void setUp () throws Exception {
35
- driver = new BridgeVifDriver ();
36
- }
39
+ @ Spy
40
+ @ InjectMocks
41
+ private BridgeVifDriver driver = new BridgeVifDriver ();
37
42
38
43
@ Test
39
44
public void isBroadcastTypeVlanOrVxlan () {
@@ -58,4 +63,41 @@ public void isValidProtocolAndVnetId() {
58
63
Assert .assertTrue (driver .isValidProtocolAndVnetId ("123" , "vlan" ));
59
64
Assert .assertTrue (driver .isValidProtocolAndVnetId ("456" , "vxlan" ));
60
65
}
66
+
67
+ @ Test
68
+ public void createStorageVnetBridgeIfNeededReturnsStorageBrNameWhenBroadcastTypeIsNotStorageButValidValues () throws InternalErrorException {
69
+ NicTO nic = new NicTO ();
70
+ nic .setBroadcastType (Networks .BroadcastDomainType .Storage );
71
+ int vlan = 123 ;
72
+ String newBridge = "br-" + vlan ;
73
+ nic .setBroadcastUri (Networks .BroadcastDomainType .Storage .toUri (vlan ));
74
+ Mockito .doReturn (newBridge ).when (driver ).createVnetBr (Mockito .anyString (), Mockito .anyString (), Mockito .anyString ());
75
+ String result = driver .createStorageVnetBridgeIfNeeded (nic , "trafficLabel" , BRIDGE_NAME );
76
+ Assert .assertEquals (newBridge , result );
77
+ }
78
+
79
+ @ Test
80
+ public void createStorageVnetBridgeIfNeededReturnsStorageBrNameWhenBroadcastTypeIsNotStorage () throws InternalErrorException {
81
+ NicTO nic = new NicTO ();
82
+ nic .setBroadcastType (Networks .BroadcastDomainType .Vlan );
83
+ String result = driver .createStorageVnetBridgeIfNeeded (nic , "trafficLabel" , BRIDGE_NAME );
84
+ Assert .assertEquals (BRIDGE_NAME , result );
85
+ }
86
+
87
+ @ Test
88
+ public void createStorageVnetBridgeIfNeededReturnsStorageBrNameWhenBroadcastUriIsNull () throws InternalErrorException {
89
+ NicTO nic = new NicTO ();
90
+ nic .setBroadcastType (Networks .BroadcastDomainType .Storage );
91
+ String result = driver .createStorageVnetBridgeIfNeeded (nic , "trafficLabel" , BRIDGE_NAME );
92
+ Assert .assertEquals (BRIDGE_NAME , result );
93
+ }
94
+
95
+ @ Test
96
+ public void createStorageVnetBridgeIfNeededCreatesVnetBridgeWhenUntaggedVlan () throws InternalErrorException , URISyntaxException {
97
+ NicTO nic = new NicTO ();
98
+ nic .setBroadcastType (Networks .BroadcastDomainType .Storage );
99
+ nic .setBroadcastUri (new URI (Networks .BroadcastDomainType .Storage .scheme () + "://untagged" ));
100
+ String result = driver .createStorageVnetBridgeIfNeeded (nic , "trafficLabel" , BRIDGE_NAME );
101
+ Assert .assertEquals (BRIDGE_NAME , result );
102
+ }
61
103
}
0 commit comments