summaryrefslogtreecommitdiffstats
path: root/adapters
diff options
context:
space:
mode:
Diffstat (limited to 'adapters')
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java21
-rw-r--r--adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatUtilsTest.java16
-rw-r--r--adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/client/RequestsDbClientTest.java46
3 files changed, 51 insertions, 32 deletions
diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java
index 7174bc0e31..28d4f3f9b4 100644
--- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java
+++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java
@@ -31,8 +31,8 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
+import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import java.util.stream.Collectors;
import org.onap.logging.ref.slf4j.ONAPLogConstants;
import org.onap.so.adapters.vdu.CloudInfo;
import org.onap.so.adapters.vdu.PluginAction;
@@ -79,7 +79,6 @@ import com.woorea.openstack.base.client.OpenStackResponseException;
import com.woorea.openstack.heat.Heat;
import com.woorea.openstack.heat.model.CreateStackParam;
import com.woorea.openstack.heat.model.Events;
-import com.woorea.openstack.heat.model.Resource;
import com.woorea.openstack.heat.model.Resources;
import com.woorea.openstack.heat.model.Stack;
import com.woorea.openstack.heat.model.Stack.Output;
@@ -405,17 +404,15 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin {
protected Stack handleKeyPairConflict(String cloudSiteId, String tenantId, CreateStackParam stackCreate,
int timeoutMinutes, boolean backout, Stack stack) throws MsoException {
logger.info("Keypair conflict found on stack, attempting to clean up");
-
- Resources resources = queryStackResources(cloudSiteId, tenantId, stackCreate.getStackName(), 2);
- List<Resource> keyPairs = resources.getList().stream()
- .filter(p -> "OS::Nova::KeyPair".equalsIgnoreCase(p.getType())).collect(Collectors.toList());
- keyPairs.stream().forEach(keyPair -> {
- try {
- novaClient.deleteKeyPair(cloudSiteId, tenantId, keyPair.getLogicalResourceId());
- } catch (MsoCloudSiteNotFound | NovaClientException e) {
- logger.warn("Could not delete keypair", e);
+ try {
+ Matcher m = Pattern.compile("'([^']+?)'").matcher(stack.getStackStatusReason());
+ if (m.find()) {
+ novaClient.deleteKeyPair(cloudSiteId, tenantId, m.group(1));
}
- });
+ } catch (NovaClientException e) {
+ logger.warn("Could not delete keypair", e);
+ }
+
handleUnknownCreateStackFailure(stack, timeoutMinutes, cloudSiteId, tenantId);
Stack newStack = createStack(stackCreate, cloudSiteId, tenantId);
newStack.setStackName(stackCreate.getStackName());
diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatUtilsTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatUtilsTest.java
index de55e85ad6..687b7d8d2f 100644
--- a/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatUtilsTest.java
+++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoHeatUtilsTest.java
@@ -33,9 +33,7 @@ import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.times;
import java.io.IOException;
-import java.util.ArrayList;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
import org.junit.Before;
import org.junit.Rule;
@@ -60,7 +58,6 @@ import com.woorea.openstack.heat.StackResource;
import com.woorea.openstack.heat.StackResource.CreateStack;
import com.woorea.openstack.heat.StackResource.DeleteStack;
import com.woorea.openstack.heat.model.CreateStackParam;
-import com.woorea.openstack.heat.model.Resource;
import com.woorea.openstack.heat.model.Resources;
import com.woorea.openstack.heat.model.Stack;
@@ -320,19 +317,9 @@ public class MsoHeatUtilsTest extends MsoHeatUtils {
createdStack.setStackStatus("CREATE_COMPLETE");
createdStack.setStackStatusReason("Stack Created");
-
-
- List<Resource> resources = new ArrayList<>();
- Resource resource = new Resource();
- resource.setName("KeypairName");
- resource.setLogicalResourceId("KeypairName");
- resource.setType("OS::Nova::KeyPair");
- resources.add(resource);
-
CreateStackParam createStackParam = new CreateStackParam();
createStackParam.setStackName("stackName");
- doReturn(resources).when(mockResources).getList();
doReturn(mockResources).when(heatUtils).queryStackResources(cloudSiteId, tenantId, "stackName", 2);
doNothing().when(novaClient).deleteKeyPair(cloudSiteId, tenantId, "KeypairName");
doReturn(null).when(heatUtils).handleUnknownCreateStackFailure(stack, 120, cloudSiteId, tenantId);
@@ -341,8 +328,7 @@ public class MsoHeatUtilsTest extends MsoHeatUtils {
createStackParam, false);
heatUtils.handleKeyPairConflict(cloudSiteId, tenantId, createStackParam, 120, true, stack);
- Mockito.verify(heatUtils, times(1)).queryStackResources(cloudSiteId, tenantId, "stackName", 2);
- Mockito.verify(novaClient, times(1)).deleteKeyPair(cloudSiteId, tenantId, "KeypairName");
+ Mockito.verify(novaClient, times(1)).deleteKeyPair(cloudSiteId, tenantId, "hst3bbfnm0011vm001");
Mockito.verify(heatUtils, times(1)).handleUnknownCreateStackFailure(stack, 120, cloudSiteId, tenantId);
Mockito.verify(heatUtils, times(1)).createStack(createStackParam, cloudSiteId, tenantId);
Mockito.verify(heatUtils, times(1)).processCreateStack(cloudSiteId, tenantId, 120, true, createdStack,
diff --git a/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/client/RequestsDbClientTest.java b/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/client/RequestsDbClientTest.java
index 711606cfa1..49291b6863 100644
--- a/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/client/RequestsDbClientTest.java
+++ b/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/client/RequestsDbClientTest.java
@@ -26,6 +26,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
+import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -33,9 +34,7 @@ import java.util.Map;
import java.util.UUID;
import org.junit.Before;
import org.junit.Test;
-import org.junit.runner.RunWith;
import org.onap.so.adapters.requestsdb.RequestsAdapterBase;
-import org.onap.so.adapters.requestsdb.application.MSORequestDBApplication;
import org.onap.so.db.request.beans.CloudApiRequests;
import org.onap.so.db.request.beans.InfraActiveRequests;
import org.onap.so.db.request.beans.OperationStatus;
@@ -43,10 +42,7 @@ import org.onap.so.db.request.beans.OperationalEnvDistributionStatus;
import org.onap.so.db.request.beans.OperationalEnvServiceModelStatus;
import org.onap.so.db.request.beans.RequestProcessingData;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.web.server.LocalServerPort;
-import org.springframework.test.context.ActiveProfiles;
-import org.springframework.test.context.junit4.SpringRunner;
public class RequestsDbClientTest extends RequestsAdapterBase {
@@ -86,6 +82,7 @@ public class RequestsDbClientTest extends RequestsAdapterBase {
infraActiveRequests.setRequestStatus("IN_PROGRESS");
infraActiveRequests.setAction("create");
infraActiveRequests.setRequestAction("someaction");
+ infraActiveRequests.setStartTime(new Timestamp(System.currentTimeMillis()));
infraActiveRequests
.setRequestUrl("http://localhost:8080/onap/so/infra/serviceInstantiation/v7/serviceInstances");
List<CloudApiRequests> cloudApiRequests = new ArrayList<>();
@@ -97,6 +94,34 @@ public class RequestsDbClientTest extends RequestsAdapterBase {
cloudApiRequests.add(cloudRequest);
infraActiveRequests.setCloudApiRequests(cloudApiRequests);
requestsDbClient.save(infraActiveRequests);
+
+ InfraActiveRequests infraActiveRequests2 = new InfraActiveRequests();
+ infraActiveRequests2.setRequestId(UUID.randomUUID().toString());
+ infraActiveRequests2.setOperationalEnvId(UUID.randomUUID().toString());
+ infraActiveRequests2.setServiceInstanceId(UUID.randomUUID().toString());
+ infraActiveRequests2.setServiceInstanceName("serviceInstanceNameTest");
+ infraActiveRequests2.setVnfId(UUID.randomUUID().toString());
+ infraActiveRequests2.setVnfName("vnfInstanceNameTest");
+ infraActiveRequests2.setVfModuleId(UUID.randomUUID().toString());
+ infraActiveRequests2.setVfModuleName("vfModuleInstanceNameTest");
+ infraActiveRequests2.setVolumeGroupId(UUID.randomUUID().toString());
+ infraActiveRequests2.setVolumeGroupName("volumeGroupInstanceNameTest");
+ infraActiveRequests2.setNetworkId(UUID.randomUUID().toString());
+ infraActiveRequests2.setNetworkName("networkInstanceNameTest");
+ infraActiveRequests2.setConfigurationId(UUID.randomUUID().toString());
+ infraActiveRequests2.setConfigurationName("configurationInstanceNameTest");
+ infraActiveRequests2.setAicCloudRegion("1");
+ infraActiveRequests2.setTenantId(UUID.randomUUID().toString());
+ infraActiveRequests2.setRequestScope("operationalEnvironment");
+ infraActiveRequests2.setRequestorId(UUID.randomUUID().toString());
+ infraActiveRequests2.setSource("sourceTest");
+ infraActiveRequests2.setOperationalEnvName(UUID.randomUUID().toString());
+ infraActiveRequests2.setRequestStatus("IN_PROGRESS");
+ infraActiveRequests2.setAction("create");
+ infraActiveRequests2.setRequestAction("someaction");
+ infraActiveRequests2.setStartTime(new Timestamp(System.currentTimeMillis()));
+ infraActiveRequests
+ .setRequestUrl("http://localhost:8080/onap/so/infra/serviceInstantiation/v7/serviceInstances");
}
private void verifyOperationStatus(OperationStatus request, OperationStatus response) {
@@ -278,4 +303,15 @@ public class RequestsDbClientTest extends RequestsAdapterBase {
assertNotNull(requestProcessingData);
}
+
+ @Test
+ public void getInfraActiveRequestbyRequestId_Filters_Test() {
+ Map<String, String[]> filters = new HashMap<>();
+ filters.put("requestStatus", new String[] {"EQ", "IN_PROGRESS"});
+ filters.put("action", new String[] {"EQ", "create"});
+ filters.put("serviceInstanceId", new String[] {"EQ", infraActiveRequests.getServiceInstanceId()});
+ List<InfraActiveRequests> infraActiveRequestsResponse = requestsDbClient.getRequest(filters);
+
+ verifyInfraActiveRequests(infraActiveRequestsResponse.get(0));
+ }
}