From e39c6bfda15fce56cf6ddf037a19f4b3b0618900 Mon Sep 17 00:00:00 2001 From: "Boslet, Cory" Date: Tue, 29 Sep 2020 11:32:57 -0400 Subject: [PATCH] Changed to use the physical network name Changed to use the physical network name and refactor/fixes WIP Fixed the failing junit test as a result of change Issue-ID: SO-3278 Signed-off-by: Benjamin, Max (mb388a) Change-Id: I34c0d5978c914260ca6300948a697c0c7ab7fdfa --- .../org/onap/so/heatbridge/HeatBridgeImpl.java | 30 +++++++++++----------- .../onap/so/heatbridge/utils/HeatBridgeUtils.java | 4 +-- .../so/heatbridge/utils/HeatBridgeUtilsTest.java | 2 +- 3 files changed, 18 insertions(+), 18 deletions(-) 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..3aa742a3e3 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 @@ -597,33 +597,29 @@ public class HeatBridgeImpl implements HeatBridgeApi { lIf.setInterfaceDescription( "Attached to SR-IOV port: " + pserverHostName + "::" + matchingPifName.get()); try { - Optional matchingPIf = resourcesClient.get(PInterface.class, + AAIResourceUri pInterfaceUri = 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 + .depth(Depth.ONE); + if (resourcesClient.exists(pInterfaceUri)) { + PInterface matchingPIf = resourcesClient.get(PInterface.class, pInterfaceUri).get(); + String pfPciId = port.getProfile().get(HeatBridgeConstants.OS_PCI_SLOT_KEY).toString(); - List existingSriovPfs = pIfSriovPfs.getSriovPf(); - if (CollectionUtils.isEmpty(existingSriovPfs) || existingSriovPfs.stream() - .noneMatch(existingSriovPf -> existingSriovPf.getPfPciId().equals(pfPciId))) { - // Add sriov-pf object with PCI-ID to AAI + if (matchingPIf.getSriovPfs() == null + || CollectionUtils.isEmpty(matchingPIf.getSriovPfs().getSriovPf()) + || matchingPIf.getSriovPfs().getSriovPf().stream() + .noneMatch(existingSriovPf -> existingSriovPf.getPfPciId().equals(pfPciId))) { + 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())); - + // TODO if it does exist, should check if relationship is there, if not then create? if (!resourcesClient.exists(sriovPfUri)) { transaction.create(sriovPfUri, sriovPf); @@ -634,6 +630,10 @@ public class HeatBridgeImpl implements HeatBridgeApi { transaction.connect(sriovPfUri, sriovVfUri); } } + } else { + logger.warn( + "PInterface {} does not exist in AAI. Unable to build sriov-vf to sriov-pf relationship.", + matchingPifName.get()); } } catch (WebApplicationException e) { // Silently log that we failed to update the Pserver p-interface with PCI-ID 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 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 extractPciIdsFromVServer(Vserver vserver) { 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 serverName = HeatBridgeUtils.getMatchingPserverPifName("differentServerName"); - assertThat(serverName).isEmpty(); + assertThat(serverName).isNotEmpty().hasValue("differentServerName"); } } -- 2.16.6