From d9c694b4c4123bbd3e62f8a64484c27c6be1b100 Mon Sep 17 00:00:00 2001 From: Munir Ahmad Date: Thu, 30 Jul 2020 10:24:50 -0400 Subject: [SO] heatbridge implemention to populate AAI with openstack provider network/subnet Issue-ID: SO-3109 Signed-off-by: Munir Ahmad Change-Id: Ibb8f5b994072b797783dba7ce412baecb9b64174 --- .../org/onap/so/heatbridge/HeatBridgeImplTest.java | 66 ++++++++++++++++++++++ 1 file changed, 66 insertions(+) (limited to 'adapters/mso-openstack-adapters/src/test') diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/heatbridge/HeatBridgeImplTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/heatbridge/HeatBridgeImplTest.java index 643dd4cd9a..8c21e3f7f7 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/heatbridge/HeatBridgeImplTest.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/heatbridge/HeatBridgeImplTest.java @@ -85,9 +85,11 @@ import org.openstack4j.model.compute.Server; import org.openstack4j.model.compute.Server.Status; import org.openstack4j.model.heat.Resource; import org.openstack4j.model.network.IP; +import org.openstack4j.model.network.IPVersionType; import org.openstack4j.model.network.Network; import org.openstack4j.model.network.NetworkType; import org.openstack4j.model.network.Port; +import org.openstack4j.model.network.Subnet; import org.openstack4j.openstack.heat.domain.HeatResource; import org.openstack4j.openstack.heat.domain.HeatResource.Resources; import org.springframework.core.env.Environment; @@ -449,6 +451,70 @@ public class HeatBridgeImplTest { verify(osClient, times(10)).getNetworkById(anyString()); } + @Test + public void testUpdateNetworksToAai() throws HeatBridgeException { + + Subnet subnet1 = mock(Subnet.class); + when(subnet1.getId()).thenReturn("test-subnet1-id"); + when(subnet1.getName()).thenReturn("test-subnet1-name"); + when(subnet1.isDHCPEnabled()).thenReturn(true); + when(subnet1.getGateway()).thenReturn("test-subnet1-gateway"); + when(subnet1.getCidr()).thenReturn("test-subnet1-gateway"); + when(subnet1.getIpVersion()).thenReturn(IPVersionType.V4); + + Subnet subnet2 = mock(Subnet.class); + when(subnet2.getId()).thenReturn("test-subnet2-id"); + when(subnet2.getName()).thenReturn("test-subnet2-name"); + when(subnet2.isDHCPEnabled()).thenReturn(true); + when(subnet2.getGateway()).thenReturn("test-subnet1-gateway"); + when(subnet2.getCidr()).thenReturn("test-subnet1-gateway"); + when(subnet2.getIpVersion()).thenReturn(IPVersionType.V6); + + when(osClient.getSubnetById(subnet1.getId())).thenReturn(subnet1); + when(osClient.getSubnetById(subnet2.getId())).thenReturn(subnet2); + + List subnetIds = Arrays.asList(subnet1.getId(), subnet2.getId()); + + // Arrange + Network network1 = mock(Network.class); + when(network1.getId()).thenReturn("test-network1-id"); + when(network1.isShared()).thenReturn(true); + when(network1.isRouterExternal()).thenReturn(true); + when(network1.isAdminStateUp()).thenReturn(true); + when(network1.getProviderPhyNet()).thenReturn("sriov-network1"); + when(network1.getName()).thenReturn("network1"); + when(network1.getSubnets()).thenReturn(subnetIds); + + Network network2 = mock(Network.class); + when(network2.getId()).thenReturn("test-network2-id"); + when(network2.isShared()).thenReturn(true); + when(network2.isRouterExternal()).thenReturn(true); + when(network2.isAdminStateUp()).thenReturn(true); + when(network2.getProviderPhyNet()).thenReturn("sriov-network2"); + when(network2.getName()).thenReturn("network2"); + when(network2.getSubnets()).thenReturn(subnetIds); + + String vnfId = "some-uuiid-of-the-vnf"; + String vfModuleId = "some-uuiid-of-the-vf-module"; + + Subnet subnet = mock(Subnet.class); + + List networks = Arrays.asList(network1, network2); + + // Act #1 + heatbridge.buildAddNetworksToAaiAction(vnfId, vfModuleId, networks); + + // Assert #1 + verify(transaction, times(2)).createIfNotExists(any(AAIResourceUri.class), any(Optional.class)); + + // Act #2 + heatbridge.buildAddNetworksToAaiAction(vnfId, vfModuleId, networks); + + // Assert #2 + verify(transaction, times(4)).createIfNotExists(any(AAIResourceUri.class), any(Optional.class)); + + } + @Test public void testUpdateVserverLInterfacesToAai_skipVlans() throws HeatBridgeException { // Arrange -- cgit 1.2.3-korg