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:
[email protected]
With regards,
Apache Git Services