summaryrefslogtreecommitdiffstats
path: root/adapters/mso-openstack-adapters
diff options
context:
space:
mode:
authorSteve Smokowski <ss835w@att.com>2020-10-21 19:04:01 +0000
committerGerrit Code Review <gerrit@onap.org>2020-10-21 19:04:01 +0000
commitc3cb2537fe0e4d6bd23dd77a4369705a76e6930a (patch)
treec92c726507a76cc1333956658e30dca78408bbe9 /adapters/mso-openstack-adapters
parenteb00f2d1bbc80fb858f15a565a54fa8336c6650d (diff)
parentb60470ebdd206c190c7ca29d294670ec5f9744b4 (diff)
Merge "Update code to filter null or empty images"
Diffstat (limited to 'adapters/mso-openstack-adapters')
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/HeatBridgeImpl.java2
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/heatbridge/HeatBridgeImplTest.java30
2 files changed, 31 insertions, 1 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 6a62a5de61..45b29244d1 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
@@ -245,7 +245,7 @@ public class HeatBridgeImpl implements HeatBridgeApi {
@Override
public List<org.openstack4j.model.compute.Image> extractOpenstackImagesFromServers(final List<Server> servers) {
Objects.requireNonNull(osClient, ERR_MSG_NULL_OS_CLIENT);
- return servers.stream().map(Server::getImage)
+ return servers.stream().filter(s -> s.getImage() != null).map(Server::getImage)
.filter(distinctByProperty(org.openstack4j.model.compute.Image::getId)).collect(Collectors.toList());
}
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 531496cc8f..ebc7c3a81e 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
@@ -102,6 +102,8 @@ import org.openstack4j.model.network.Port;
import org.openstack4j.model.network.Subnet;
import org.openstack4j.openstack.heat.domain.HeatResource;
import org.openstack4j.openstack.heat.domain.HeatResource.Resources;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.core.env.Environment;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.type.TypeReference;
@@ -118,6 +120,8 @@ public class HeatBridgeImplTest {
private static final String TENANT_ID = "7320ec4a5b9d4589ba7c4412ccfd290f";
private static final ObjectMapper MAPPER = new ObjectMapper();
+ private static Logger logger = LoggerFactory.getLogger(HeatBridgeImplTest.class);
+
@Mock
private OpenstackClient osClient;
@@ -139,6 +143,12 @@ public class HeatBridgeImplTest {
private Server server;
@Mock
+ private Server server2;
+
+ @Mock
+ private Image image;
+
+ @Mock
private AAIDSLQueryClient dSLQueryClient;
@Spy
@@ -626,6 +636,25 @@ public class HeatBridgeImplTest {
verify(osClient, times(5)).getNetworkById(anyString());
}
+
+ @Test
+ public void testExtractOpenstackImagesFromServers() throws HeatBridgeException {
+ // Arrange
+ List<Server> serverList = new ArrayList<>();
+ serverList.add(server);
+ serverList.add(server2);
+ when(server.getImage()).thenReturn(null);
+ when(server.getImage()).thenReturn(image);
+ when(image.getId()).thenReturn("imageId");
+ // Act
+
+ List<Image> images = heatbridge.extractOpenstackImagesFromServers(serverList);
+
+
+ // Assert
+ assertEquals(1, images.size());
+ }
+
private List<? extends Resource> extractTestStackResources() {
List<HeatResource> stackResources = null;
try {
@@ -638,6 +667,7 @@ public class HeatBridgeImplTest {
return stackResources;
}
+
private String readTestResourceFile(String filePath) {
String content = null;
String pathname = Objects.requireNonNull(getClass().getClassLoader().getResource(filePath)).getFile();