From fece3044e254866abd948629b05107f0de6b9ba2 Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Tue, 10 Nov 2020 10:12:53 -0500 Subject: Allow mixed case in check of prov-status Apparently SO/AAI in Frankfurt are setting the prov-status to "active" instead of "ACTIVE". Modified the code to ignore case when comparing. Issue-ID: POLICY-2890-prov-status Change-Id: Ibe2bcf451dcdc05361f40d2c5c5146eb6a9cb620 Signed-off-by: Jim Hahn --- .../eventmanager/ControlLoopEventManager.java | 5 +++-- .../eventmanager/ControlLoopEventManager2.java | 5 +++-- .../eventmanager/ControlLoopEventManager2Test.java | 13 +++++++++++++ .../eventmanager/ControlLoopEventManagerTest.java | 16 ++++++++++++++-- 4 files changed, 33 insertions(+), 6 deletions(-) (limited to 'controlloop') diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java index 6e88ce982..08cd82fda 100644 --- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java +++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java @@ -768,8 +768,9 @@ public class ControlLoopEventManager implements Serializable { */ protected static boolean isProvStatusInactive(VirtualControlLoopEvent event) { Map aai = event.getAai(); - return (!PROV_STATUS_ACTIVE.equals(aai.getOrDefault(VSERVER_PROV_STATUS, PROV_STATUS_ACTIVE)) - || !PROV_STATUS_ACTIVE.equals(aai.getOrDefault(GENERIC_VNF_PROV_STATUS, PROV_STATUS_ACTIVE))); + return (!PROV_STATUS_ACTIVE.equalsIgnoreCase(aai.getOrDefault(VSERVER_PROV_STATUS, PROV_STATUS_ACTIVE)) + || !PROV_STATUS_ACTIVE.equalsIgnoreCase( + aai.getOrDefault(GENERIC_VNF_PROV_STATUS, PROV_STATUS_ACTIVE))); } /** diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager2.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager2.java index 5f611c098..b3bd2e347 100644 --- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager2.java +++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager2.java @@ -554,8 +554,9 @@ public class ControlLoopEventManager2 implements ManagerContext, Serializable { */ private static boolean isProvStatusInactive(VirtualControlLoopEvent event) { Map aai = event.getAai(); - return !(PROV_STATUS_ACTIVE.equals(aai.getOrDefault(VSERVER_PROV_STATUS, PROV_STATUS_ACTIVE)) - && PROV_STATUS_ACTIVE.equals(aai.getOrDefault(GENERIC_VNF_PROV_STATUS, PROV_STATUS_ACTIVE))); + return !(PROV_STATUS_ACTIVE.equalsIgnoreCase(aai.getOrDefault(VSERVER_PROV_STATUS, PROV_STATUS_ACTIVE)) + && PROV_STATUS_ACTIVE.equalsIgnoreCase( + aai.getOrDefault(GENERIC_VNF_PROV_STATUS, PROV_STATUS_ACTIVE))); } /** diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager2Test.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager2Test.java index d09c2c88b..e38ef2f4e 100644 --- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager2Test.java +++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager2Test.java @@ -193,6 +193,19 @@ public class ControlLoopEventManager2Test { assertThatThrownBy(() -> new ControlLoopEventManager2(params, event, workMem)) .hasMessage("prov-status is not ACTIVE on VServer or VNF"); + // test with both prov-status flags, with mixed case + event.setAai(addAai(orig, ControlLoopEventManager2.VSERVER_PROV_STATUS, "ACTIVE")); + assertThatCode(() -> new ControlLoopEventManager2(params, event, workMem)).doesNotThrowAnyException(); + + event.setAai(addAai(orig, ControlLoopEventManager2.VSERVER_PROV_STATUS, "active")); + assertThatCode(() -> new ControlLoopEventManager2(params, event, workMem)).doesNotThrowAnyException(); + + event.setAai(addAai(orig, ControlLoopEventManager2.GENERIC_VNF_PROV_STATUS, "ACTIVE")); + assertThatCode(() -> new ControlLoopEventManager2(params, event, workMem)).doesNotThrowAnyException(); + + event.setAai(addAai(orig, ControlLoopEventManager2.GENERIC_VNF_PROV_STATUS, "active")); + assertThatCode(() -> new ControlLoopEventManager2(params, event, workMem)).doesNotThrowAnyException(); + // valid event.setAai(orig); assertThatCode(() -> mgr.checkEventSyntax(event)).doesNotThrowAnyException(); diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java index db16c4528..7c89f1897 100644 --- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java +++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java @@ -733,13 +733,25 @@ public class ControlLoopEventManagerTest { aai.remove(ControlLoopEventManager.VSERVER_PROV_STATUS); assertFalse(ControlLoopEventManager.isProvStatusInactive(onset)); + // null, ACTIVE + aai.remove(ControlLoopEventManager.GENERIC_VNF_PROV_STATUS); + aai.put(ControlLoopEventManager.VSERVER_PROV_STATUS, ControlLoopEventManager.PROV_STATUS_ACTIVE.toUpperCase()); + assertFalse(ControlLoopEventManager.isProvStatusInactive(onset)); + // null, active aai.remove(ControlLoopEventManager.GENERIC_VNF_PROV_STATUS); - aai.put(ControlLoopEventManager.VSERVER_PROV_STATUS, ControlLoopEventManager.PROV_STATUS_ACTIVE); + aai.put(ControlLoopEventManager.VSERVER_PROV_STATUS, ControlLoopEventManager.PROV_STATUS_ACTIVE.toLowerCase()); + assertFalse(ControlLoopEventManager.isProvStatusInactive(onset)); + + // ACTIVE, null + aai.put(ControlLoopEventManager.GENERIC_VNF_PROV_STATUS, + ControlLoopEventManager.PROV_STATUS_ACTIVE.toUpperCase()); + aai.remove(ControlLoopEventManager.VSERVER_PROV_STATUS); assertFalse(ControlLoopEventManager.isProvStatusInactive(onset)); // active, null - aai.put(ControlLoopEventManager.GENERIC_VNF_PROV_STATUS, ControlLoopEventManager.PROV_STATUS_ACTIVE); + aai.put(ControlLoopEventManager.GENERIC_VNF_PROV_STATUS, + ControlLoopEventManager.PROV_STATUS_ACTIVE.toLowerCase()); aai.remove(ControlLoopEventManager.VSERVER_PROV_STATUS); assertFalse(ControlLoopEventManager.isProvStatusInactive(onset)); -- cgit 1.2.3-korg