[ 
https://issues.apache.org/jira/browse/CLOUDSTACK-10199?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16449362#comment-16449362
 ] 

ASF GitHub Bot commented on CLOUDSTACK-10199:
---------------------------------------------

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:
us...@infra.apache.org


> Support requesting a specific IPv4 address in Basic Networking during 
> Instance creation
> ---------------------------------------------------------------------------------------
>
>                 Key: CLOUDSTACK-10199
>                 URL: https://issues.apache.org/jira/browse/CLOUDSTACK-10199
>             Project: CloudStack
>          Issue Type: Improvement
>      Security Level: Public(Anyone can view this level - this is the 
> default.) 
>          Components: API
>         Environment: CloudStack 4.10
>            Reporter: Wido den Hollander
>            Priority: Major
>              Labels: basic-networking
>
> DirectPodBasedNetworkGuru does not support requesting a custom IP-Address 
> while creating a new NIC/Instance.
> {quote}
> Error 530: Does not support custom ip allocation at this time: 
> NicProfile[0-0-null-null-null
> {
>   "cserrorcode": 4250,
>   "errorcode": 530,
>   "errortext": "Does not support custom ip allocation at this time: 
> NicProfile[0-0-null-null-null",
>   "uuidList": []
> }
> {quote}
> Some use-cases prefer the ability to request the IPv4 address which the 
> Instance will get.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to