Modified create-vcpe to filter out "bad" VNFs 13/23713/1
authorJim Hahn <jrh3@att.com>
Wed, 15 Nov 2017 23:25:57 +0000 (18:25 -0500)
committerJim Hahn <jrh3@att.com>
Wed, 15 Nov 2017 23:25:57 +0000 (18:25 -0500)
Modified create-vcpe to delete the BRG and TXC items from the
service VNF list contained within the service decomposition
structure.

Change-Id: I7624a93b422fa172a2079f70d66a2604ee2229b0
Issue-Id: SO-344
Signed-off-by: Jim Hahn <jrh3@att.com>
bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/vcpe/scripts/CreateVcpeResCustService.groovy
bpmn/MSOInfrastructureBPMN/src/test/groovy/org/openecomp/mso/bpmn/vcpe/scripts/CreateVcpeResCustServiceTest.groovy

index 703ea8b..dd6d451 100644 (file)
@@ -343,6 +343,9 @@ public class CreateVcpeResCustService extends AbstractServiceTaskProcessor {
 \r
                        // VNFs\r
                        List<VnfResource> vnfList = serviceDecomposition.getServiceVnfs()\r
+                       filterVnfs(vnfList)\r
+                       serviceDecomposition.setServiceVnfs(vnfList)\r
+                       \r
                        execution.setVariable("vnfList", vnfList)\r
                        execution.setVariable("vnfListString", vnfList.toString())\r
 \r
@@ -372,6 +375,24 @@ public class CreateVcpeResCustService extends AbstractServiceTaskProcessor {
                   exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)\r
                }\r
        }\r
+       \r
+       private void filterVnfs(List<VnfResource> vnfList) {\r
+               if(vnfList == null) {\r
+                       return\r
+               }\r
+               \r
+               // remove BRG & TXC from VNF list\r
+               \r
+               Iterator<VnfResource> it = vnfList.iterator()\r
+               while(it.hasNext()) {\r
+                       VnfResource vr = it.next()\r
+                       \r
+                       String role = vr.getNfRole()\r
+                       if(role == "BRG" || role == "TunnelXConn") {\r
+                               it.remove()\r
+                       }\r
+               }\r
+       }\r
 \r
 \r
        public void prepareCreateAllottedResourceTXC(Execution execution) {\r
index f0645b2..7005042 100644 (file)
@@ -370,7 +370,7 @@ class CreateVcpeResCustServiceTest extends GroovyTestBase {
        // @Ignore  
        public void processDecomposition() {
                ExecutionEntity mex = setupMock()
-               def svcdecomp = initProcessDecomposition(mex, true, true)
+               def svcdecomp = initProcessDecomposition(mex)
                
                CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
                CreateVcpeResCustService.processDecomposition(mex)
@@ -378,8 +378,8 @@ class CreateVcpeResCustServiceTest extends GroovyTestBase {
                verify(mex).getVariable(DBGFLAG)
                
                verify(mex).setVariable("vnfList", svcdecomp.getServiceVnfs())
-               verify(mex).setVariable("vnfListString", '[myvnf, myvnf2, myvnf3]')
-               verify(mex).setVariable(Prefix+"VNFsCount", 3)
+               verify(mex).setVariable("vnfListString", '[myvnf]')
+               verify(mex).setVariable(Prefix+"VNFsCount", 1)
                
                verify(mex).setVariable("vnfModelInfo", "mymodel")
                verify(mex).setVariable("vnfModelInfoString", "mymodel")
@@ -389,7 +389,7 @@ class CreateVcpeResCustServiceTest extends GroovyTestBase {
        // @Ignore  
        public void processDecomposition_EmptyNet_EmptyVnf() {
                ExecutionEntity mex = setupMock()
-               def svcdecomp = initProcessDecomposition(mex, true, true)
+               def svcdecomp = initProcessDecomposition(mex)
                
                when(svcdecomp.getServiceVnfs()).thenReturn(new LinkedList<VnfResource>())
                
@@ -410,7 +410,7 @@ class CreateVcpeResCustServiceTest extends GroovyTestBase {
        // @Ignore  
        public void processDecomposition_Ex() {
                ExecutionEntity mex = setupMock()
-               def svcdecomp = initProcessDecomposition(mex, true, true)
+               def svcdecomp = initProcessDecomposition(mex)
                
                when(svcdecomp.getServiceVnfs()).thenThrow(new RuntimeException("expected exception"))
                
@@ -420,6 +420,35 @@ class CreateVcpeResCustServiceTest extends GroovyTestBase {
        }
        
        
+       // ***** filterVnfs *****
+                       
+       @Test
+       // @Ignore  
+       public void filterVnfs() {
+               ExecutionEntity mex = setupMock()
+               def svcdecomp = initFilterVnfs(mex)
+               
+               CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
+               CreateVcpeResCustService.processDecomposition(mex)
+               
+               verify(mex).setVariable("vnfListString", '[myvnf3, myvnf5]')
+       }
+                       
+       @Test
+       // @Ignore  
+       public void filterVnfs_Null() {
+               ExecutionEntity mex = setupMock()
+               def svcdecomp = initFilterVnfs(mex)
+               
+               when(svcdecomp.getServiceVnfs()).thenReturn(null)
+               
+               CreateVcpeResCustService CreateVcpeResCustService = new CreateVcpeResCustService()
+               CreateVcpeResCustService.processDecomposition(mex)
+               
+               // nothing more to check, as long as it didn't throw an exception
+       }
+       
+       
        // ***** prepareCreateAllottedResourceTXC *****
                        
        @Test
@@ -1034,13 +1063,30 @@ class CreateVcpeResCustServiceTest extends GroovyTestBase {
                when(mex.getVariable("serviceInstanceName")).thenReturn("sin")
        }
        
-       private ServiceDecomposition initProcessDecomposition(ExecutionEntity mex, boolean haveNet, boolean haveVnf) {
+       private ServiceDecomposition initProcessDecomposition(ExecutionEntity mex) {
+               List<VnfResource> vnflst = new LinkedList<>()
+               vnflst.add(makeVnf("", ""))
+               vnflst.add(makeVnf("2", "BRG"))
+               vnflst.add(makeVnf("3", "BRG"))
+                       
+               ServiceDecomposition svcdecomp = mock(ServiceDecomposition.class)
+               when(svcdecomp.getServiceVnfs()).thenReturn(vnflst)
+               
+               when(mex.getVariable(DBGFLAG)).thenReturn("true")
+               when(mex.getVariable("serviceDecomposition")).thenReturn(svcdecomp)
+               when(mex.getVariable("serviceInstanceId")).thenReturn("sii")
+               when(mex.getVariable("serviceInstanceName")).thenReturn("sin")
+               
+               return svcdecomp
+       }
+       
+       private ServiceDecomposition initFilterVnfs(ExecutionEntity mex) {
                List<VnfResource> vnflst = new LinkedList<>()
-               if(haveVnf) {
-                       vnflst.add(makeVnf(""))
-                       vnflst.add(makeVnf("2"))
-                       vnflst.add(makeVnf("3"))
-               }
+               vnflst.add(makeVnf("", "BRG"))
+               vnflst.add(makeVnf("2", "TunnelXConn"))
+               vnflst.add(makeVnf("3", ""))
+               vnflst.add(makeVnf("4", "BRG"))
+               vnflst.add(makeVnf("5", "other"))
                        
                ServiceDecomposition svcdecomp = mock(ServiceDecomposition.class)
                when(svcdecomp.getServiceVnfs()).thenReturn(vnflst)
@@ -1133,10 +1179,10 @@ class CreateVcpeResCustServiceTest extends GroovyTestBase {
                
                List<VnfResource> vnflst = new LinkedList<>()
                
-               vnflst.add(makeVnf("A"))
-               vnflst.add(makeVnf("B"))
-               vnflst.add(makeVnf("C"))
-               vnflst.add(makeVnf("D"))
+               vnflst.add(makeVnf("A", "BRG"))
+               vnflst.add(makeVnf("B", ""))
+               vnflst.add(makeVnf("C", ""))
+               vnflst.add(makeVnf("D", "TunnelXConn"))
                
                when(mex.getVariable(DBGFLAG)).thenReturn("true")
                when(mex.getVariable("createVcpeServiceRequest")).thenReturn(request)
@@ -1146,7 +1192,7 @@ class CreateVcpeResCustServiceTest extends GroovyTestBase {
                when(mex.getVariable("sdncVersion")).thenReturn("myvers")
        }
        
-       private VnfResource makeVnf(String id) {                
+       private VnfResource makeVnf(String id, String role) {           
                ModelInfo mod = mock(ModelInfo.class)           
                VnfResource vnf = mock(VnfResource.class)
                
@@ -1154,8 +1200,9 @@ class CreateVcpeResCustServiceTest extends GroovyTestBase {
                
                when(vnf.toString()).thenReturn("myvnf"+id)
                when(vnf.getModelInfo()).thenReturn(mod)
+               when(vnf.getNfRole()).thenReturn(role)
 
-               return vnf              
+               return vnf
        }
        
        private initValidateVnfCreate(ExecutionEntity mex) {