diff options
author | Ram Krishna Verma <ram_krishna.verma@bell.ca> | 2020-03-19 15:40:52 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2020-03-19 15:40:52 +0000 |
commit | 6b7d3064ebc4bd6e3dca5d60708e853d2a4836f2 (patch) | |
tree | bee1c31c7ef1baeb91907cf7f688e9990a1cdcb6 /controlloop/common/rules-test/src | |
parent | 780268ec538e303bc5bd5c93e2b813e0d3dcbcc7 (diff) | |
parent | ffb12d3ca702aa53c3f95d6e721f202f27e1aa8b (diff) |
Merge "Add rainyDayTest for VFW"
Diffstat (limited to 'controlloop/common/rules-test/src')
7 files changed, 233 insertions, 4 deletions
diff --git a/controlloop/common/rules-test/src/main/java/org/onap/policy/controlloop/common/rules/test/BaseRuleTest.java b/controlloop/common/rules-test/src/main/java/org/onap/policy/controlloop/common/rules/test/BaseRuleTest.java index 1de02e54c..f8b033ca0 100644 --- a/controlloop/common/rules-test/src/main/java/org/onap/policy/controlloop/common/rules/test/BaseRuleTest.java +++ b/controlloop/common/rules-test/src/main/java/org/onap/policy/controlloop/common/rules/test/BaseRuleTest.java @@ -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 /** @@ -435,6 +461,81 @@ public abstract class BaseRuleTest { } /** + * 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. * * @param policyFile file containing the ToscaPolicy to be loaded @@ -481,6 +582,24 @@ public abstract class BaseRuleTest { } /** + * 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. */ diff --git a/controlloop/common/rules-test/src/main/java/org/onap/policy/controlloop/common/rules/test/Listener.java b/controlloop/common/rules-test/src/main/java/org/onap/policy/controlloop/common/rules/test/Listener.java index a353c98fb..5110fe7b9 100644 --- a/controlloop/common/rules-test/src/main/java/org/onap/policy/controlloop/common/rules/test/Listener.java +++ b/controlloop/common/rules-test/src/main/java/org/onap/policy/controlloop/common/rules/test/Listener.java @@ -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 index 000000000..335068514 --- /dev/null +++ b/controlloop/common/rules-test/src/main/resources/vfw/tosca-compliant-timeout-vfw.json @@ -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" + } + ] + } +} diff --git a/controlloop/common/rules-test/src/main/resources/vfw/tosca-compliant-vfw.json b/controlloop/common/rules-test/src/main/resources/vfw/tosca-compliant-vfw.json index f55145658..6d8603b0f 100644 --- a/controlloop/common/rules-test/src/main/resources/vfw/tosca-compliant-vfw.json +++ b/controlloop/common/rules-test/src/main/resources/vfw/tosca-compliant-vfw.json @@ -26,7 +26,7 @@ } } }, - "timeout": 300, + "timeout": 7, "retries": 0, "success": "final_success", "failure": "final_failure", diff --git a/controlloop/common/rules-test/src/main/resources/vfw/tosca-vfw.json b/controlloop/common/rules-test/src/main/resources/vfw/tosca-vfw.json index 35a839698..b9f6b7f43 100644 --- a/controlloop/common/rules-test/src/main/resources/vfw/tosca-vfw.json +++ b/controlloop/common/rules-test/src/main/resources/vfw/tosca-vfw.json @@ -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 index 000000000..ff4361867 --- /dev/null +++ b/controlloop/common/rules-test/src/main/resources/vfw/vfw.appc.failure.json @@ -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" + } +} diff --git a/controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/BaseRuleTestTest.java b/controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/BaseRuleTestTest.java index 745013b3b..7274c6bda 100644 --- a/controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/BaseRuleTestTest.java +++ b/controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/BaseRuleTestTest.java @@ -316,6 +316,21 @@ public class BaseRuleTestTest { } @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); |