|
52 | 52 | import java.util.HashMap; |
53 | 53 | import java.util.List; |
54 | 54 | import java.util.Map; |
| 55 | +import java.util.Set; |
55 | 56 | import java.util.UUID; |
56 | 57 |
|
57 | 58 | import org.apache.cloudstack.acl.Role; |
|
139 | 140 | import com.cloud.network.dao.PhysicalNetworkVO; |
140 | 141 | import com.cloud.network.element.NetworkElement; |
141 | 142 | import com.cloud.network.vpc.Vpc; |
| 143 | +import com.cloud.network.vpc.VpcOfferingVO; |
| 144 | +import com.cloud.network.vpc.dao.VpcOfferingDao; |
142 | 145 | import com.cloud.network.vpc.dao.VpcOfferingServiceMapDao; |
143 | 146 | import com.cloud.network.vpc.dao.VpcServiceMapDao; |
| 147 | +import com.cloud.offerings.NetworkOfferingVO; |
| 148 | +import com.cloud.offerings.dao.NetworkOfferingDao; |
144 | 149 | import com.cloud.offerings.dao.NetworkOfferingServiceMapDao; |
145 | 150 | import org.apache.cloudstack.extension.NetworkCustomActionProvider; |
146 | 151 | import com.cloud.org.Cluster; |
@@ -223,6 +228,12 @@ public class ExtensionsManagerImplTest { |
223 | 228 | @Mock |
224 | 229 | private VpcOfferingServiceMapDao vpcOfferingServiceMapDao; |
225 | 230 |
|
| 231 | + @Mock |
| 232 | + private NetworkOfferingDao networkOfferingDao; |
| 233 | + |
| 234 | + @Mock |
| 235 | + private VpcOfferingDao vpcOfferingDao; |
| 236 | + |
226 | 237 | @Before |
227 | 238 | public void setUp() { |
228 | 239 | MockitoAnnotations.openMocks(this); |
@@ -961,6 +972,7 @@ public void testUpdateExtension_RemovingUsedNetworkServiceThrows() { |
961 | 972 |
|
962 | 973 | when(networkOfferingServiceMapDao.listOfferingIdsByServiceAndProvider(Network.Service.StaticNat, "MyExt")) |
963 | 974 | .thenReturn(Collections.singletonList(1L)); |
| 975 | + when(networkOfferingDao.findById(1L)).thenReturn(mock(NetworkOfferingVO.class)); |
964 | 976 |
|
965 | 977 | extensionsManager.updateExtension(cmd); |
966 | 978 | } |
@@ -992,10 +1004,42 @@ public void testUpdateExtension_RemovingServiceUsedByVpcOfferingThrows() { |
992 | 1004 | .thenReturn(Collections.emptyList()); |
993 | 1005 | when(vpcOfferingServiceMapDao.listOfferingIdsByServiceAndProvider(Network.Service.StaticNat, "MyExt")) |
994 | 1006 | .thenReturn(Collections.singletonList(1L)); |
| 1007 | + when(vpcOfferingDao.findById(1L)).thenReturn(mock(VpcOfferingVO.class)); |
995 | 1008 |
|
996 | 1009 | extensionsManager.updateExtension(cmd); |
997 | 1010 | } |
998 | 1011 |
|
| 1012 | + @Test |
| 1013 | + public void updateNetworkExtensionServicesOnPhysicalNetworks_IgnoresRemovedOfferings() { |
| 1014 | + ExtensionVO ext = mock(ExtensionVO.class); |
| 1015 | + when(ext.getId()).thenReturn(9L); |
| 1016 | + when(ext.getName()).thenReturn("MyExt"); |
| 1017 | + |
| 1018 | + // service map rows still reference offerings 1 (network) and 2 (VPC), but both offerings are removed |
| 1019 | + when(networkOfferingServiceMapDao.listOfferingIdsByServiceAndProvider(Network.Service.CustomAction, "MyExt")) |
| 1020 | + .thenReturn(Collections.singletonList(1L)); |
| 1021 | + when(vpcOfferingServiceMapDao.listOfferingIdsByServiceAndProvider(Network.Service.CustomAction, "MyExt")) |
| 1022 | + .thenReturn(Collections.singletonList(2L)); |
| 1023 | + when(networkOfferingDao.findById(1L)).thenReturn(null); |
| 1024 | + when(vpcOfferingDao.findById(2L)).thenReturn(null); |
| 1025 | + |
| 1026 | + when(extensionResourceMapDao.listResourceIdsByExtensionIdAndType(9L, ExtensionResourceMap.ResourceType.PhysicalNetwork)) |
| 1027 | + .thenReturn(Collections.singletonList(100L)); |
| 1028 | + PhysicalNetworkServiceProviderVO nsp = mock(PhysicalNetworkServiceProviderVO.class); |
| 1029 | + when(nsp.getId()).thenReturn(500L); |
| 1030 | + when(nsp.getEnabledServices()).thenReturn(new ArrayList<>(Collections.singletonList(Network.Service.CustomAction))); |
| 1031 | + when(physicalNetworkServiceProviderDao.findByServiceProvider(100L, "MyExt")).thenReturn(nsp); |
| 1032 | + |
| 1033 | + extensionsManager.updateNetworkExtensionServicesOnPhysicalNetworks(ext, |
| 1034 | + Set.of(Network.Service.CustomAction), Set.of(Network.Service.UserData)); |
| 1035 | + |
| 1036 | + ArgumentCaptor<List<Network.Service>> captor = ArgumentCaptor.forClass(List.class); |
| 1037 | + verify(nsp).setEnabledServices(captor.capture()); |
| 1038 | + assertFalse(captor.getValue().contains(Network.Service.CustomAction)); |
| 1039 | + assertTrue(captor.getValue().contains(Network.Service.UserData)); |
| 1040 | + verify(physicalNetworkServiceProviderDao).update(500L, nsp); |
| 1041 | + } |
| 1042 | + |
999 | 1043 | @Test |
1000 | 1044 | public void testUpdateExtension_UpdatesPhysicalNetworkServicesWhenNotInUse() { |
1001 | 1045 | UpdateExtensionCmd cmd = mock(UpdateExtensionCmd.class); |
|
0 commit comments