marcaurele 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_r183615564
 
 

 ##########
 File path: 
engine/orchestration/src/test/java/org/apache/cloudstack/engine/orchestration/NetworkOrchestratorTest.java
 ##########
 @@ -159,4 +177,256 @@ 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 empty or blank", 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());
+            hasException = true;
+        }
+        assertEquals(expectException, hasException);
+
+        verifyAndAssert(null, null, null, nicProfile, 0, 0);
+    }
+
+    @Test
+    public void testConfigureNicProfileBasedOnRequestedIpTestGatewayIsBlank() {
+        testConfigureNicProfileBasedOnRequestedIpTestGateway("");
+    }
+
+    @Test
+    public void 
testConfigureNicProfileBasedOnRequestedIpTestGatewayIsNotValid() {
+        testConfigureNicProfileBasedOnRequestedIpTestGateway("123");
+    }
+
+    @Test
+    public void testConfigureNicProfileBasedOnRequestedIpTestGatewayIsNull() {
+        testConfigureNicProfileBasedOnRequestedIpTestGateway(null);
+    }
+
+    private void testConfigureNicProfileBasedOnRequestedIpTestGateway(String 
ipv4Gateway) {
+        Network network = mock(Network.class);
+        NicProfile requestedNicProfile = new NicProfile();
+        NicProfile nicProfile = Mockito.spy(new NicProfile());
+
+        configureTestConfigureNicProfileBasedOnRequestedIpTests(nicProfile, 
0l, false, IPAddressVO.State.Free, ipv4Gateway, "255.255.255.0", 
"00-88-14-4D-4C-FB",
+                requestedNicProfile, "00-88-14-4D-4C-FB", "192.168.100.150");
+        try {
+            
testOrchastrator.configureNicProfileBasedOnRequestedIp(requestedNicProfile, 
nicProfile, network);
+        } catch (CloudRuntimeException e) {
+            assertEquals(String.format("The [IPv4Gateway='%s'] from 
[VlanId='%s'] is not valid", ipv4Gateway, 0l), e.getMessage());
+            hasException = true;
+        }
+        assertTrue(hasException);
+        verifyAndAssert(null, null, null, nicProfile, 1, 0);
+    }
+
+    @Test
+    public void testConfigureNicProfileBasedOnRequestedIpTestNetmaskIsNull() {
+        testConfigureNicProfileBasedOnRequestedIpTestNetmask(null);
+    }
+
+    @Test
+    public void testConfigureNicProfileBasedOnRequestedIpTestNetmaskIsBlank() {
+        testConfigureNicProfileBasedOnRequestedIpTestNetmask("");
+    }
+
+    @Test
+    public void 
testConfigureNicProfileBasedOnRequestedIpTestNetmaskIsNotValid() {
+        testConfigureNicProfileBasedOnRequestedIpTestNetmask("123");
+    }
+
+    private void testConfigureNicProfileBasedOnRequestedIpTestNetmask(String 
ipv4Netmask) {
+        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", ipv4Netmask, 
"00-88-14-4D-4C-FB",
+                requestedNicProfile, "00-88-14-4D-4C-FB", "192.168.100.150");
+        try {
+            
testOrchastrator.configureNicProfileBasedOnRequestedIp(requestedNicProfile, 
nicProfile, network);
+        } catch (CloudRuntimeException e) {
+            assertEquals(String.format("The [IPv4Netmask='%s'] from 
[VlanId='%s'] is not valid", ipv4Netmask, 0l), e.getMessage());
+            hasException = true;
+        }
+        assertTrue(hasException);
+        verifyAndAssert(null, null, null, nicProfile, 1, 0);
+    }
+
+    @Test//(expected = CloudRuntimeException.class)
 
 Review comment:
   typo: the comment `//...` can be removed

----------------------------------------------------------------
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