aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMnushkin, Dmitry <dmitry.mnushkin@att.com>2020-05-16 12:11:13 -0400
committerMnushkin, Dmitry (dm4252) <dm4252@att.com>2020-05-19 14:27:55 -0500
commit4ae7c5e7af5a4b91f7586e8244359430607da3b3 (patch)
tree3b08e122c965fab1fd0644cf983c65d83572b1e3
parent66e51a92e185963b1c50ad82d44ee974d2db5197 (diff)
add null check for server HostName/Name/Flavor
add null check for server HostName/Name/Flavor maven format file after build failure include relationship empty string verification add unit test to verify null/empty string update empty string validation code Issue-ID: SO-2912 Signed-off-by: Benjamin, Max (mb388a) <mb388a@att.com> Change-Id: If308469cd4ec0008a6d1a480641da890d67b4259 Signed-off-by: Mnushkin, Dmitry (dm4252) <dm4252@att.com>
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/helpers/AaiHelper.java24
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/heatbridge/HeatBridgeImplTest.java74
2 files changed, 86 insertions, 12 deletions
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 727cdccff5..f18279d5d3 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
@@ -41,6 +41,7 @@ import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
import org.onap.aai.domain.yang.Flavor;
import org.onap.aai.domain.yang.Image;
import org.onap.aai.domain.yang.PInterface;
@@ -75,11 +76,12 @@ public class AaiHelper {
List<Relationship> relationships = relationshipList.getRelationship();
// vserver to pserver relationship
- Relationship pserverRelationship =
- buildRelationship(HeatBridgeConstants.AAI_PSERVER, ImmutableMap.<String, String>builder()
- .put(HeatBridgeConstants.AAI_PSERVER_HOSTNAME, server.getHypervisorHostname()).build());
- relationships.add(pserverRelationship);
-
+ if (!StringUtils.isEmpty(server.getHypervisorHostname())) {
+ Relationship pserverRelationship =
+ buildRelationship(HeatBridgeConstants.AAI_PSERVER, ImmutableMap.<String, String>builder()
+ .put(HeatBridgeConstants.AAI_PSERVER_HOSTNAME, server.getHypervisorHostname()).build());
+ relationships.add(pserverRelationship);
+ }
// vserver to vf-module relationship
Relationship vfModuleRelationship = buildRelationship(HeatBridgeConstants.AAI_VF_MODULE,
ImmutableMap.<String, String>builder().put(HeatBridgeConstants.AAI_GENERIC_VNF_ID, genericVnfId)
@@ -96,11 +98,13 @@ public class AaiHelper {
}
// vserver to flavor relationship
- Relationship flavorRel = buildRelationship(HeatBridgeConstants.AAI_FLAVOR,
- ImmutableMap.<String, String>builder().put(HeatBridgeConstants.AAI_CLOUD_OWNER, cloudOwner)
- .put(HeatBridgeConstants.AAI_CLOUD_REGION_ID, cloudRegionId)
- .put(HeatBridgeConstants.AAI_FLAVOR_ID, server.getFlavor().getId()).build());
- relationships.add(flavorRel);
+ if (server.getFlavor() != null) {
+ Relationship flavorRel = buildRelationship(HeatBridgeConstants.AAI_FLAVOR,
+ ImmutableMap.<String, String>builder().put(HeatBridgeConstants.AAI_CLOUD_OWNER, cloudOwner)
+ .put(HeatBridgeConstants.AAI_CLOUD_REGION_ID, cloudRegionId)
+ .put(HeatBridgeConstants.AAI_FLAVOR_ID, server.getFlavor().getId()).build());
+ relationships.add(flavorRel);
+ }
return relationshipList;
}
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 e2f5531280..988e78b9a3 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
@@ -72,6 +72,7 @@ import org.onap.so.client.aai.entities.uri.AAIUriFactory;
import org.onap.so.client.graphinventory.exceptions.BulkProcessFailed;
import org.onap.so.db.catalog.beans.CloudIdentity;
import org.onap.so.heatbridge.constants.HeatBridgeConstants;
+import org.onap.so.heatbridge.helpers.AaiHelper;
import org.onap.so.heatbridge.openstack.api.OpenstackClient;
import org.onap.so.heatbridge.openstack.api.OpenstackClientException;
import org.openstack4j.model.compute.Flavor;
@@ -87,7 +88,6 @@ import org.openstack4j.openstack.heat.domain.HeatResource.Resources;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableMap;
-
@RunWith(MockitoJUnitRunner.class)
public class HeatBridgeImplTest {
@@ -228,7 +228,7 @@ public class HeatBridgeImplTest {
Server server2 = mock(Server.class);
when(server2.getId()).thenReturn("test-server2-id");
- when(server2.getHypervisorHostname()).thenReturn("test-hypervisor");
+ when(server2.getHypervisorHostname()).thenReturn("");
when(server2.getName()).thenReturn("test-server2-name");
when(server2.getStatus()).thenReturn(Status.ACTIVE);
when(server2.getLinks()).thenReturn(new ArrayList<>());
@@ -245,6 +245,49 @@ public class HeatBridgeImplTest {
when(server2.getFlavor()).thenReturn(flavor);
when(flavor.getId()).thenReturn("test-flavor-id");
+ // Act
+ heatbridge.buildAddVserversToAaiAction("test-genericVnf-id", "test-vfModule-id", servers);
+
+ // Assert
+ ArgumentCaptor<AAIResourceUri> captor = ArgumentCaptor.forClass(AAIResourceUri.class);
+ verify(transaction, times(2)).create(captor.capture(), any(Vserver.class));
+
+ List<AAIResourceUri> uris = captor.getAllValues();
+ assertEquals(AAIUriFactory.createResourceUri(AAIObjectType.VSERVER, CLOUD_OWNER, REGION_ID, TENANT_ID,
+ server1.getId()), uris.get(0));
+ assertEquals(AAIUriFactory.createResourceUri(AAIObjectType.VSERVER, CLOUD_OWNER, REGION_ID, TENANT_ID,
+ server2.getId()), uris.get(1));
+
+ }
+
+ @Test
+ public void testUpdateVserversToAaiNoHypervisorName() throws HeatBridgeException {
+ // Arrange
+ Server server1 = mock(Server.class);
+
+ when(server1.getId()).thenReturn("test-server1-id");
+ when(server1.getHypervisorHostname()).thenReturn("");
+ when(server1.getName()).thenReturn("test-server1-name");
+ when(server1.getStatus()).thenReturn(Status.ACTIVE);
+ when(server1.getLinks()).thenReturn(new ArrayList<>());
+
+ Server server2 = mock(Server.class);
+ when(server2.getId()).thenReturn("test-server2-id");
+ when(server2.getName()).thenReturn("test-server2-name");
+ when(server2.getStatus()).thenReturn(Status.ACTIVE);
+ when(server2.getLinks()).thenReturn(new ArrayList<>());
+
+ List<Server> servers = Arrays.asList(server1, server2);
+
+ Image image = mock(Image.class);
+ when(server1.getImage()).thenReturn(image);
+ when(server2.getImage()).thenReturn(image);
+ when(image.getId()).thenReturn("test-image-id");
+
+ Flavor flavor = mock(Flavor.class);
+ when(server1.getFlavor()).thenReturn(flavor);
+ when(server2.getFlavor()).thenReturn(flavor);
+ when(flavor.getId()).thenReturn("test-flavor-id");
// Act
heatbridge.buildAddVserversToAaiAction("test-genericVnf-id", "test-vfModule-id", servers);
@@ -258,7 +301,34 @@ public class HeatBridgeImplTest {
server1.getId()), uris.get(0));
assertEquals(AAIUriFactory.createResourceUri(AAIObjectType.VSERVER, CLOUD_OWNER, REGION_ID, TENANT_ID,
server2.getId()), uris.get(1));
+ }
+
+ @Test
+ public void testCreateRelationships() throws HeatBridgeException {
+ AaiHelper aaiHelper = new AaiHelper();
+ // Arrange
+ Server server1 = mock(Server.class);
+
+ when(server1.getHypervisorHostname()).thenReturn("test-hypervisor");
+
+ // HypervisorHostname is not set
+ Server server2 = mock(Server.class);
+
+ // HypervisorHostname is empty string
+ Server server3 = mock(Server.class);
+ when(server3.getHypervisorHostname()).thenReturn("");
+
+ org.onap.aai.domain.yang.RelationshipList relList = aaiHelper.getVserverRelationshipList(CLOUD_OWNER, REGION_ID,
+ "test-genericVnf-id", "test-vfModule-id", server1);
+ assertEquals(2, relList.getRelationship().size());
+
+ org.onap.aai.domain.yang.RelationshipList relList2 = aaiHelper.getVserverRelationshipList(CLOUD_OWNER,
+ REGION_ID, "test-genericVnf-id", "test-vfModule-id", server2);
+ assertEquals(1, relList2.getRelationship().size());
+ org.onap.aai.domain.yang.RelationshipList relList3 = aaiHelper.getVserverRelationshipList(CLOUD_OWNER,
+ REGION_ID, "test-genericVnf-id", "test-vfModule-id", server3);
+ assertEquals(1, relList3.getRelationship().size());
}
@Test