private void updateVnicType( VnicProfileView profile, VmNetworkInterface existingVnic, VmNetworkInterface editedVnic) { boolean shouldBePciPassthroughType = profile != null && profile.isPassthrough() && supportedInterfaceTypes != null && supportedInterfaceTypes.contains(VmInterfaceType.pciPassthrough); if (existingVnic == null) { if (shouldBePciPassthroughType) { editedVnic.setType(VmInterfaceType.pciPassthrough.getValue()); } else { editedVnic.setType(defaultType == null ? null : defaultType.getValue()); } } else { VmInterfaceType existingInterfaceType = VmInterfaceType.forValue(existingVnic.getType()); boolean shouldRestoreToDefault = profile != null && !profile.isPassthrough() && VmInterfaceType.pciPassthrough.equals(existingInterfaceType); if (shouldBePciPassthroughType) { existingVnic.setType(VmInterfaceType.pciPassthrough.getValue()); } else if (shouldRestoreToDefault || supportedInterfaceTypes == null || !supportedInterfaceTypes.contains(existingInterfaceType)) { existingVnic.setType(defaultType == null ? null : defaultType.getValue()); } } }
/** Ensures that the network interface profile is returned. */ @Test public void testGetForUserWithPermission() { // This user has permissions on the network, hence he has permissions on the associated profiles VnicProfileView result = dao.get(FixturesTool.VM_NETWORK_INTERFACE_PROFILE, PRIVILEGED_USER_ID, true); assertNotNull(result); assertEquals(FixturesTool.VM_NETWORK_INTERFACE_PROFILE, result.getId()); }
/** Ensures the right set of vnic profiles is returned for the given data center. */ @Test public void testGetAllForDataCenter() { List<VnicProfileView> result = dao.getAllForDataCenter(FixturesTool.DATA_CENTER); assertNotNull(result); assertFalse(result.isEmpty()); for (VnicProfileView profile : result) { assertEquals(FixturesTool.DATA_CENTER_NAME, profile.getDataCenterName()); } }
/** Ensures the right set of vnic profiles is returned for the given data center. */ @Test public void testGetAllForDataCenterWithPermissions() { List<VnicProfileView> result = dao.getAllForDataCenter(FixturesTool.DATA_CENTER, PRIVILEGED_USER_ID, true); assertNotNull(result); assertFalse(result.isEmpty()); for (VnicProfileView profile : result) { assertEquals(FixturesTool.DATA_CENTER_NAME, profile.getDataCenterName()); } }
/** Ensures the right set of vnic profiles is returned for the given cluster id. */ @Test public void testGetAllForCluster() { List<VnicProfileView> result = dao.getAllForCluster(FixturesTool.CLUSTER); assertNotNull(result); assertFalse(result.isEmpty()); final Set<Guid> clusterNetworkIds = findClusterNetworkIds(FixturesTool.CLUSTER); for (VnicProfileView profile : result) { assertTrue(clusterNetworkIds.contains(profile.getNetworkId())); } }