diff options
Diffstat (limited to 'adapters/mso-openstack-adapters')
7 files changed, 166 insertions, 154 deletions
diff --git a/adapters/mso-openstack-adapters/pom.xml b/adapters/mso-openstack-adapters/pom.xml index eb6cba5510..7d5e8cc6fd 100644 --- a/adapters/mso-openstack-adapters/pom.xml +++ b/adapters/mso-openstack-adapters/pom.xml @@ -51,76 +51,6 @@ </execution> </executions> </plugin> - - <!-- run the following plugin only when there's a wsdl change and you need to recompile the java classes - <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>jaxws-maven-plugin</artifactId> - <version>2.4.1</version> - <executions> - <execution> - <id>generate-network-async-stubs</id> - <phase>process-classes</phase> - <goals> - <goal>wsimport</goal> - </goals> - <configuration> - <vmArgs> - <vmArg>-Djavax.xml.accessExternalSchema=all</vmArg> - </vmArgs> - <wsdlDirectory>src/main/resources/wsdl</wsdlDirectory> - <wsdlFiles> - <wsdlFile>NetworkAdapterNotify.wsdl</wsdlFile> - </wsdlFiles> - <wsdlLocation>/NetworkAdapterNotify.wsdl</wsdlLocation> - <packageName>org.onap.so.adapters.network.async.client</packageName> - <xnocompile>false</xnocompile> - <keep>true</keep> - </configuration> - </execution> - - <execution> - <id>generate-vnf-async-stubs</id> - <phase>process-classes</phase> - <goals> - <goal>wsimport</goal> - </goals> - <configuration> - <vmArgs> - <vmArg>-Djavax.xml.accessExternalSchema=all</vmArg> - </vmArgs> - <wsdlDirectory>src/main/resources/wsdl</wsdlDirectory> - <wsdlFiles> - <wsdlFile>VnfAdapterNotify.wsdl</wsdlFile> - </wsdlFiles> - <wsdlLocation>/VnfAdapterNotify.wsdl</wsdlLocation> - <packageName>org.onap.so.adapters.vnf.async.client</packageName> - <xnocompile>false</xnocompile> - <keep>true</keep> - </configuration> - </execution> - </executions> - </plugin> - <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>build-helper-maven-plugin</artifactId> - <version>3.0.0</version> - <executions> - <execution> - <id>add-source</id> - <phase>generate-sources</phase> - <goals> - <goal>add-source</goal> - </goals> - <configuration> - <sources> - <source>${project.build.directory}/generated-sources/wsimport/</source> - </sources> - </configuration> - </execution> - </executions> - </plugin> - --> <plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> @@ -228,17 +158,14 @@ <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-spring-boot-starter-jaxws</artifactId> - <version>${cxf.version}</version> </dependency> <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-spring-boot-starter-jaxrs</artifactId> - <version>${cxf.version}</version> </dependency> <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-rs-service-description-swagger</artifactId> - <version>${cxf.version}</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/HeatBridgeImpl.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/HeatBridgeImpl.java index 90a578d3b4..5cb870e0d7 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/HeatBridgeImpl.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/HeatBridgeImpl.java @@ -46,6 +46,7 @@ import java.util.stream.Collectors; import javax.annotation.Nonnull; import javax.ws.rs.NotFoundException; import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.UriBuilder; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.validator.routines.InetAddressValidator; import org.onap.aai.domain.yang.Flavor; @@ -59,7 +60,6 @@ import org.onap.aai.domain.yang.Pserver; import org.onap.aai.domain.yang.Relationship; import org.onap.aai.domain.yang.RelationshipList; import org.onap.aai.domain.yang.SriovPf; -import org.onap.aai.domain.yang.SriovPfs; import org.onap.aai.domain.yang.Subnets; import org.onap.aai.domain.yang.SriovVf; import org.onap.aai.domain.yang.VfModule; @@ -80,12 +80,12 @@ import org.onap.aaiclient.client.graphinventory.entities.DSLQuery; import org.onap.aaiclient.client.graphinventory.entities.DSLQueryBuilder; import org.onap.aaiclient.client.graphinventory.entities.DSLStartNode; import org.onap.aaiclient.client.graphinventory.entities.Node; +import org.onap.aaiclient.client.graphinventory.entities.Pathed; import org.onap.aaiclient.client.graphinventory.entities.Start; import org.onap.aaiclient.client.graphinventory.entities.TraversalBuilder; import org.onap.aaiclient.client.graphinventory.entities.__; import org.onap.aaiclient.client.graphinventory.entities.uri.Depth; import org.onap.aaiclient.client.graphinventory.exceptions.BulkProcessFailed; -import org.onap.logging.filter.base.ErrorCode; import org.onap.so.cloud.resource.beans.NodeType; import org.onap.so.db.catalog.beans.CloudIdentity; import org.onap.so.db.catalog.beans.ServerType; @@ -95,8 +95,6 @@ import org.onap.so.heatbridge.helpers.AaiHelper; import org.onap.so.heatbridge.openstack.api.OpenstackClient; import org.onap.so.heatbridge.openstack.factory.OpenstackClientFactoryImpl; import org.onap.so.heatbridge.utils.HeatBridgeUtils; -import org.onap.so.logger.LoggingAnchor; -import org.onap.so.logger.MessageEnum; import org.onap.so.spring.SpringContextHelper; import org.openstack4j.model.compute.Server; import org.openstack4j.model.heat.Resource; @@ -466,7 +464,7 @@ public class HeatBridgeImpl implements HeatBridgeApi { resourcesClient.createIfNotExists(uri, Optional.of(pInterface)); } - private void updateLInterfaceVlan(final Port port, final LInterface lIf, final String hostName) + protected void updateLInterfaceVlan(final Port port, final LInterface lIf, final String hostName) throws HeatBridgeException { // add back all vlan logic Vlan vlan = new Vlan(); @@ -486,11 +484,13 @@ public class HeatBridgeImpl implements HeatBridgeApi { Optional.of(vlan)); } - if (nodeType == NodeType.GREENFIELD) { - validatePhysicalNetwork(port, network); - processOVS(lIf, hostName, NodeType.GREENFIELD.getInterfaceName()); - } else { - processOVS(lIf, hostName, NodeType.BROWNFIELD.getInterfaceName()); + if (!lIf.getInterfaceType().equals(SRIOV)) { + if (nodeType == NodeType.GREENFIELD) { + validatePhysicalNetwork(port, network); + processOVS(lIf, hostName, NodeType.GREENFIELD.getInterfaceName()); + } else { + processOVS(lIf, hostName, NodeType.BROWNFIELD.getInterfaceName()); + } } List<String> privateVlans = (ArrayList<String>) port.getProfile().get(PRIVATE_VLANS); @@ -580,69 +580,67 @@ public class HeatBridgeImpl implements HeatBridgeApi { * * @param port Openstack port object * @param lIf AAI l-interface object + * @throws HeatBridgeException */ - private void updateSriovPfToPserver(final Port port, final LInterface lIf) { + protected void updateSriovPfToPserver(final Port port, final LInterface lIf) throws HeatBridgeException { if (port.getvNicType().equalsIgnoreCase(HeatBridgeConstants.OS_SRIOV_PORT_TYPE)) { - if (port.getProfile() == null || Strings - .isNullOrEmpty(port.getProfile().get(HeatBridgeConstants.OS_PHYSICAL_NETWORK_KEY).toString())) { - logger.debug("The SRIOV port:" + port.getName() + " is missing physical-network-id, cannot update " - + "sriov-pf object for host pserver: " + port.getHostId()); - return; - } - Optional<String> matchingPifName = HeatBridgeUtils.getMatchingPserverPifName( - port.getProfile().get(HeatBridgeConstants.OS_PHYSICAL_NETWORK_KEY).toString()); - if (matchingPifName.isPresent()) { - // Update l-interface description - String pserverHostName = port.getHostId(); - lIf.setInterfaceDescription( - "Attached to SR-IOV port: " + pserverHostName + "::" + matchingPifName.get()); - try { - Optional<PInterface> matchingPIf = resourcesClient.get(PInterface.class, - AAIUriFactory - .createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure() - .pserver(pserverHostName).pInterface(matchingPifName.get())) - .depth(Depth.ONE)); - if (matchingPIf.isPresent()) { - SriovPfs pIfSriovPfs = matchingPIf.get().getSriovPfs(); - if (pIfSriovPfs == null) { - pIfSriovPfs = new SriovPfs(); - } - // Extract PCI-ID from OS port object - String pfPciId = port.getProfile().get(HeatBridgeConstants.OS_PCI_SLOT_KEY).toString(); - - List<SriovPf> existingSriovPfs = pIfSriovPfs.getSriovPf(); - if (CollectionUtils.isEmpty(existingSriovPfs) || existingSriovPfs.stream() - .noneMatch(existingSriovPf -> existingSriovPf.getPfPciId().equals(pfPciId))) { - // Add sriov-pf object with PCI-ID to AAI - SriovPf sriovPf = new SriovPf(); - sriovPf.setPfPciId(pfPciId); - logger.debug("Queuing AAI command to update sriov-pf object to pserver: " + pserverHostName - + "/" + matchingPifName.get()); - - AAIResourceUri sriovPfUri = AAIUriFactory.createResourceUri( - AAIFluentTypeBuilder.cloudInfrastructure().pserver(pserverHostName) - .pInterface(matchingPifName.get()).sriovPf(sriovPf.getPfPciId())); - - - if (!resourcesClient.exists(sriovPfUri)) { - transaction.create(sriovPfUri, sriovPf); - - AAIResourceUri sriovVfUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder - .cloudInfrastructure().cloudRegion(cloudOwner, cloudRegionId).tenant(tenantId) - .vserver(port.getDeviceId()).lInterface(lIf.getInterfaceName()).sriovVf( - port.getProfile().get(HeatBridgeConstants.OS_PCI_SLOT_KEY).toString())); - transaction.connect(sriovPfUri, sriovVfUri); - } - } + + AAIResourceUri sriovVfUri = AAIUriFactory + .createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure().cloudRegion(cloudOwner, cloudRegionId) + .tenant(tenantId).vserver(port.getDeviceId()).lInterface(lIf.getInterfaceName()) + .sriovVf(port.getProfile().get(HeatBridgeConstants.OS_PCI_SLOT_KEY).toString())); + + boolean relationshipExist = sriovVfHasSriovPfRelationship(sriovVfUri); + + String pserverHostName = port.getHostId(); + lIf.setInterfaceDescription("Attached to SR-IOV port: " + pserverHostName); + + if (!relationshipExist) { + AAIResourceUri pserverUri = AAIUriFactory + .createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure().pserver(pserverHostName)); + if (resourcesClient.exists(pserverUri)) { + String pfPciId = port.getProfile().get(HeatBridgeConstants.OS_PF_PCI_SLOT_KEY).toString(); + + DSLQueryBuilder<Start, Node> builder = TraversalBuilder + .fragment(new DSLStartNode(Types.PSERVER, __.key("hostname", pserverHostName))) + .to(__.node(Types.P_INTERFACE) + .to(__.node(Types.SRIOV_PF, __.key("pf-pci-id", pfPciId)).output())); + + List<Pathed> results = getAAIDSLClient().queryPathed(new DSLQuery(builder.build())); + + if (results.size() == 1) { + + AAIResourceUri sriovPfUri = AAIUriFactory.createResourceFromExistingURI(Types.SRIOV_PF, + UriBuilder.fromUri(results.get(0).getResourceLink()).build()); + + transaction.connect(sriovPfUri, sriovVfUri); + + } else { + throw new HeatBridgeException("Unable to find sriov-pf related link " + pfPciId + + ". Unexpected results size" + results.size()); } - } catch (WebApplicationException e) { - // Silently log that we failed to update the Pserver p-interface with PCI-ID - logger.error(LoggingAnchor.NINE, MessageEnum.GENERAL_EXCEPTION, pserverHostName, - matchingPifName.get(), cloudOwner, tenantId, "OpenStack", "Heatbridge", - ErrorCode.DataError.getValue(), "Exception - Failed to add sriov-pf object to pserver", e); + } else { + logger.error("Pserver {} does not exist in AAI. Unable to build sriov-vf to sriov-pf relationship.", + pserverHostName); + throw new HeatBridgeException("Pserver " + pserverHostName + " does not exist in AAI"); + } + } + } + } + + protected boolean sriovVfHasSriovPfRelationship(AAIResourceUri sriovVfUri) { + boolean pfRelationshipsExist = false; + if (resourcesClient.exists(sriovVfUri)) { + Optional<Relationships> sriovVfRelationships = resourcesClient.get(sriovVfUri).getRelationships(); + + if (sriovVfRelationships.isPresent()) { + List<AAIResourceUri> sriovPfUris = sriovVfRelationships.get().getRelatedUris(Types.SRIOV_PF); + if (sriovPfUris.size() != 0) { + pfRelationshipsExist = true; } } } + return pfRelationshipsExist; } protected void updateLInterfaceIps(final Port port, final LInterface lIf) { diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/constants/HeatBridgeConstants.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/constants/HeatBridgeConstants.java index 71c6a96cd6..c8a39a5795 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/constants/HeatBridgeConstants.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/constants/HeatBridgeConstants.java @@ -43,6 +43,7 @@ public class HeatBridgeConstants { public static final String OS_NEUTRON_PROVIDERNET = "OS::Neutron::ProviderNet"; public static final String OS_SRIOV_PORT_TYPE = "direct"; public static final String OS_PCI_SLOT_KEY = "pci_slot"; + public static final String OS_PF_PCI_SLOT_KEY = "pf_pci_slot"; public static final String OS_PHYSICAL_NETWORK_KEY = "physical_network"; public static final String OS_PHYSICAL_INTERFACE_KEY = "physical-interface"; public static final String OS_VLAN_NETWORK_KEY = "vlan"; diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/utils/HeatBridgeUtils.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/utils/HeatBridgeUtils.java index 1667f980e1..c281dbd9e5 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/utils/HeatBridgeUtils.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/utils/HeatBridgeUtils.java @@ -59,7 +59,7 @@ public final class HeatBridgeUtils { public static Optional<String> getMatchingPserverPifName(@Nonnull final String physicalNetworkName) { Preconditions.checkState(!Strings.isNullOrEmpty(physicalNetworkName), - "Physical network name is null or " + "empty!"); + "Physical network name is null or empty!"); if (physicalNetworkName.contains(OS_SIDE_DEDICATED_SRIOV_PREFIX)) { return Optional.of( physicalNetworkName.replace(OS_SIDE_DEDICATED_SRIOV_PREFIX, COMPUTE_SIDE_DEDICATED_SRIOV_PREFIX)); @@ -67,7 +67,7 @@ public final class HeatBridgeUtils { return Optional .of(physicalNetworkName.replace(OS_SIDE_SHARED_SRIOV_PREFIX, COMPUTE_SIDE_SHARED_SRIOV_PREFIX)); } - return Optional.empty(); + return Optional.of(physicalNetworkName); } public static List<String> extractPciIdsFromVServer(Vserver vserver) { 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 110faaf8ab..531496cc8f 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 @@ -41,6 +41,8 @@ import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -48,9 +50,10 @@ import static org.mockito.Mockito.when; import java.io.File; import java.io.IOException; import java.nio.charset.Charset; +import java.nio.file.Files; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Objects; @@ -59,12 +62,12 @@ import java.util.Set; import org.apache.commons.io.FileUtils; import org.junit.Assert; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.InjectMocks; import org.mockito.Mock; +import org.mockito.Spy; import org.mockito.junit.MockitoJUnitRunner; import org.onap.aai.domain.yang.L3InterfaceIpv6AddressList; import org.onap.aai.domain.yang.LInterface; @@ -73,9 +76,12 @@ import org.onap.aai.domain.yang.SriovPf; import org.onap.aaiclient.client.aai.AAIDSLQueryClient; import org.onap.aaiclient.client.aai.AAIResourcesClient; import org.onap.aaiclient.client.aai.AAISingleTransactionClient; +import org.onap.aaiclient.client.aai.entities.Results; import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri; import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory; import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder; +import org.onap.aaiclient.client.graphinventory.entities.DSLQuery; +import org.onap.aaiclient.client.graphinventory.entities.Pathed; import org.onap.aaiclient.client.graphinventory.exceptions.BulkProcessFailed; import org.onap.so.cloud.resource.beans.NodeType; import org.onap.so.db.catalog.beans.CloudIdentity; @@ -98,6 +104,7 @@ import org.openstack4j.openstack.heat.domain.HeatResource; import org.openstack4j.openstack.heat.domain.HeatResource.Resources; import org.springframework.core.env.Environment; import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.collect.ImmutableMap; @@ -131,6 +138,10 @@ public class HeatBridgeImplTest { @Mock private Server server; + @Mock + private AAIDSLQueryClient dSLQueryClient; + + @Spy @InjectMocks private HeatBridgeImpl heatbridge = new HeatBridgeImpl(resourcesClient, cloudIdentity, CLOUD_OWNER, REGION_ID, REGION_ID, TENANT_ID, NodeType.GREENFIELD); @@ -339,11 +350,13 @@ public class HeatBridgeImplTest { } @Test - public void testUpdateVserverLInterfacesToAai() throws HeatBridgeException { + public void testUpdateVserverLInterfacesToAai() + throws HeatBridgeException, JsonParseException, JsonMappingException, IOException { // Arrange List<Resource> stackResources = (List<Resource>) extractTestStackResources(); Port port = mock(Port.class); when(port.getId()).thenReturn("test-port-id"); + when(port.getHostId()).thenReturn("pserverId"); when(port.getName()).thenReturn("test-port-name"); when(port.getvNicType()).thenReturn(HeatBridgeConstants.OS_SRIOV_PORT_TYPE); when(port.getMacAddress()).thenReturn("78:4f:43:68:e2:78"); @@ -354,7 +367,7 @@ public class HeatBridgeImplTest { when(server.getHypervisorHostname()).thenReturn("test.server.name"); String pfPciId = "0000:08:00.0"; when(port.getProfile()).thenReturn(ImmutableMap.of(HeatBridgeConstants.OS_PCI_SLOT_KEY, pfPciId, - HeatBridgeConstants.OS_PHYSICAL_NETWORK_KEY, "physical_network_id")); + HeatBridgeConstants.OS_PF_PCI_SLOT_KEY, "testPfPciId")); IP ip = mock(IP.class); @@ -383,10 +396,14 @@ public class HeatBridgeImplTest { SriovPf sriovPf = new SriovPf(); sriovPf.setPfPciId(pfPciId); - PInterface pIf = mock(PInterface.class); - when(pIf.getInterfaceName()).thenReturn("test-port-id"); - when(resourcesClient.get(eq(PInterface.class), any(AAIResourceUri.class))).thenReturn(Optional.of(pIf)); + + when(resourcesClient.exists(any(AAIResourceUri.class))).thenReturn(true); when(env.getProperty("mso.cloudOwner.included", "")).thenReturn("CloudOwner"); + doReturn(dSLQueryClient).when(heatbridge).getAAIDSLClient(); + List<Pathed> pathed = ((Results<Pathed>) MAPPER.readValue(getJson("pathed-sriov-pf.json"), + new TypeReference<Results<Pathed>>() {})).getResult(); + when(dSLQueryClient.queryPathed(any(DSLQuery.class))).thenReturn(pathed); + doReturn(false).when(heatbridge).sriovVfHasSriovPfRelationship(any()); // Act heatbridge.buildAddVserverLInterfacesToAaiAction(stackResources, Arrays.asList("1", "2"), "CloudOwner"); @@ -396,6 +413,7 @@ public class HeatBridgeImplTest { verify(osClient, times(5)).getPortById(anyString()); verify(osClient, times(5)).getSubnetById("testSubnetId"); verify(osClient, times(10)).getNetworkById(anyString()); + verify(transaction, times(5)).connect(any(AAIResourceUri.class), any(AAIResourceUri.class)); } @Test @@ -463,6 +481,63 @@ public class HeatBridgeImplTest { } @Test + public void testUpdateLInterfaceVlan() throws HeatBridgeException { + // Arrange + List<Resource> stackResources = (List<Resource>) extractTestStackResources(); + Port port = mock(Port.class); + when(port.getId()).thenReturn("test-port-id"); + when(port.getName()).thenReturn("test-port-name"); + when(port.getvNicType()).thenReturn(HeatBridgeConstants.OS_SRIOV_PORT_TYPE); + when(port.getMacAddress()).thenReturn("78:4f:43:68:e2:78"); + when(port.getNetworkId()).thenReturn("890a203a-23gg-56jh-df67-731656a8f13a"); + when(port.getDeviceId()).thenReturn("test-device-id"); + + LInterface lIf = new LInterface(); + lIf.setInterfaceId("test-port-id"); + lIf.setInterfaceType("SRIOV"); + lIf.setInterfaceName("name"); + + String pfPciId = "0000:08:00.0"; + when(port.getProfile()).thenReturn(ImmutableMap.of(HeatBridgeConstants.OS_PCI_SLOT_KEY, pfPciId, + HeatBridgeConstants.OS_PHYSICAL_NETWORK_KEY, "physical_network_id")); + + IP ip = mock(IP.class); + + Set<IP> ipSet = new HashSet<>(); + ipSet.add(ip); + when(ip.getIpAddress()).thenReturn("2606:ae00:2e60:100::226"); + when(ip.getSubnetId()).thenReturn("testSubnetId"); + when(port.getFixedIps()).thenAnswer(x -> ipSet); + + Subnet subnet = mock(Subnet.class); + when(subnet.getCidr()).thenReturn("169.254.100.0/24"); + when(osClient.getSubnetById("testSubnetId")).thenReturn(subnet); + + Network network = mock(Network.class); + when(network.getId()).thenReturn("test-network-id"); + when(network.getNetworkType()).thenReturn(NetworkType.VLAN); + when(network.getProviderSegID()).thenReturn("2345"); + when(network.getProviderPhyNet()).thenReturn("ovsnet"); + doNothing().when(heatbridge).processOVS(any(), any(), any()); + + when(osClient.getNetworkById(anyString())).thenReturn(network); + + SriovPf sriovPf = new SriovPf(); + sriovPf.setPfPciId(pfPciId); + PInterface pIf = mock(PInterface.class); + when(pIf.getInterfaceName()).thenReturn("test-port-id"); + when(resourcesClient.get(eq(PInterface.class), any(AAIResourceUri.class))).thenReturn(Optional.of(pIf)); + + // Act + heatbridge.updateLInterfaceVlan(port, lIf, "hostname"); + + // Assert + verify(transaction, times(2)).createIfNotExists(any(AAIResourceUri.class), any(Optional.class)); + verify(osClient, times(1)).getNetworkById(anyString()); + verify(heatbridge, times(0)).processOVS(any(), any(), any()); + } + + @Test public void testUpdateLInterfaceIps() throws HeatBridgeException, JsonParseException, JsonMappingException, IOException { @@ -511,7 +586,8 @@ public class HeatBridgeImplTest { } @Test - public void testUpdateVserverLInterfacesToAai_skipVlans() throws HeatBridgeException { + public void testUpdateVserverLInterfacesToAai_skipVlans() + throws HeatBridgeException, JsonParseException, JsonMappingException, IOException { // Arrange List<Resource> stackResources = (List<Resource>) extractTestStackResources(); Port port = mock(Port.class); @@ -537,11 +613,9 @@ public class HeatBridgeImplTest { when(osClient.getPortById("c54b9f45-b413-4937-bbe4-3c8a5689cfc9")).thenReturn(port); when(osClient.getNetworkById(anyString())).thenReturn(network); - SriovPf sriovPf = new SriovPf(); - sriovPf.setPfPciId(pfPciId); PInterface pIf = mock(PInterface.class); when(pIf.getInterfaceName()).thenReturn("test-port-id"); - when(resourcesClient.get(eq(PInterface.class), any(AAIResourceUri.class))).thenReturn(Optional.of(pIf)); + doNothing().when(heatbridge).updateSriovPfToPserver(any(), any()); // Act heatbridge.buildAddVserverLInterfacesToAaiAction(stackResources, Arrays.asList("1", "2"), "CloudOwner"); @@ -576,5 +650,9 @@ public class HeatBridgeImplTest { return content; } + private String getJson(String filename) throws IOException { + return new String(Files.readAllBytes(Paths.get("src/test/resources/__files/" + filename))); + } + } diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/heatbridge/utils/HeatBridgeUtilsTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/heatbridge/utils/HeatBridgeUtilsTest.java index bbc99bd258..13a8cb21e7 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/heatbridge/utils/HeatBridgeUtilsTest.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/heatbridge/utils/HeatBridgeUtilsTest.java @@ -26,6 +26,6 @@ public class HeatBridgeUtilsTest { @Test public void matchServerName_unknown() { Optional<String> serverName = HeatBridgeUtils.getMatchingPserverPifName("differentServerName"); - assertThat(serverName).isEmpty(); + assertThat(serverName).isNotEmpty().hasValue("differentServerName"); } } diff --git a/adapters/mso-openstack-adapters/src/test/resources/__files/pathed-sriov-pf.json b/adapters/mso-openstack-adapters/src/test/resources/__files/pathed-sriov-pf.json new file mode 100644 index 0000000000..cccad4c6d3 --- /dev/null +++ b/adapters/mso-openstack-adapters/src/test/resources/__files/pathed-sriov-pf.json @@ -0,0 +1,8 @@ +{ + "results" : [ + { + "resource-type" : "sriov-pf", + "resource-link" : "/cloud-infrastructure/pservers/pserver/id1/p-interfaces/p-interface/id2/sriov-pfs/sriov-pf/id3" + } + ] +}
\ No newline at end of file |