diff options
author | Boslet, Cory <cory.boslet@att.com> | 2020-07-07 11:49:48 -0400 |
---|---|---|
committer | Benjamin, Max (mb388a) <mb388a@att.com> | 2020-07-10 15:46:33 -0400 |
commit | 179127791b4aee4ceb266062f30ea3cea5ccc31f (patch) | |
tree | 53b47288e034527e86970dc640973e581ba94a21 | |
parent | 72eaef0f8559c9fa16cca0d4808b45bcfc7cff8f (diff) |
Began fixing issues with heat bridge
Began fixing issues with heat bridge WIP.
Removed duplicate method call from heat bridge
Added to populate ipv4 prefix lendth with subnet prefix
Fixed remaining issues with heat bridge code.
Change sriov pf to be sriov vf in aai object.
Issue-ID: SO-3035
Signed-off-by: Benjamin, Max (mb388a) <mb388a@att.com>
Change-Id: I05de776126b2442268d98d87176855f1080109bd
7 files changed, 91 insertions, 57 deletions
diff --git a/adapters/mso-openstack-adapters/pom.xml b/adapters/mso-openstack-adapters/pom.xml index 893f50c458..d78178f5ba 100644 --- a/adapters/mso-openstack-adapters/pom.xml +++ b/adapters/mso-openstack-adapters/pom.xml @@ -353,5 +353,10 @@ <artifactId>camunda-external-task-client</artifactId> <version>1.1.1</version> </dependency> + <dependency> + <groupId>com.github.seancfoley</groupId> + <artifactId>ipaddress</artifactId> + <version>2.0.0</version> + </dependency> </dependencies> </project> 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 f37555392a..3224f4b4f1 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 @@ -86,12 +86,14 @@ import org.openstack4j.model.network.IP; 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.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.core.env.Environment; import com.google.common.base.Preconditions; import com.google.common.base.Strings; import com.google.common.collect.ImmutableMap; +import inet.ipaddr.IPAddressString; /** * This class provides an implementation of {@link HeatBridgeApi} @@ -266,13 +268,12 @@ public class HeatBridgeImpl implements HeatBridgeApi { extractStackResourceIdsByResourceType(stackResources, HeatBridgeConstants.OS_PORT_RESOURCE_TYPE); for (String portId : portIds) { Port port = osClient.getPortById(portId); + Network network = osClient.getNetworkById(port.getNetworkId()); LInterface lIf = new LInterface(); lIf.setInterfaceId(port.getId()); lIf.setInterfaceName(port.getName()); lIf.setMacaddr(port.getMacAddress()); - if (port.getProfile() != null && port.getProfile().get("physical_network") != null) { - lIf.setNetworkName((String) port.getProfile().get("physical_network")); - } + lIf.setNetworkName(network.getName()); lIf.setIsPortMirrored(false); lIf.setIsIpUnnumbered(false); lIf.setInMaint(false); @@ -297,6 +298,8 @@ public class HeatBridgeImpl implements HeatBridgeApi { // Update l-interface to the vserver transaction.create(AAIUriFactory.createResourceUri(AAIObjectType.L_INTERFACE, cloudOwner, cloudRegionId, tenantId, port.getDeviceId(), lIf.getInterfaceName()), lIf); + + updateSriovPfToPserver(port, lIf); } } @@ -350,8 +353,7 @@ public class HeatBridgeImpl implements HeatBridgeApi { Vlan vlan = new Vlan(); Network network = osClient.getNetworkById(port.getNetworkId()); if (network.getNetworkType() != null && network.getNetworkType().equals(NetworkType.VLAN)) { - vlan.setVlanInterface(network.getName() + network.getProviderSegID()); - + vlan.setVlanInterface(port.getName() + network.getProviderSegID()); vlan.setVlanIdOuter(Long.parseLong(network.getProviderSegID())); vlan.setVlanIdInner(0L); vlan.setInMaint(false); @@ -371,17 +373,12 @@ public class HeatBridgeImpl implements HeatBridgeApi { SriovVf sriovVf = new SriovVf(); sriovVf.setPciId(port.getProfile().get(HeatBridgeConstants.OS_PCI_SLOT_KEY).toString()); sriovVf.setNeutronNetworkId(port.getNetworkId()); - if (port.getVifDetails() != null) { - sriovVf.setVfVlanFilter((String) port.getVifDetails().get(HeatBridgeConstants.OS_VLAN_NETWORK_KEY)); - } + sriovVf.setVfVlanFilter("0"); sriovVf.setVfVlanAntiSpoofCheck(false); sriovVf.setVfMacAntiSpoofCheck(false); sriovVfList.add(sriovVf); lIf.setSriovVfs(sriovVfs); - - // For the given port create sriov-pf for host pserver/p-interface if absent - updateSriovPfToPserver(port, lIf); } } @@ -395,48 +392,59 @@ public class HeatBridgeImpl implements HeatBridgeApi { * @param lIf AAI l-interface object */ private void updateSriovPfToPserver(final Port port, final LInterface lIf) { - 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(AAIObjectType.P_INTERFACE, pserverHostName, 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()); - transaction.create(AAIUriFactory.createResourceUri(AAIObjectType.SRIOV_PF, pserverHostName, - matchingPifName.get(), sriovPf.getPfPciId()), sriovPf); + 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(AAIObjectType.P_INTERFACE, pserverHostName, 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(AAIObjectType.SRIOV_PF, + pserverHostName, matchingPifName.get(), sriovPf.getPfPciId()); + + transaction.create(sriovPfUri, sriovPf); + + AAIResourceUri sriovVfUri = AAIUriFactory.createResourceUri(AAIObjectType.SRIOV_VF, + cloudOwner, cloudRegionId, tenantId, port.getDeviceId(), lIf.getInterfaceName(), + port.getProfile().get(HeatBridgeConstants.OS_PCI_SLOT_KEY).toString()); + + transaction.connect(sriovPfUri, sriovVfUri); + } } + } 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); } - } 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); } } } @@ -446,11 +454,13 @@ public class HeatBridgeImpl implements HeatBridgeApi { for (IP ip : port.getFixedIps()) { String ipAddress = ip.getIpAddress(); if (InetAddressValidator.getInstance().isValidInet4Address(ipAddress)) { + Subnet subnet = osClient.getSubnetById(ip.getSubnetId()); + IPAddressString cidr = new IPAddressString(subnet.getCidr()); L3InterfaceIpv4AddressList lInterfaceIp = new L3InterfaceIpv4AddressList(); lInterfaceIp.setL3InterfaceIpv4Address(ipAddress); lInterfaceIp.setNeutronNetworkId(port.getNetworkId()); lInterfaceIp.setNeutronSubnetId(ip.getSubnetId()); - lInterfaceIp.setL3InterfaceIpv4PrefixLength(32L); + lInterfaceIp.setL3InterfaceIpv4PrefixLength(Long.parseLong(cidr.getNetworkPrefixLength().toString())); lInterfaceIps.add(lInterfaceIp); } } diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/helpers/AaiHelper.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/helpers/AaiHelper.java index 6817be8c49..c4d9cbe871 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/helpers/AaiHelper.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/helpers/AaiHelper.java @@ -145,7 +145,6 @@ public class AaiHelper { vserver.setVserverId(serverId); vserver.setVserverName(server.getName()); vserver.setVserverName2(server.getName()); - vserver.setProvStatus(server.getStatus().value()); server.getLinks().stream().filter(link -> link.getRel().equals(HeatBridgeConstants.OS_RESOURCES_SELF_LINK_KEY)) .findFirst().ifPresent(link -> vserver.setVserverSelflink(link.getHref())); return vserver; diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/openstack/api/OpenstackClient.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/openstack/api/OpenstackClient.java index 7184ec1e93..8d47ff4ceb 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/openstack/api/OpenstackClient.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/openstack/api/OpenstackClient.java @@ -42,6 +42,7 @@ import org.openstack4j.model.compute.Server; import org.openstack4j.model.heat.Resource; import org.openstack4j.model.network.Network; import org.openstack4j.model.network.Port; +import org.openstack4j.model.network.Subnet; public interface OpenstackClient { @@ -92,4 +93,12 @@ public interface OpenstackClient { * @return List of filtered Network objects */ List<Network> listNetworksByFilter(Map<String, String> filterParams); + + /** + * Get a subnet object by subnet ID + * + * @param subnetId Unique UUID of the subnet. + * @return Subnet object. + */ + Subnet getSubnetById(String subnetId); } diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/openstack/api/OpenstackClientImpl.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/openstack/api/OpenstackClientImpl.java index 5a2b0732dc..1505203d7c 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/openstack/api/OpenstackClientImpl.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/openstack/api/OpenstackClientImpl.java @@ -45,6 +45,7 @@ import org.openstack4j.model.compute.Server; import org.openstack4j.model.heat.Resource; import org.openstack4j.model.network.Network; import org.openstack4j.model.network.Port; +import org.openstack4j.model.network.Subnet; abstract class OpenstackClientImpl implements OpenstackClient { @Override @@ -78,6 +79,11 @@ abstract class OpenstackClientImpl implements OpenstackClient { return (List<Network>) getClient().networking().network().list(filterParams); } + @Override + public Subnet getSubnetById(String subnetId) { + return getClient().networking().subnet().get(subnetId); + } + /** * Retrieves the specific client to utilize. * 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 de40f1e6ba..091edefe5a 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 @@ -49,9 +49,11 @@ import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.HashSet; import java.util.List; import java.util.Objects; import java.util.Optional; +import java.util.Set; import org.apache.commons.io.FileUtils; import org.junit.Assert; import org.junit.Before; @@ -83,6 +85,7 @@ import org.openstack4j.model.compute.Image; 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.Network; import org.openstack4j.model.network.NetworkType; import org.openstack4j.model.network.Port; @@ -415,7 +418,6 @@ public class HeatBridgeImplTest { 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"); - when(port.getVifDetails()).thenReturn(ImmutableMap.of(HeatBridgeConstants.OS_VLAN_NETWORK_KEY, "2345")); 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")); @@ -445,7 +447,7 @@ public class HeatBridgeImplTest { // Assert verify(transaction, times(5)).create(any(AAIResourceUri.class), any(LInterface.class)); verify(osClient, times(5)).getPortById(anyString()); - verify(osClient, times(5)).getNetworkById(anyString()); + verify(osClient, times(10)).getNetworkById(anyString()); } @Test @@ -459,7 +461,6 @@ public class HeatBridgeImplTest { 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"); - when(port.getVifDetails()).thenReturn(ImmutableMap.of(HeatBridgeConstants.OS_VLAN_NETWORK_KEY, "2345")); 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")); @@ -474,6 +475,7 @@ public class HeatBridgeImplTest { when(osClient.getPortById("70a09dfd-f1c5-4bc8-bd8f-dc539b8d662a")).thenReturn(port); when(osClient.getPortById("12f88b4d-c8a4-4fbd-bcb4-7e36af02430b")).thenReturn(port); when(osClient.getPortById("c54b9f45-b413-4937-bbe4-3c8a5689cfc9")).thenReturn(port); + when(osClient.getNetworkById(anyString())).thenReturn(network); SriovPf sriovPf = new SriovPf(); sriovPf.setPfPciId(pfPciId); @@ -487,7 +489,7 @@ public class HeatBridgeImplTest { // Assert verify(transaction, times(5)).create(any(AAIResourceUri.class), any(LInterface.class)); verify(osClient, times(5)).getPortById(anyString()); - verify(osClient, times(0)).getNetworkById(anyString()); + verify(osClient, times(5)).getNetworkById(anyString()); } private List<? extends Resource> extractTestStackResources() { diff --git a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/AAIObjectType.java b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/AAIObjectType.java index b3402fa221..2335a48d43 100644 --- a/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/AAIObjectType.java +++ b/graph-inventory/aai-client/src/main/java/org/onap/aaiclient/client/aai/AAIObjectType.java @@ -63,6 +63,7 @@ import org.onap.aai.domain.yang.ServiceSubscription; import org.onap.aai.domain.yang.SliceProfile; import org.onap.aai.domain.yang.SpPartner; import org.onap.aai.domain.yang.SriovPf; +import org.onap.aai.domain.yang.SriovVf; import org.onap.aai.domain.yang.Subnet; import org.onap.aai.domain.yang.Tenant; import org.onap.aai.domain.yang.TunnelXconnect; @@ -184,6 +185,8 @@ public class AAIObjectType implements AAIObjectBase, GraphInventoryObjectType, S new AAIObjectType(AAINamespaceConstants.NETWORK, AggregateRoute.class); public static final AAIObjectType L_INTERFACE = new AAIObjectType(AAIObjectType.VSERVER.uriTemplate(), LInterface.class); + public static final AAIObjectType SRIOV_VF = + new AAIObjectType(AAIObjectType.L_INTERFACE.uriTemplate(), SriovVf.class); public static final AAIObjectType SUB_L_INTERFACE = new AAIObjectType(AAIObjectType.L_INTERFACE.uriTemplate(), "/l-interfaces/l-interface/{sub-interface-name}", "sub-l-interface"); public static final AAIObjectType IMAGE = new AAIObjectType(AAIObjectType.CLOUD_REGION.uriTemplate(), Image.class); |