Relax VNF Change Management filters for VNFs 30/113530/1
authormarcinrzepeckiwroc <marcin.rzepecki@nokia.com>
Mon, 5 Oct 2020 12:17:30 +0000 (14:17 +0200)
committermarcinrzepeckiwroc <marcin.rzepecki@nokia.com>
Mon, 5 Oct 2020 12:17:30 +0000 (14:17 +0200)
Issue-ID: VID-837
Signed-off-by: marcinrzepeckiwroc <marcin.rzepecki@nokia.com>
Change-Id: I1b1a501897d013a9f2b54423100aa8de924e5a9d

vid-app-common/src/main/webapp/app/vid/scripts/modals/new-change-management/new-change-management.controller.js
vid-app-common/src/main/webapp/app/vid/scripts/modals/new-change-management/new-change-management.controller.test.js

index 08791b2..3ebadda 100644 (file)
@@ -3,6 +3,7 @@
  * VID
  * ================================================================================
  * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2020 Nokia Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
             vm.vnfNames = [];
             vm.changeManagement.vnfNames = [];
 
-            var instances = vm.changeManagement.serviceType["service-instances"]["service-instance"];
-            // var promiseArrOfGetVnfs = preparePromiseArrOfGetVnfs(instances);
-
             vm.vnfs = [];
             vm.vfModules = [];
+            vm.genericVnfs = [];
 
             let nfRole = null;
             let cloudRegion = null;
                 cloudRegion = vm.changeManagement.cloudRegion ? vm.changeManagement.cloudRegion : null;
             }
 
-            AaiService.getVnfsByCustomerIdAndServiceType(
+            return AaiService.getVnfsByCustomerIdAndServiceType(
                 vm.changeManagement.subscriberId,
                 vm.changeManagement.serviceType["service-type"],
                 nfRole,
                             if (vnfsData[i]) {
                                 const nodeType = vnfsData[i]['node-type'];
                                 if (nodeType === "generic-vnf") {
-                                    if (_.find(vnfsData[i]['related-to'], function (node) {
-                                        return node['node-type'] === 'vserver';
-                                    }) !== undefined) {
-                                        vm.vnfs.push(vnfsData[i]);
-                                    }
+                                    vm.genericVnfs.push(vnfsData[i]);
                                 } else if (nodeType === "service-instance") {
                                     vm.serviceInstances.push(vnfsData[i]);
                                 } else if (nodeType === "vf-module") {
                             }
                         }
 
+                        vm.genericVnfs.forEach(function (vnf) {
+                            if (vnf['related-to'].find(function (node) {return node['node-type'] === 'vf-module';}) !== undefined) {
+                                let vfModuleRel = vnf['related-to'].find(function (node) {
+                                    return node['node-type'] === 'vf-module'
+                                })
+                                for (var i = 0; i < vm.vfModules.length; i++) {
+                                    const vfModule = vm.vfModules[i];
+                                    if (vfModule['id'] === vfModuleRel['id']){
+                                        if (vfModule['related-to'].find(function (node) {return node['node-type'] === 'vserver';}) !== undefined) {
+                                            vm.vnfs.push(vnf);
+                                        }
+                                    }
+                                }
+                            } else if (vnf['related-to'].find(function (node) {return node['node-type'] === 'vserver';}) !== undefined) {
+                                vm.vnfs.push(vnf);
+                            }
+                        });
+
                         vm.vnfs = _.flattenDeep(
                             _.remove(vm.vnfs, function (vnf) {
                                 var nfRole = vnf.properties['nf-role'];
 
         init();
     }
-})();
\ No newline at end of file
+})();
index e8cba4a..224289f 100644 (file)
@@ -3,6 +3,7 @@
  * VID
  * ================================================================================
  * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2020 Nokia Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -33,6 +34,7 @@ describe('Testing workFlows from SO', () => {
 
   beforeEach(inject(function (_$controller_) {
     $notNeeded = jestMock.fn();
+    let lodash = require('lodash')
 
     // mock ChangeManagementService
     $changeManagementService = jestMock.fn();
@@ -59,7 +61,7 @@ describe('Testing workFlows from SO', () => {
       changeManagementService: $changeManagementService,
       Upload: $notNeeded,
       $log: $notNeeded,
-      _: $notNeeded,
+      _: lodash,
       COMPONENT: $flags,
       VIDCONFIGURATION: $notNeeded,
       DataService: $notNeeded,
@@ -421,4 +423,96 @@ describe('Testing workFlows from SO', () => {
     }]);
   });
 });
+
+    test('Verify that vm.searchVNFs return only generic-vnfs with relation to vserver', () => {
+        // given
+        $controller.changeManagement.serviceType = [];
+        let getVnfsByCustomerIdAndServiceType = Promise.resolve({"data":
+                { "results" : [
+                        { "id": "1",
+                            "node-type": "generic-vnf",
+                            "properties": {
+                                "nf-role": "vLB"
+                            },
+                            "related-to": [
+                                { "id": "11",
+                                    "node-type": "vf-module"
+                                },
+                                { "id": "12",
+                                    "node-type": "tenant"
+                                }
+                            ]
+                        },
+                        { "id": "2",
+                            "node-type": "generic-vnf",
+                            "properties": {
+                                "nf-role": "vLB"
+                            },
+                            "related-to": [
+                                { "id": "21",
+                                    "node-type": "tenant"
+                                }
+                            ]
+                        },
+                        { "id": "3",
+                            "node-type": "generic-vnf",
+                            "properties": {
+                                "nf-role": "vLB"
+                            },
+                            "related-to": [
+                                { "id": "31",
+                                    "node-type": "vf-module"
+                                },
+                                { "id": "32",
+                                    "node-type": "tenant"
+                                },
+                                { "id": "33",
+                                    "node-type": "vserver"
+                                }
+                            ]
+                        },
+                        { "id": "11",
+                            "node-type": "vf-module",
+                            "related-to": [
+                                { "id": "111",
+                                    "node-type": "vserver"
+                                }
+                            ]
+                        },
+                        { "id": "31",
+                            "node-type": "vf-module",
+                            "related-to": [
+                                { "id": "311",
+                                    "node-type": "vserver"
+                                }
+                            ]
+                        }
+                    ]
+                }
+        });
+        let expectedVnfs = [
+            {
+                "id": "1",
+                "node-type": "generic-vnf",
+                "properties": {"nf-role": "vLB"},
+                "related-to": [
+                    {"id": "11", "node-type": "vf-module"},
+                    {"id": "12", "node-type": "tenant"}]},
+            {
+                "id": "3",
+                "node-type": "generic-vnf",
+                "properties": {"nf-role": "vLB"},
+                "related-to": [
+                    {"id": "31", "node-type": "vf-module"},
+                    {"id": "32", "node-type": "tenant"},
+                    {"id": "33", "node-type": "vserver"}
+                ]}];
+        $aaiService.getVnfsByCustomerIdAndServiceType = () => getVnfsByCustomerIdAndServiceType;
+
+        // when
+        $controller.searchVNFs().then(() => {
+            expect($controller.vnfs).toHaveLength(2);
+            expect($controller.vnfs).toEqual(expectedVnfs);
+        });
+    });
 });