Changed to use the physical network name 28/113328/1
authorBoslet, Cory <cory.boslet@att.com>
Tue, 29 Sep 2020 15:32:57 +0000 (11:32 -0400)
committerBenjamin, Max (mb388a) <mb388a@att.com>
Tue, 29 Sep 2020 15:32:58 +0000 (11:32 -0400)
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) <mb388a@att.com>
Change-Id: I34c0d5978c914260ca6300948a697c0c7ab7fdfa

adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/HeatBridgeImpl.java
adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/utils/HeatBridgeUtils.java
adapters/mso-openstack-adapters/src/test/java/org/onap/so/heatbridge/utils/HeatBridgeUtilsTest.java

index 90a578d..3aa742a 100644 (file)
@@ -597,33 +597,29 @@ public class HeatBridgeImpl implements HeatBridgeApi {
                 lIf.setInterfaceDescription(
                         "Attached to SR-IOV port: " + pserverHostName + "::" + matchingPifName.get());
                 try {
-                    Optional<PInterface> 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<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
+                        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
index 1667f98..c281dbd 100644 (file)
@@ -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) {
index bbc99bd..13a8cb2 100644 (file)
@@ -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");
     }
 }