Add rainyDayTest for VFW 09/103809/5
authorPeyton Puckett <peyton.puckett@att.com>
Tue, 17 Mar 2020 16:30:11 +0000 (11:30 -0500)
committerPeyton Puckett <peyton.puckett@att.com>
Wed, 18 Mar 2020 20:56:16 +0000 (15:56 -0500)
Added less restrictive filter condition to consider discarded messages

Issue-ID: POLICY-2431
Change-Id: I0bc5e34636699094c97bd7e5669f66df875cd6ae
Signed-off-by: Peyton Puckett <peyton.puckett@att.com>
controlloop/common/controller-usecases/src/test/java/org/onap/policy/controlloop/UsecasesTest.java
controlloop/common/rules-test/src/main/java/org/onap/policy/controlloop/common/rules/test/BaseRuleTest.java
controlloop/common/rules-test/src/main/java/org/onap/policy/controlloop/common/rules/test/Listener.java
controlloop/common/rules-test/src/main/resources/vfw/tosca-compliant-timeout-vfw.json [new file with mode: 0644]
controlloop/common/rules-test/src/main/resources/vfw/tosca-compliant-vfw.json
controlloop/common/rules-test/src/main/resources/vfw/tosca-vfw.json
controlloop/common/rules-test/src/main/resources/vfw/vfw.appc.failure.json [new file with mode: 0644]
controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/BaseRuleTestTest.java

index 53c15a3..1250dc8 100644 (file)
@@ -115,6 +115,6 @@ public class UsecasesTest extends BaseRuleTest {
                     Listener<VirtualControlLoopNotification> policyClMgt, ControlLoopNotificationType finalType) {
 
         return policyClMgt.await(notif -> notif.getNotification() == finalType
-                        && (policy.getIdentifier().getName() + ".EVENT.MANAGER").equals(notif.getPolicyName()));
+                        && (notif.getPolicyName().contains(policy.getIdentifier().getName() + ".EVENT.MANAGER")));
     }
 }
index 1de02e5..f8b033c 100644 (file)
@@ -29,6 +29,7 @@ import java.util.function.Supplier;
 import java.util.stream.Collectors;
 import lombok.AccessLevel;
 import lombok.Getter;
+
 import org.junit.Test;
 import org.onap.policy.appc.Request;
 import org.onap.policy.appclcm.AppcLcmDmaapWrapper;
@@ -87,8 +88,10 @@ public abstract class BaseRuleTest {
     // VFW
     private static final String VFW_TOSCA_LEGACY_POLICY = "vfw/tosca-vfw.json";
     private static final String VFW_TOSCA_COMPLIANT_POLICY = "vfw/tosca-compliant-vfw.json";
+    private static final String VFW_TOSCA_COMPLIANT_TIME_OUT_POLICY = "vfw/tosca-compliant-timeout-vfw.json";
     private static final String VFW_ONSET = "vfw/vfw.onset.json";
     private static final String VFW_APPC_SUCCESS = "vfw/vfw.appc.success.json";
+    private static final String VFW_APPC_FAILURE = "vfw/vfw.appc.failure.json";
 
     // VLB
     private static final String VLB_TOSCA_LEGACY_POLICY = "vlb/tosca-vlb.json";
@@ -111,7 +114,6 @@ public abstract class BaseRuleTest {
     protected static HttpClients httpClients;
     protected static Simulators simulators;
 
-
     // used to inject and wait for messages
     @Getter(AccessLevel.PROTECTED)
     private Topics topics;
@@ -322,6 +324,30 @@ public abstract class BaseRuleTest {
         appcLegacySunnyDay(VFW_TOSCA_COMPLIANT_POLICY, VFW_ONSET, "ModifyConfig");
     }
 
+    /**
+     * VFW Rainy Day using legacy tosca policy (operation and final failure).
+     */
+    @Test
+    public void testVfwRainyDayLegacyFailure() {
+        appcLegacyRainyDay(VFW_TOSCA_LEGACY_POLICY, VFW_ONSET, "ModifyConfig");
+    }
+
+    /**
+     * VFW Rainy Day using compliant tosca policy (final failure).
+     */
+    @Test
+    public void testVfwRainyDayOverallTimeout() {
+        appcLegacyRainyDayNoResponse(VFW_TOSCA_COMPLIANT_TIME_OUT_POLICY, VFW_ONSET, "ModifyConfig");
+    }
+
+    /**
+     * VFW Rainy day using compliant tosca policy (final failure due to timeout).
+     */
+    @Test
+    public void testVfwRainyDayCompliantTimeout() {
+        appcLegacyRainyDayNoResponse(VFW_TOSCA_COMPLIANT_POLICY, VFW_ONSET, "ModifyConfig");
+    }
+
     // VLB
 
     /**
@@ -434,6 +460,81 @@ public abstract class BaseRuleTest {
         waitForFinalSuccess(policy, policyClMgt);
     }
 
+    /**
+     * Rainy day scenario for use cases that use Legacy APPC.
+     *
+     * @param policyFile file containing the ToscaPolicy to be loaded
+     * @param onsetFile file containing the ONSET to be injected
+     * @param operation expected APPC operation request
+     * @param checkOperation flag to determine whether or not to wait for operation timeout
+     */
+    protected void appcLegacyRainyDay(String policyFile, String onsetFile, String operation) {
+        policyClMgt = topics.createListener(POLICY_CL_MGT_TOPIC, VirtualControlLoopNotification.class, controller);
+        appcClSink = topics.createListener(APPC_CL_TOPIC, Request.class, APPC_LEGACY_CODER);
+
+        assertEquals(0, controller.getDrools().factCount(rules.getControllerName()));
+        policy = rules.setupPolicyFromFile(policyFile);
+        assertEquals(2, controller.getDrools().factCount(rules.getControllerName()));
+
+        /* Inject an ONSET event over the DCAE topic */
+        topics.inject(DCAE_TOPIC, onsetFile);
+
+        /* Wait to acquire a LOCK and a PDP-X PERMIT */
+        waitForLockAndPermit(policy, policyClMgt);
+
+        /*
+         * Ensure that an APPC RESTART request was sent in response to the matching ONSET
+         */
+        Request appcreq = appcClSink.await(req -> operation.equals(req.getAction()));
+
+        /*
+         * Inject a 401 APPC Response Return over the APPC topic, with appropriate
+         * subRequestId
+         */
+        topics.inject(APPC_CL_TOPIC, VFW_APPC_FAILURE, appcreq.getCommonHeader().getSubRequestId());
+
+        /* --- Operation Completed --- */
+        waitForOperationFailure();
+
+        /* --- Transaction Completed --- */
+        waitForFinalFailure(policy, policyClMgt);
+    }
+
+    /**
+     * Rainy day scenario for use cases that use Legacy APPC.
+     * Expected to fail due to timeout.
+     *
+     * @param policyFile file containing the ToscaPolicy to be loaded
+     * @param onsetFile file containing the ONSET to be injected
+     * @param operation expected APPC operation request
+     */
+    protected void appcLegacyRainyDayNoResponse(String policyFile, String onsetFile, String operation) {
+        policyClMgt = topics.createListener(POLICY_CL_MGT_TOPIC, VirtualControlLoopNotification.class, controller);
+        appcClSink = topics.createListener(APPC_CL_TOPIC, Request.class, APPC_LEGACY_CODER);
+
+        assertEquals(0, controller.getDrools().factCount(rules.getControllerName()));
+        policy = rules.setupPolicyFromFile(policyFile);
+        assertEquals(2, controller.getDrools().factCount(rules.getControllerName()));
+
+        /* Inject an ONSET event over the DCAE topic */
+        topics.inject(DCAE_TOPIC, onsetFile);
+
+        /* Wait to acquire a LOCK and a PDP-X PERMIT */
+        waitForLockAndPermit(policy, policyClMgt);
+
+        /*
+         * Ensure that an APPC RESTART request was sent in response to the matching ONSET
+         */
+        appcClSink.await(req -> operation.equals(req.getAction()));
+
+        /*
+         * Do not inject an APPC Response.
+         */
+
+        /* --- Transaction Completed --- */
+        waitForFinalFailure(policy, policyClMgt);
+    }
+
     /**
      * Sunny day scenario for use cases that use an HTTP simulator.
      *
@@ -480,6 +581,24 @@ public abstract class BaseRuleTest {
         return this.waitForFinal(policy, policyClMgt, ControlLoopNotificationType.FINAL_SUCCESS);
     }
 
+    /**
+     * Waits for a OPERATION FAILURE transaction notification.
+     */
+    protected void waitForOperationFailure() {
+        policyClMgt.await(notif -> notif.getNotification() == ControlLoopNotificationType.OPERATION_FAILURE);
+    }
+
+    /**
+     * Waits for a FINAL FAILURE transaction notification.
+     *
+     * @return the FINAL FAILURE notification
+     */
+    protected VirtualControlLoopNotification waitForFinalFailure(ToscaPolicy policy,
+                    Listener<VirtualControlLoopNotification> policyClMgt) {
+
+        return this.waitForFinal(policy, policyClMgt, ControlLoopNotificationType.FINAL_FAILURE);
+    }
+
     /**
      * Waits for notifications for LOCK acquisition and GUARD Permit so that event
      * processing may proceed.
index a353c98..5110fe7 100644 (file)
@@ -41,7 +41,7 @@ import org.slf4j.LoggerFactory;
  */
 public class Listener<T> implements TopicListener {
     private static final Logger logger = LoggerFactory.getLogger(Listener.class);
-    private static final long DEFAULT_WAIT_SEC = 5L;
+    private static final long DEFAULT_WAIT_SEC = 10L;
 
     private final TopicSink sink;
     private final Function<String, T> decoder;
diff --git a/controlloop/common/rules-test/src/main/resources/vfw/tosca-compliant-timeout-vfw.json b/controlloop/common/rules-test/src/main/resources/vfw/tosca-compliant-timeout-vfw.json
new file mode 100644 (file)
index 0000000..3350685
--- /dev/null
@@ -0,0 +1,40 @@
+{
+    "type": "onap.policies.controlloop.operational.common.Drools",
+    "type_version": "1.0.0",
+    "name": "operational.modifyconfig",
+    "version": "1.0.0",
+    "metadata": {
+        "policy-id": "operational.modifyconfig"
+    },
+    "properties": {
+        "controllerName": "usecases",
+        "id": "ControlLoop-vFirewall-d0a1dfc6-94f5-4fd4-a5b5-4630b438850a",
+        "timeout": 7,
+        "abatement": false,
+        "trigger": "unique-policy-id-1-modifyConfig",
+        "operations": [
+            {
+                "id": "unique-policy-id-1-modifyConfig",
+                "description": "Modify the packet generator",
+                "operation": {
+                    "actor": "APPC",
+                    "operation": "ModifyConfig",
+                    "target": {
+                        "targetType": "VNF",
+                        "entityIds": {
+                            "resourceID": "bbb3cefd-01c8-413c-9bdd-2b92f9ca3d38"
+                        }
+                    }
+                },
+                "timeout": 10,
+                "retries": 0,
+                "success": "final_success",
+                "failure": "final_failure",
+                "failure_timeout": "final_failure_timeout",
+                "failure_retries": "final_failure_retries",
+                "failure_exception": "final_failure_exception",
+                "failure_guard": "final_failure_guard"
+            }
+        ]
+    }
+}
index f551456..6d8603b 100644 (file)
@@ -26,7 +26,7 @@
                         }
                     }
                 },
-                "timeout": 300,
+                "timeout": 7,
                 "retries": 0,
                 "success": "final_success",
                 "failure": "final_failure",
index 35a8396..b9f6b7f 100644 (file)
@@ -2,7 +2,7 @@
   "type": "onap.policies.controlloop.Operational",
   "type_version": "1.0.0",
   "properties": {
-    "content": "controlLoop%3A%0A%20%20version%3A%202.0.0%0A%20%20controlLoopName%3A%20ControlLoop-vFirewall-d0a1dfc6-94f5-4fd4-a5b5-4630b438850a%0A%20%20services%3A%0A%20%20%20%20-%20serviceInvariantUUID%3A%20f6937c86-584c-47ae-ad29-8d41d6f0cc7c%0A%20%20%20%20%20%20serviceUUID%3A%207be584e2-0bb2-4126-adaf-ced2c77ca0b3%0A%20%20%20%20%20%20serviceName%3A%20Service_Ete_Name7ba1fbde-6187-464a-a62d-d9dd25bdf4e8%0A%20%20trigger_policy%3A%20unique-policy-id-1-modifyConfig%0A%20%20timeout%3A%2060%0A%20%20abatement%3A%20false%0A%20%0Apolicies%3A%0A%20%20-%20id%3A%20unique-policy-id-1-modifyConfig%0A%20%20%20%20name%3A%20modify%20packet%20gen%20config%0A%20%20%20%20description%3A%0A%20%20%20%20actor%3A%20APPC%0A%20%20%20%20recipe%3A%20ModifyConfig%0A%20%20%20%20target%3A%0A%20%20%20%20%20%20resourceID%3A%20bbb3cefd-01c8-413c-9bdd-2b92f9ca3d38%0A%20%20%20%20%20%20type%3A%20VNF%0A%20%20%20%20retry%3A%200%0A%20%20%20%20timeout%3A%2030%0A%20%20%20%20success%3A%20final_success%0A%20%20%20%20failure%3A%20final_failure%0A%20%20%20%20failure_timeout%3A%20final_failure_timeout%0A%20%20%20%20failure_retries%3A%20final_failure_retries%0A%20%20%20%20failure_exception%3A%20final_failure_exception%0A%20%20%20%20failure_guard%3A%20final_failure_guard"
+    "content": "controlLoop%3A%0A%20%20version%3A%202.0.0%0A%20%20controlLoopName%3A%20ControlLoop-vFirewall-d0a1dfc6-94f5-4fd4-a5b5-4630b438850a%0A%20%20services%3A%0A%20%20%20%20-%20serviceInvariantUUID%3A%20f6937c86-584c-47ae-ad29-8d41d6f0cc7c%0A%20%20%20%20%20%20serviceUUID%3A%207be584e2-0bb2-4126-adaf-ced2c77ca0b3%0A%20%20%20%20%20%20serviceName%3A%20Service_Ete_Name7ba1fbde-6187-464a-a62d-d9dd25bdf4e8%0A%20%20trigger_policy%3A%20unique-policy-id-1-modifyConfig%0A%20%20timeout%3A%2060%0A%20%20abatement%3A%20false%0A%20%0Apolicies%3A%0A%20%20-%20id%3A%20unique-policy-id-1-modifyConfig%0A%20%20%20%20name%3A%20modify%20packet%20gen%20config%0A%20%20%20%20description%3A%0A%20%20%20%20actor%3A%20APPC%0A%20%20%20%20recipe%3A%20ModifyConfig%0A%20%20%20%20target%3A%0A%20%20%20%20%20%20resourceID%3A%20bbb3cefd-01c8-413c-9bdd-2b92f9ca3d38%0A%20%20%20%20%20%20type%3A%20VNF%0A%20%20%20%20retry%3A%200%0A%20%20%20%20timeout%3A%207%0A%20%20%20%20success%3A%20final_success%0A%20%20%20%20failure%3A%20final_failure%0A%20%20%20%20failure_timeout%3A%20final_failure_timeout%0A%20%20%20%20failure_retries%3A%20final_failure_retries%0A%20%20%20%20failure_exception%3A%20final_failure_exception%0A%20%20%20%20failure_guard%3A%20final_failure_guard"
   },
   "name": "vfw",
   "version": "1.0.0"
diff --git a/controlloop/common/rules-test/src/main/resources/vfw/vfw.appc.failure.json b/controlloop/common/rules-test/src/main/resources/vfw/vfw.appc.failure.json
new file mode 100644 (file)
index 0000000..ff43618
--- /dev/null
@@ -0,0 +1,17 @@
+{
+  "CommonHeader": {
+    "TimeStamp": 1506051879001,
+    "APIver": "1.01",
+    "RequestID": "c7c6a4aa-bb61-4a15-b831-ba1472dd4a65",
+    "SubRequestID": "${replaceMe}",
+    "RequestTrack": [],
+    "Flags": []
+  },
+  "Status": {
+    "Code": 401,
+    "Value": "FAILURE"
+  },
+  "Payload": {
+    "generic-vnf.vnf-id": "jimmy-test-vnf2"
+  }
+}
index 745013b..7274c6b 100644 (file)
@@ -315,6 +315,21 @@ public class BaseRuleTestTest {
         checkAppcLegacyPolicy("ModifyConfig", base::testVfwSunnyDayCompliant);
     }
 
+    @Test
+    public void testTestVfwRainyDayLegacyFailure() {
+        checkAppcLegacyPolicyOperationFailure("ModifyConfig", base::testVfwRainyDayLegacyFailure);
+    }
+
+    @Test
+    public void testTestVfwRainyDayOverallTimeout() {
+        checkAppcLegacyPolicyFinalFailure("ModifyConfig", base::testVfwRainyDayOverallTimeout);
+    }
+
+    @Test
+    public void testTestVfwRainyDayCompliantTimeout() {
+        checkAppcLegacyPolicyFinalFailure("ModifyConfig", base::testVfwRainyDayCompliantTimeout);
+    }
+
     @Test
     public void testTestVlbSunnyDayLegacy() {
         checkHttpPolicy(base::testVlbSunnyDayLegacy);
@@ -365,6 +380,44 @@ public class BaseRuleTestTest {
         verify(topics).inject(eq(BaseRuleTest.APPC_CL_TOPIC), any(), any());
     }
 
+    protected void checkAppcLegacyPolicyOperationFailure(String operation, Runnable test) {
+        enqueueAppcLegacy(operation);
+        enqueueClMgt(ControlLoopNotificationType.OPERATION_FAILURE);
+        enqueueClMgt(ControlLoopNotificationType.FINAL_FAILURE);
+
+        test.run();
+
+        assertEquals(1, permitCount);
+        assertEquals(1, finalCount);
+
+        assertTrue(appcLcmQueue.isEmpty());
+        assertTrue(clMgtQueue.isEmpty());
+
+        // initial event
+        verify(topics).inject(eq(BaseRuleTest.DCAE_TOPIC), any());
+
+        // reply to each APPC request
+        verify(topics).inject(eq(BaseRuleTest.APPC_CL_TOPIC), any(), any());
+    }
+
+    protected void checkAppcLegacyPolicyFinalFailure(String operation, Runnable test) {
+        enqueueAppcLegacy(operation);
+        enqueueClMgt(ControlLoopNotificationType.FINAL_FAILURE);
+
+        test.run();
+
+        assertEquals(1, permitCount);
+        assertEquals(1, finalCount);
+
+        assertTrue(appcLcmQueue.isEmpty());
+        assertTrue(clMgtQueue.isEmpty());
+
+        // initial event
+        verify(topics).inject(eq(BaseRuleTest.DCAE_TOPIC), any());
+
+        // There were no requests sent
+    }
+
     protected void checkHttpPolicy(Runnable test) {
         enqueueClMgt(ControlLoopNotificationType.OPERATION_SUCCESS);
         enqueueClMgt(ControlLoopNotificationType.FINAL_SUCCESS);