[ https://issues.apache.org/jira/browse/CLOUDSTACK-10288?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16444573#comment-16444573 ]
ASF GitHub Bot commented on CLOUDSTACK-10288: --------------------------------------------- nvazquez commented on a change in pull request #2566: ConfigDrive fixes: CLOUDSTACK-10288, CLOUDSTACK-10289 URL: https://github.com/apache/cloudstack/pull/2566#discussion_r182843439 ########## File path: server/test/com/cloud/network/element/ConfigDriveNetworkElementTest.java ########## @@ -236,13 +240,79 @@ public void testGetCapabilities () { @Test public void testAddPasswordAndUserdata() throws InsufficientCapacityException, ResourceUnavailableException { + List<String[]> actualVmData = getVmData(); + + assertThat(actualVmData, containsInAnyOrder( + new String[]{"userdata", "user_data", VMUSERDATA}, + new String[]{"metadata", "service-offering", VMOFFERING}, + new String[]{"metadata", "availability-zone", ZONENAME}, + new String[]{"metadata", "local-hostname", VMINSTANCENAME}, + new String[]{"metadata", "local-ipv4", "192.168.111.111"}, + new String[]{"metadata", "public-hostname", null}, + new String[]{"metadata", "public-ipv4", "192.168.111.111"}, + new String[]{"metadata", "vm-id", String.valueOf(VMID)}, + new String[]{"metadata", "instance-id", VMINSTANCENAME}, + new String[]{"metadata", "public-keys", PUBLIC_KEY}, + new String[]{"metadata", "cloud-identifier", String.format("CloudStack-{%s}", CLOUD_ID)}, + new String[]{PASSWORD, "vm_password", PASSWORD} + )); + } + + @Test + public void testAddPasswordAndUserdataStaticNat() throws InsufficientCapacityException, ResourceUnavailableException { + when(_ipAddressDao.findByAssociatedVmId(VMID)).thenReturn(publicIp); + when(publicIp.getAddress()).thenReturn(new Ip("7.7.7.7")); + + List<String[]> actualVmData = getVmData(); + + assertThat(actualVmData, containsInAnyOrder( + new String[]{"userdata", "user_data", VMUSERDATA}, + new String[]{"metadata", "service-offering", VMOFFERING}, + new String[]{"metadata", "availability-zone", ZONENAME}, + new String[]{"metadata", "local-hostname", VMINSTANCENAME}, + new String[]{"metadata", "local-ipv4", "192.168.111.111"}, + new String[]{"metadata", "public-hostname", "7.7.7.7"}, + new String[]{"metadata", "public-ipv4", "7.7.7.7"}, + new String[]{"metadata", "vm-id", String.valueOf(VMID)}, + new String[]{"metadata", "instance-id", VMINSTANCENAME}, + new String[]{"metadata", "public-keys", PUBLIC_KEY}, + new String[]{"metadata", "cloud-identifier", String.format("CloudStack-{%s}", CLOUD_ID)}, + new String[]{PASSWORD, "vm_password", PASSWORD} + )); + } + + + @Test + public void testAddPasswordAndUserdataUuid() throws InsufficientCapacityException, ResourceUnavailableException { + when(virtualMachine.getUuid()).thenReturn("vm-uuid"); + + List<String[]> actualVmData = getVmData(); + + assertThat(actualVmData, containsInAnyOrder( + new String[]{"userdata", "user_data", VMUSERDATA}, + new String[]{"metadata", "service-offering", VMOFFERING}, + new String[]{"metadata", "availability-zone", ZONENAME}, + new String[]{"metadata", "local-hostname", VMINSTANCENAME}, + new String[]{"metadata", "local-ipv4", "192.168.111.111"}, + new String[]{"metadata", "public-hostname", null}, + new String[]{"metadata", "public-ipv4", "192.168.111.111"}, + new String[]{"metadata", "vm-id", "vm-uuid"}, + new String[]{"metadata", "instance-id", "vm-uuid"}, + new String[]{"metadata", "public-keys", PUBLIC_KEY}, + new String[]{"metadata", "cloud-identifier", String.format("CloudStack-{%s}", CLOUD_ID)}, + new String[]{PASSWORD, "vm_password", PASSWORD} + )); + } + + private List<String[]> getVmData() throws InsufficientCapacityException, ResourceUnavailableException { final Answer answer = mock(Answer.class); final UserVmDetailVO userVmDetailVO = mock(UserVmDetailVO.class); when(endpoint.sendMessage(any(HandleConfigDriveIsoCommand.class))).thenReturn(answer); when(answer.getResult()).thenReturn(true); when(network.getTrafficType()).thenReturn(Networks.TrafficType.Guest); when(virtualMachine.getState()).thenReturn(VirtualMachine.State.Stopped); when(userVmDetailVO.getValue()).thenReturn(PUBLIC_KEY); + when(nicp.getIPv4Address()).thenReturn("192.168.111.111"); Review comment: Why not this one also as a final variable to use on the assert methods? ---------------------------------------------------------------- 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 > Config drive - Usedata corruption when gzipped > ----------------------------------------------- > > Key: CLOUDSTACK-10288 > URL: https://issues.apache.org/jira/browse/CLOUDSTACK-10288 > Project: CloudStack > Issue Type: Bug > Security Level: Public(Anyone can view this level - this is the > default.) > Affects Versions: 4.11.0.0 > Reporter: Rohit Yadav > Assignee: Frank Maximus > Priority: Major > > Should be able to create userdata via "echo hi | gzip | base64 -w0" and read > it back in VM via "mount -o loop /dev/sr1 /mnt/tmp; cat > /mnt/tmp/cloudstack/userdata/user_data.txt | gunzip" -- This message was sent by Atlassian JIRA (v7.6.3#76005)