GabrielBrascher commented on a change in pull request #2595: CLOUDSTACK-10199: 
Support requesting a specific IPv4 address
URL: https://github.com/apache/cloudstack/pull/2595#discussion_r186748709
 
 

 ##########
 File path: 
engine/orchestration/src/test/java/org/apache/cloudstack/engine/orchestration/NetworkOrchestratorTest.java
 ##########
 @@ -159,4 +174,255 @@ public void testDontRemoveDhcpServiceWhenNotProvided() {
         verify(testOrchastrator._ntwkSrvcDao, 
never()).getProviderForServiceInNetwork(network.getId(), Service.Dhcp);
         verify(testOrchastrator._networksDao, 
times(1)).findById(nic.getNetworkId());
     }
+
+    @Test
+    public void testConfigureNicProfileBasedOnRequestedIpTestMacNull() {
+        Network network = mock(Network.class);
+        NicProfile requestedNicProfile = new NicProfile();
+        NicProfile nicProfile = Mockito.spy(new NicProfile());
+
+        configureTestConfigureNicProfileBasedOnRequestedIpTests(nicProfile, 
0l, false, IPAddressVO.State.Free, "192.168.100.1", "255.255.255.0", 
"00-88-14-4D-4C-FB",
+                requestedNicProfile, null, "192.168.100.150");
+
+        
testOrchastrator.configureNicProfileBasedOnRequestedIp(requestedNicProfile, 
nicProfile, network);
+
+        verifyAndAssert("192.168.100.150", "192.168.100.1", "255.255.255.0", 
nicProfile, 1, 1);
+    }
+
+    @Test
+    public void 
testConfigureNicProfileBasedOnRequestedIpTestNicProfileMacNotNull() {
+        Network network = mock(Network.class);
+        NicProfile requestedNicProfile = new NicProfile();
+        NicProfile nicProfile = Mockito.spy(new NicProfile());
+
+        configureTestConfigureNicProfileBasedOnRequestedIpTests(nicProfile, 
0l, false, IPAddressVO.State.Free, "192.168.100.1", "255.255.255.0", 
"00-88-14-4D-4C-FB",
+                requestedNicProfile, "00-88-14-4D-4C-FB", "192.168.100.150");
+
+        
testOrchastrator.configureNicProfileBasedOnRequestedIp(requestedNicProfile, 
nicProfile, network);
+
+        verifyAndAssert("192.168.100.150", "192.168.100.1", "255.255.255.0", 
nicProfile, 1, 0);
+    }
+
+    @Test
+    public void testConfigureNicProfileBasedOnRequestedIpTestRequestedIpNull() 
{
+        testConfigureNicProfileBasedOnRequestedIpTestRequestedIp(null, "", 
false);
+    }
+
+    @Test
+    public void 
testConfigureNicProfileBasedOnRequestedIpTestRequestedIpIsBlank() {
+        testConfigureNicProfileBasedOnRequestedIpTestRequestedIp("", "The 
requested [IPv4 address=''] is not a valid IP address", true);
+    }
+
+    @Test
+    public void 
testConfigureNicProfileBasedOnRequestedIpTestRequestedIpIsNotValid() {
+        testConfigureNicProfileBasedOnRequestedIpTestRequestedIp("123", "The 
requested [IPv4 address='123'] is not a valid IP address", true);
+    }
+
+    private void 
testConfigureNicProfileBasedOnRequestedIpTestRequestedIp(String 
requestedIpv4Address, String exceptionAssert, boolean expectException) {
+        Network network = mock(Network.class);
+        NicProfile requestedNicProfile = new NicProfile();
+        NicProfile nicProfile = Mockito.spy(new NicProfile());
+
+        configureTestConfigureNicProfileBasedOnRequestedIpTests(nicProfile, 
0l, false, IPAddressVO.State.Free, "192.168.100.1", "255.255.255.0", 
"00-88-14-4D-4C-FB",
+                requestedNicProfile, null, requestedIpv4Address);
+        try {
+            
testOrchastrator.configureNicProfileBasedOnRequestedIp(requestedNicProfile, 
nicProfile, network);
+        } catch (InvalidParameterValueException e) {
+            assertEquals(exceptionAssert, e.getMessage());
 
 Review comment:
   Fixed.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to