Skip to content

Commit 7adcf8c

Browse files
committed
NSX: fix segment profile cloning and strengthen tests
Signed-off-by: Dogface2k <100990646+Dogface2k@users.noreply.github.com>
1 parent f3456b9 commit 7adcf8c

3 files changed

Lines changed: 36 additions & 5 deletions

File tree

plugins/network-elements/nsx/src/test/java/org/apache/cloudstack/service/NsxApiClientTest.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.vmware.nsx.model.ClusterStatus;
2424
import com.vmware.nsx.model.ControllerClusterStatus;
2525
import com.vmware.nsx_policy.Infra;
26+
import com.vmware.nsx_policy.InfraStub;
2627
import com.vmware.nsx_policy.infra.IpDiscoveryProfiles;
2728
import com.vmware.nsx_policy.infra.LbAppProfiles;
2829
import com.vmware.nsx_policy.infra.LbMonitorProfiles;
@@ -52,7 +53,12 @@
5253
import com.vmware.nsx_policy.model.SegmentDiscoveryProfileBindingMap;
5354
import com.vmware.nsx_policy.model.SegmentSecurityProfile;
5455
import com.vmware.vapi.bindings.Service;
56+
import com.vmware.vapi.bindings.StubConfiguration;
5557
import com.vmware.vapi.bindings.Structure;
58+
import com.vmware.vapi.core.ApiProvider;
59+
import com.vmware.vapi.core.AsyncHandle;
60+
import com.vmware.vapi.core.MethodResult;
61+
import com.vmware.vapi.data.DataValue;
5662
import com.vmware.vapi.std.errors.Error;
5763
import com.vmware.vapi.std.errors.NotFound;
5864
import org.apache.cloudstack.resource.NsxLoadBalancerMember;
@@ -118,7 +124,8 @@ public void testCreateGroupForSegment() {
118124

119125
@Test
120126
public void testCreateSegmentBindsConfiguredProfiles() {
121-
Infra infraService = Mockito.mock(Infra.class);
127+
ApiProvider apiProvider = Mockito.mock(ApiProvider.class);
128+
Infra infraService = Mockito.spy(new InfraStub(apiProvider, new StubConfiguration()));
122129
IpDiscoveryProfiles ipProfiles = Mockito.mock(IpDiscoveryProfiles.class);
123130
MacDiscoveryProfiles macProfiles = Mockito.mock(MacDiscoveryProfiles.class);
124131
SegmentSecurityProfiles securityProfiles = Mockito.mock(SegmentSecurityProfiles.class);
@@ -138,6 +145,11 @@ public void testCreateSegmentBindsConfiguredProfiles() {
138145
when(ipProfile.getPath()).thenReturn("/infra/ip-discovery-profiles/ip-profile");
139146
when(macProfile.getPath()).thenReturn("/infra/mac-discovery-profiles/mac-profile");
140147
when(securityProfile.getPath()).thenReturn("/infra/segment-security-profiles/security-profile");
148+
Mockito.doAnswer(invocation -> {
149+
AsyncHandle<MethodResult> asyncHandle = invocation.getArgument(4);
150+
asyncHandle.setResult(MethodResult.EMPTY);
151+
return null;
152+
}).when(apiProvider).invoke(anyString(), eq("patch"), any(DataValue.class), any(), any());
141153
ArgumentCaptor<com.vmware.nsx_policy.model.Infra> infraCaptor =
142154
ArgumentCaptor.forClass(com.vmware.nsx_policy.model.Infra.class);
143155

@@ -146,6 +158,7 @@ public void testCreateSegmentBindsConfiguredProfiles() {
146158
"ip-profile", "mac-profile", "security-profile");
147159

148160
verify(infraService).patch(infraCaptor.capture(), eq(false));
161+
verify(apiProvider).invoke(anyString(), eq("patch"), any(DataValue.class), any(), any());
149162
verify(nsxService, never()).apply(Segments.class);
150163
Assert.assertEquals("Infra", infraCaptor.getValue().getResourceType());
151164
Assert.assertEquals(1, infraCaptor.getValue().getChildren().size());

server/src/test/java/com/cloud/network/NetworkServiceImplTest.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,12 +688,30 @@ public void testMatchingNsxSegmentProfilesAllowOfferingUpgrade() {
688688
public void testDifferentNsxSegmentProfilesRejectOfferingUpgrade() {
689689
long oldOfferingId = 1L;
690690
long newOfferingId = 2L;
691+
long networkId = 3L;
692+
Network network = Mockito.mock(Network.class);
693+
NetworkOfferingVO oldOffering = Mockito.mock(NetworkOfferingVO.class);
694+
NetworkOfferingVO newOffering = Mockito.mock(NetworkOfferingVO.class);
695+
Mockito.when(network.getId()).thenReturn(networkId);
696+
Mockito.when(networkOfferingDao.findByIdIncludingRemoved(oldOfferingId)).thenReturn(oldOffering);
697+
Mockito.when(networkOfferingDao.findById(newOfferingId)).thenReturn(newOffering);
698+
Mockito.when(oldOffering.getGuestType()).thenReturn(Network.GuestType.Isolated);
699+
Mockito.when(newOffering.getGuestType()).thenReturn(Network.GuestType.Isolated);
700+
Mockito.when(oldOffering.getTrafficType()).thenReturn(Networks.TrafficType.Guest);
701+
Mockito.when(newOffering.getTrafficType()).thenReturn(Networks.TrafficType.Guest);
702+
Mockito.when(ipAddressDao.listByAssociatedNetwork(networkId, null)).thenReturn(List.of());
703+
Mockito.when(networkModel.getNetworkOfferingServiceProvidersMap(newOfferingId)).thenReturn(new HashMap<>());
691704
Mockito.when(networkModel.getNtwkOffDetails(oldOfferingId)).thenReturn(Map.of(
692705
NetworkOffering.Detail.NsxMacDiscoveryProfileId, "old-mac-profile"));
706+
Mockito.when(networkModel.getNtwkOffDetails(newOfferingId)).thenReturn(Map.of(
707+
NetworkOffering.Detail.NsxMacDiscoveryProfileId, "old-mac-profile"));
708+
709+
Assert.assertTrue(service.canUpgrade(network, oldOfferingId, newOfferingId));
710+
693711
Mockito.when(networkModel.getNtwkOffDetails(newOfferingId)).thenReturn(Map.of(
694712
NetworkOffering.Detail.NsxMacDiscoveryProfileId, "new-mac-profile"));
695713

696-
Assert.assertFalse(service.haveMatchingNsxSegmentProfiles(oldOfferingId, newOfferingId));
714+
Assert.assertFalse(service.canUpgrade(network, oldOfferingId, newOfferingId));
697715
}
698716

699717
@Test

ui/src/views/offering/CloneNetworkOffering.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -978,9 +978,9 @@ export default {
978978
if (r.details.macaddresschanges) this.form.macaddresschanges = r.details.macaddresschanges
979979
if (r.details.forgedtransmits) this.form.forgedtransmits = r.details.forgedtransmits
980980
if (r.details.maclearning) this.form.maclearning = r.details.maclearning
981-
if (r.details.nsxipdiscoveryprofileid) this.form.nsxipdiscoveryprofileid = r.details.nsxipdiscoveryprofileid
982-
if (r.details.nsxmacdiscoveryprofileid) this.form.nsxmacdiscoveryprofileid = r.details.nsxmacdiscoveryprofileid
983-
if (r.details.nsxsegmentsecurityprofileid) this.form.nsxsegmentsecurityprofileid = r.details.nsxsegmentsecurityprofileid
981+
if (r.details.NsxIpDiscoveryProfileId) this.form.nsxipdiscoveryprofileid = r.details.NsxIpDiscoveryProfileId
982+
if (r.details.NsxMacDiscoveryProfileId) this.form.nsxmacdiscoveryprofileid = r.details.NsxMacDiscoveryProfileId
983+
if (r.details.NsxSegmentSecurityProfileId) this.form.nsxsegmentsecurityprofileid = r.details.NsxSegmentSecurityProfileId
984984
}
985985
986986
this.forVpc = r.forvpc || false

0 commit comments

Comments
 (0)