Fix ovp lcm validation 96/96396/2
authorKanagaraj M <mkr1481@gmail.com>
Mon, 30 Sep 2019 04:19:30 +0000 (06:19 +0200)
committerKanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
Mon, 30 Sep 2019 04:45:54 +0000 (06:45 +0200)
Issue-ID: CLI-166

Change-Id: I0c8def49c6d3eb79d4686b40899ff165ae2461ce
Signed-off-by: Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
25 files changed:
deployment/zip/src/main/release/conf/open-cli.properties
framework/src/main/java/org/onap/cli/fw/conf/OnapCommandConstants.java
framework/src/main/resources/open-cli.properties
main/src/main/java/org/onap/cli/main/OnapCli.java
products/onap-dublin/features/integration/src/main/resources/conf/vnf-tosca-lcm.json [moved from products/onap-dublin/features/integration/src/main/resources/conf/vnf-tosca-provision.json with 100% similarity]
products/onap-dublin/features/integration/src/main/resources/open-cli-sample/vnf-tosca-lcm-dublin-schema-sample.yaml [moved from products/onap-dublin/features/integration/src/main/resources/open-cli-sample/vnf-tosca-provision-dublin-schema-sample.yaml with 98% similarity]
products/onap-dublin/features/integration/src/main/resources/open-cli-schema/vnf-tosca-lcm-dublin-schema.yaml [moved from products/onap-dublin/features/integration/src/main/resources/open-cli-schema/vnf-tosca-provision-dublin-schema.yaml with 94% similarity]
products/onap-dublin/features/integration/src/main/resources/script/vnf-tosca-lcm.py [moved from products/onap-dublin/features/integration/src/main/resources/script/vnf-tosca-provision.py with 97% similarity]
products/onap-dublin/features/vfc/src/main/resources/open-cli-sample/catalog/vfc-catalog-onboard-ns-schema-moco.json
products/onap-dublin/features/vfc/src/main/resources/open-cli-sample/catalog/vfc-catalog-onboard-vnf-schema-moco.json
products/onap-dublin/features/vfc/src/main/resources/open-cli-sample/moco-global.json [new file with mode: 0644]
products/onap-dublin/features/vfc/src/main/resources/open-cli-sample/nslcm/vfc-nslcm-create-schema-moco.json
products/onap-dublin/features/vfc/src/main/resources/open-cli-sample/nslcm/vfc-nslcm-delete-schema-moco.json [new file with mode: 0644]
products/onap-dublin/features/vfc/src/main/resources/open-cli-sample/nslcm/vfc-nslcm-delete-schema-sample.yaml [new file with mode: 0644]
products/onap-dublin/features/vfc/src/main/resources/open-cli-sample/nslcm/vfc-nslcm-instantiate-schema-moco.json [new file with mode: 0644]
products/onap-dublin/features/vfc/src/main/resources/open-cli-sample/nslcm/vfc-nslcm-instantiate-schema-sample.yaml [new file with mode: 0644]
products/onap-dublin/features/vfc/src/main/resources/open-cli-sample/nslcm/vfc-nslcm-terminate-schema-moco.json [new file with mode: 0644]
products/onap-dublin/features/vfc/src/main/resources/open-cli-sample/nslcm/vfc-nslcm-terminate-schema-sample.yaml [new file with mode: 0644]
products/onap-dublin/features/vfc/src/main/resources/open-cli-schema/nslcm/vfc-nslcm-create-schema.yaml
products/onap-dublin/features/vfc/src/main/resources/open-cli-schema/nslcm/vfc-nslcm-delete-schema.yaml
products/onap-dublin/features/vfc/src/main/resources/open-cli-schema/nslcm/vfc-nslcm-get-schema.yaml
products/onap-dublin/features/vfc/src/main/resources/open-cli-schema/nslcm/vfc-nslcm-instantiate-schema.yaml
products/onap-dublin/features/vfc/src/main/resources/open-cli-schema/nslcm/vfc-nslcm-terminate-schema.yaml
validate/sample-yaml-generator/src/main/java/org/onap/cli/sample/yaml/SampleYamlGenerator.java
validate/sample-yaml-generator/src/test/java/org/onap/cli/sample/yaml/SampleYamlGeneratorTest.java

index 47df222..de2e843 100644 (file)
@@ -40,6 +40,7 @@ cli.schema.command.type=cmd,auth,catalog
 
 # moco properties
 cli.sample.gen.enable=true
+cli.sample.gen.name=$s{env:OPEN_CLI_USECASE}
 cli.sample.gen.target=$s{env:OPEN_CLI_HOME}/open-cli-sample
 
 # mrkanag Move this to db, once exteranl command registration is supported in place of discovery
index 51a1862..63f9db6 100644 (file)
@@ -160,6 +160,7 @@ public class OnapCommandConstants {
 
     public static final String SAMPLE_GEN_ENABLED = "cli.sample.gen.enable";
     public static final String SAMPLE_GEN_TARGET_FOLDER = "cli.sample.gen.target";
+    public static final String SAMPLE_GEN_NAME = "cli.sample.gen.name";
 
     public static final String OPEN_CLI_SAMPLE_VERSION = "open_cli_sample_version";
     public static final String OPEN_CLI_SAMPLE_VERSION_VALUE_1_0 = "1.0";
index bd8a6ac..5f2a3d8 100644 (file)
@@ -39,6 +39,7 @@ cli.schema.command.type=cmd,auth,catalog
 
 # moco properties
 cli.sample.gen.enable=false
+cli.sample.gen.name=sample1
 cli.sample.gen.target=./open-cli-sample
 
 # mrkanag Move this to db, once exteranl command registration is supported in place of discovery
index cec9cc0..4119c81 100644 (file)
@@ -764,7 +764,8 @@ public class OnapCli {
                 SampleYamlGenerator.generateSampleYaml(cmd.getName(), args, cmd.getResult().print(),
                         cmd.getInfo().getProduct(),
                         OnapCommandConfig.getPropertyValue(OnapCommandConstants.SAMPLE_GEN_TARGET_FOLDER) + "/" + cmd.getSchemaName().replaceAll(".yaml", "") + "-sample.yaml",
-                        cmd.getResult().isDebug());
+                        cmd.getResult().isDebug(),
+                        OnapCommandConfig.getPropertyValue(OnapCommandConstants.SAMPLE_GEN_NAME));
             } catch (IOException error) {
                 throw new OnapCommandInvalidSample(this.cmdName, error);
             }
@@ -1,9 +1,9 @@
 open_cli_sample_version: 1.0
-name: vnf-tosca-provision
+name: vnf-tosca-lcm
 version: onap-dublin
 samples:
   sample1:
-    name: vnf-tosca-provision
+    name: vnf-tosca-lcm
     input: --mode checkup --vsp c:\Users\k00365106\Desktop\vtp\tosca-lcm\vgw.csar --vnf-csar c:\Users\k00365106\Desktop\vtp\tosca-lcm\vgw.csar --ns-csar c:\Users\k00365106\Desktop\vtp\tosca-lcm\vgw.csar --vnfm-driver hwvnfmdriver --timeout 800000 --vnf-name vgw12345678901 --vnf-vendor-name vnfvendor12345678901 --onap-objects D:\workspace\cli\deployment\zip\target\deployunzip\data\tmp\1234567890-1567065851687_result.json
     moco: vnf-tosca-provision-dublin-schema-moco.json
     output: |
@@ -13,7 +13,7 @@
 # limitations under the License.
 
 open_cli_schema_version: 1.0
-name: vnf-tosca-provision
+name: vnf-tosca-lcm
 description: |
   ONAP TOSCA VNF validation using ONAP CLI and Open Command Platform (OCOMP)
 
@@ -82,7 +82,7 @@ description: |
         Similarly, other service IP and Port could be discovered like above, in case not know earlier :)
 
      This profile would be used while running the command with ONAP setup configured in it, as below
-       oclip --profile onap-dublin vnf-tosca-provision .....
+       oclip --profile onap-dublin vnf-tosca-lcm .....
 
   e. Verify these details once by typing 'set'
 
@@ -104,7 +104,7 @@ parameters:
     type: string
     short_option: x
     long_option: config-json
-    default_value: $s{env:OPEN_CLI_HOME}/conf/vnf-tosca-provision.json
+    default_value: $s{env:OPEN_CLI_HOME}/conf/vnf-tosca-lcm.json
     is_optional: false
   - name: vsp
     description: Path to the ONAP vendor service product (VSP) for the VNF to provision
@@ -194,7 +194,7 @@ results:
       scope: short
 cmd:
   command:
-    -  python $s{env:OPEN_CLI_HOME}/script/vnf-tosca-provision.py --vendor-name ${vnf-vendor-name} --vnf-name ${vnf-name} --mode ${mode} --result-json $s{tmp:result.json:onap-objects} --conf ${config-json} --vsp ${vsp} --vnf-csar ${vnf-csar} --ns-csar ${ns-csar} --vnfm-driver ${vnfm-driver}
+    -  python $s{env:OPEN_CLI_HOME}/script/vnf-tosca-lcm.py --vendor-name ${vnf-vendor-name} --vnf-name ${vnf-name} --mode ${mode} --result-json $s{tmp:result.json:onap-objects} --conf ${config-json} --vsp ${vsp} --vnf-csar ${vnf-csar} --ns-csar ${ns-csar} --vnfm-driver ${vnfm-driver}
   success_codes:
     - 0
   working_directory: .
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+# This script uses the ONAP CLI for providing the end-end service creation and termination.
+# Used in devops, testing, certification and production
+# NOTE: This feature is avaialble as ONAP CLI vnf-tosca-lcm
+#
+# Author: kanagaraj.manickam@huawei.com 
+#
+
 import json
 import os
 import argparse
@@ -21,6 +28,9 @@ import uuid
 import subprocess
 import platform
 import datetime
+import string
+import random
+
 from argparse import RawTextHelpFormatter
 
 if platform.system() == 'Windows':
@@ -123,7 +133,7 @@ class ONAP:
                  conf,
                  request_id,
                  debug = False):
-        self.conf = conf
+        self.conf = conf or {}
         self.ocomp = OCOMP(request_id, debug, product=product, profile=profile)
         self.preload()
         self.tag = 'Powered by Open Command Platform - OCOMP'
@@ -132,6 +142,8 @@ class ONAP:
         if self.conf['ONAP']:
             for attr in self.conf['ONAP']:
                 setattr(self, attr, self.conf['ONAP'][attr])
+        else:
+            self.conf['ONAP'] = {}
 
     def create_vlm(self):
         submit = False
@@ -320,7 +332,7 @@ class ONAP:
     def setup_cloud_and_subscription(self):
         associate = False
         if not self.location_id and not self.location_version:
-            location_id = 'ocomp-region-{}'.format(self.ocomp.request_id)
+            location_id = 'ocomp-region-{}'.format(self.conf['ONAP']['uid'])
             self.ocomp.run(command='complex-create',
                                     params={'physical-location-id': location_id,
                                             'data-center-code': 'ocomp',
@@ -349,7 +361,7 @@ class ONAP:
                     break
 
         if not self.cloud_id and not self.cloud_version:
-            cloud_id = 'OCOMP-{}'.format(self.ocomp.request_id)
+            cloud_id = 'OCOMP-{}'.format(self.conf['ONAP']['uid'])
             self.ocomp.run(command='cloud-create',
                                     params={'region-name': self.conf['cloud']['region'],
                                             'complex-name': self.location_id,
@@ -386,7 +398,7 @@ class ONAP:
 
         subscribe = False
         if not self.service_type_id and not self.service_type_version:
-            service_type_id = '{}-{}'.format(self.conf['subscription']['service-type'], self.ocomp.request_id)
+            service_type_id = '{}-{}'.format(self.conf['subscription']['service-type'], self.conf['ONAP']['uid'])
             self.ocomp.run(command='service-type-create',
                                 params={'service-type': service_type_id,
                                         'service-type-id': service_type_id})
@@ -401,7 +413,7 @@ class ONAP:
                     break
 
         if not self.customer_id and not self.customer_version:
-            customer_id = '{}-{}'.format(self.conf['subscription']['customer-name'], self.ocomp.request_id)
+            customer_id = '{}-{}'.format(self.conf['subscription']['customer-name'], self.ocomp.conf['ONAP']['random'])
             self.ocomp.run(command='customer-create',
                                 params={'customer-name': customer_id,
                                         'subscriber-name': customer_id})
@@ -508,6 +520,8 @@ class ONAP:
 
     def cleanup(self):
         if self.ns_instance_id:
+            self.ocomp.run(command='vfc-nslcm-terminate',
+                              params={'ns-instance-id': self.ns_instance_id})
             self.ocomp.run(command='vfc-nslcm-delete',
                               params={'ns-instance-id': self.ns_instance_id})
             self.ns_instance_id = None
@@ -675,6 +689,8 @@ if __name__ == '__main__':
     config_file = args.config_file_path
     with open(config_file) as json_file:
         conf = json.load(json_file)
+        if not conf['ONAP']['uid']:
+            conf['ONAP']['uid'] = ''.join(random.sample(string.ascii_lowercase,5))
         if vsp_csar:
             conf['vnf']['vsp-csar'] = vsp_csar
         if vnf_csar:
@@ -683,11 +699,10 @@ if __name__ == '__main__':
             conf['vnf']['ns-csar'] = vnf_csar
         if vnf_name:
             conf['vnf']['name'] = vnf_name
-        conf['vnf']['name'] = '{}{}'.format(conf['vnf']['name'], request_id).replace("-", "").replace("_", "")
-        if vnf_name:
+        conf['vnf']['name'] = '{}{}'.format(conf['vnf']['name'], conf['ONAP']['uid'])
+        if vendor_name:
             conf['vnf']['vendor-name'] = vendor_name
-        conf['vnf']['vendor-name'] = '{}-{}'.format(conf['vnf']['vendor-name'], request_id)
-
+        conf['vnf']['vendor-name'] = '{}-{}'.format(conf['vnf']['vendor-name'], conf['ONAP']['uid'])
 
     if args.result:
         result_file = args.result
index 5218f7f..41accfa 100644 (file)
@@ -1,14 +1,7 @@
 [ {
   "request" : {
     "method" : "post",
-    "uri" : "/api/catalog/v1/nspackages",
-    "headers" : {
-      "Accept" : "application/json",
-      "Content-Type" : "application/json"
-    },
-    "json" : {
-      "csarId" : "a3394090-c5b4-49b4-974c-00a6eac755ab"
-    }
+    "uri" : "/api/catalog/v1/nspackages"
   },
   "response" : {
     "status" : 202,
index 5e0591d..5327af7 100644 (file)
@@ -1,14 +1,7 @@
 [ {
   "request" : {
     "method" : "post",
-    "uri" : "/api/catalog/v1/vnfpackages",
-    "headers" : {
-      "Accept" : "application/json",
-      "Content-Type" : "application/json"
-    },
-    "json" : {
-      "csarId" : "c1cec675-1069-487d-b1a9-c256b17c3291"
-    }
+    "uri" : "/api/catalog/v1/vnfpackages"
   },
   "response" : {
     "status" : 202,
@@ -16,4 +9,4 @@
       "jobId" : "1d871fc4-380c-4699-8f7f-77e508f9734d"
     }
   }
-} ]
\ No newline at end of file
+} ]
diff --git a/products/onap-dublin/features/vfc/src/main/resources/open-cli-sample/moco-global.json b/products/onap-dublin/features/vfc/src/main/resources/open-cli-sample/moco-global.json
new file mode 100644 (file)
index 0000000..1ae10db
--- /dev/null
@@ -0,0 +1,20 @@
+[
+    {
+        "include" : "catalog/vfc-catalog-onboard-vnf-schema-moco.json"
+    },
+    {
+        "include" : "catalog/vfc-catalog-onboard-ns-schema-moco.json"
+    },
+    {
+        "include" : "nslcm/vfc-nslcm-create-schema-moco.json"
+    },
+    {
+        "include" : "nslcm/vfc-nslcm-instantiate-schema-moco.json"
+    },
+    {
+        "include" : "nslcm/vfc-nslcm-delete-schema-moco.json"
+    },
+    {
+        "include" : "nslcm/vfc-nslcm-terminate-schema-moco.json"
+    }
+]
\ No newline at end of file
index 0739258..9a7fd10 100644 (file)
@@ -1,15 +1,7 @@
 [ {
   "request" : {
     "method" : "post",
-    "uri" : "/api/nslcm/v1/ns",
-    "headers" : {
-      "Accept" : "application/json",
-      "Content-Type" : "application/json"
-    },
-    "json" : {
-      "csarId" : "a3394090-c5b4-49b4-974c-00a6eac755ab",
-      "nsName" : "vcpe1"
-    }
+    "uri" : "/api/nslcm/v1/ns"
   },
   "response" : {
     "status" : 201,
diff --git a/products/onap-dublin/features/vfc/src/main/resources/open-cli-sample/nslcm/vfc-nslcm-delete-schema-moco.json b/products/onap-dublin/features/vfc/src/main/resources/open-cli-sample/nslcm/vfc-nslcm-delete-schema-moco.json
new file mode 100644 (file)
index 0000000..de6743c
--- /dev/null
@@ -0,0 +1,10 @@
+[ {
+  "request" : {
+    "method" : "delete",
+    "uri" : "/api/nslcm/v1/ns/25f3159c-ff2d-4ad0-ac66-3270941bfa52"
+  },
+  "response" : {
+    "status" : 204,
+    "json" : null
+  }
+} ]
diff --git a/products/onap-dublin/features/vfc/src/main/resources/open-cli-sample/nslcm/vfc-nslcm-delete-schema-sample.yaml b/products/onap-dublin/features/vfc/src/main/resources/open-cli-sample/nslcm/vfc-nslcm-delete-schema-sample.yaml
new file mode 100644 (file)
index 0000000..4ce418b
--- /dev/null
@@ -0,0 +1,9 @@
+open_cli_sample_version: 1.0
+name: vfc-nslcm-delete
+version: onap-dublin
+samples:
+  sample1:
+    name: vfc-nslcm-delete
+    input: --host-url http://localhost:12306 --ns-instance-id 25f3159c-ff2d-4ad0-ac66-3270941bfa52
+    moco: vfc-nslcm-delete-schema-moco.json
+    output:
\ No newline at end of file
diff --git a/products/onap-dublin/features/vfc/src/main/resources/open-cli-sample/nslcm/vfc-nslcm-instantiate-schema-moco.json b/products/onap-dublin/features/vfc/src/main/resources/open-cli-sample/nslcm/vfc-nslcm-instantiate-schema-moco.json
new file mode 100644 (file)
index 0000000..94a357b
--- /dev/null
@@ -0,0 +1,12 @@
+[ {
+  "request" : {
+    "method" : "post",
+    "uri" : "/api/nslcm/v1/ns/25f3159c-ff2d-4ad0-ac66-3270941bfa52/instantiate"
+  },
+  "response" : {
+    "status" : 200,
+    "json" : {
+      "jobId" : "7b06898d-e67a-4c9f-b1ce-90346ed6e520"
+    }
+  }
+} ]
diff --git a/products/onap-dublin/features/vfc/src/main/resources/open-cli-sample/nslcm/vfc-nslcm-instantiate-schema-sample.yaml b/products/onap-dublin/features/vfc/src/main/resources/open-cli-sample/nslcm/vfc-nslcm-instantiate-schema-sample.yaml
new file mode 100644 (file)
index 0000000..bdda235
--- /dev/null
@@ -0,0 +1,14 @@
+open_cli_sample_version: 1.0
+name: vfc-nslcm-instantiate
+version: onap-dublin
+samples:
+  sample1:
+    name: vfc-nslcm-instantiate
+    input: --host-url http://localhost:12306 --ns-instance-id 25f3159c-ff2d-4ad0-ac66-3270941bfa52 --location OCOMP-lcm3_RegionOVP --sdn-controller-id 1
+    moco: vfc-nslcm-instantiate-schema-moco.json
+    output: |
+      +--------------------------------------+
+      |job-id                                |
+      +--------------------------------------+
+      |7b06898d-e67a-4c9f-b1ce-90346ed6e520  |
+      +--------------------------------------+
diff --git a/products/onap-dublin/features/vfc/src/main/resources/open-cli-sample/nslcm/vfc-nslcm-terminate-schema-moco.json b/products/onap-dublin/features/vfc/src/main/resources/open-cli-sample/nslcm/vfc-nslcm-terminate-schema-moco.json
new file mode 100644 (file)
index 0000000..f7d4363
--- /dev/null
@@ -0,0 +1,12 @@
+[ {
+  "request" : {
+    "method" : "post",
+    "uri" : "/api/nslcm/v1/ns/25f3159c-ff2d-4ad0-ac66-3270941bfa52/terminate"
+  },
+  "response" : {
+    "status" : 202,
+    "json" : {
+      "jobId" : "f479d5eb-82a1-4a1f-9174-e071ee46c841"
+    }
+  }
+} ]
diff --git a/products/onap-dublin/features/vfc/src/main/resources/open-cli-sample/nslcm/vfc-nslcm-terminate-schema-sample.yaml b/products/onap-dublin/features/vfc/src/main/resources/open-cli-sample/nslcm/vfc-nslcm-terminate-schema-sample.yaml
new file mode 100644 (file)
index 0000000..e6bdfbc
--- /dev/null
@@ -0,0 +1,14 @@
+open_cli_sample_version: 1.0
+name: vfc-nslcm-terminate
+version: onap-dublin
+samples:
+  sample1:
+    name: vfc-nslcm-terminate
+    input: --host-url http://localhost:12306 --ns-instance-id 25f3159c-ff2d-4ad0-ac66-3270941bfa52
+    moco: vfc-nslcm-terminate-schema-moco.json
+    output: |
+      +--------------------------------------+
+      |job-id                                |
+      +--------------------------------------+
+      |f479d5eb-82a1-4a1f-9174-e071ee46c841  |
+      +--------------------------------------+
index 4850e07..cda2e7f 100644 (file)
@@ -29,14 +29,6 @@ parameters:
     long_option: ns-instance-id
     is_optional: false
 
-results:
-  direction: landscape
-  attributes:
-    - name: status
-      description: status
-      scope: short
-      type: string
-
 http:
   service:
     auth: none
@@ -52,5 +44,4 @@ http:
       Accept: application/json
   success_codes:
     - 204
-  result_map:
-    status: ${success_codes}
+
index d6fa439..984a1dc 100644 (file)
@@ -22,7 +22,7 @@ info:
   author: ONAP HPA Integration Team (haibin.huang@intel.com)
 
 results:
-  direction: landscape
+  direction: portrait
   attributes:
     - name: ns-instance-id
       description: ns-instance-id
index b2e2dc8..37c5140 100644 (file)
@@ -28,15 +28,18 @@ public class SampleYamlGenerator {
     static int nTab;
 
     public static void generateSampleYaml(String cmdName, List<String> input, String output, String version,
-            String targetPath, boolean debug) throws IOException {
+            String targetPath, boolean debug, String name) throws IOException {
 
         PrintWriter writer = new PrintWriter(targetPath, "UTF-8");
         writeKeyValuePair(writer, "open_cli_sample_version", "1.0");
         writeKeyValuePair(writer, "name", cmdName);
         writeKeyValuePair(writer, "version", version);
 
+        if (name == null) {
+            name = "sample1";
+        }
         writeKey(writer, "samples");
-        writeKey(writer, "sample1");
+        writeKey(writer, name);
 
         writeKeyValuePair(writer, "name", cmdName);
         writeKeyValuePair(writer, "input", input.stream().collect(Collectors.joining(" ")).trim());
index fba93e6..cd39583 100644 (file)
@@ -26,7 +26,7 @@ public class SampleYamlGeneratorTest {
     @Test
     public void testGenerateSampleYaml() throws IOException {
         SampleYamlGenerator.generateSampleYaml("testcmd", Arrays.asList("-a", "argument"),
-                "+--------+\n+val     +\n+argument+", "test-version-1.0", "target/test.yaml", false);
+                "+--------+\n+val     +\n+argument+", "test-version-1.0", "target/test.yaml", false, "sample1");
     }
 
 }