Add SDC automatioin

Attention, maybe you can't use it because we call internal SDC API
SDC PTL said that they will change internal SDC API without any
notice.

Change-Id: Ic1a34bb6f9d3a879f8d5580c803431059ca43c26
Issue-ID: INT-795
Signed-off-by: Haibin Huang <haibin.huang@intel.com>
diff --git a/test/hpa_automation/tosca/hpa_automation.py b/test/hpa_automation/tosca/hpa_automation.py
index b83d3eb..26ee834 100755
--- a/test/hpa_automation/tosca/hpa_automation.py
+++ b/test/hpa_automation/tosca/hpa_automation.py
@@ -48,6 +48,138 @@
 
     os.system(complex_create_string)
 
+def create_vlm(parameters):
+    vlm_create_string = "oclip vlm-create -x {} -u {} -p {} -m {}".format(parameters["vendor-name"], \
+      parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_onboarding_url"])
+    command_out = (os.popen(vlm_create_string)).read()
+    out_list = get_out_helper(command_out)
+    vlm_id = out_list[3]
+    vlm_version = out_list[5]
+
+    entitlement_string = "oclip vlm-entitlement-pool-create -x {} -y {} -e {} -z {} -k {} -g {} -l {} -u {} -p {} -m {}".format( \
+      parameters["entitlement-pool-name"], vlm_id, vlm_version, parameters["entitlement-description"], parameters["vendor-name"], \
+      parameters["expiry-date"], parameters["start-date"],  parameters["sdc_creator"], parameters["sdc_password"], \
+      parameters["sdc_onboarding_url"])
+    command_out = (os.popen(entitlement_string)).read()
+    entitlement_id = (get_out_helper(command_out))[3]
+
+
+    key_group_string = "oclip vlm-key-group-create -c {} -e {} -x {} -y {} -u {} -p {} -m {}".format(vlm_id, vlm_version, \
+      parameters["key-group-name"], parameters["key-group-type"],  parameters["sdc_creator"], parameters["sdc_password"], \
+      parameters["sdc_onboarding_url"])
+    command_out = (os.popen(key_group_string)).read()
+    key_group_id = (get_out_helper(command_out))[3]
+
+    feature_group_string = "oclip vlm-feature-group-create -x {} -y {} -e {} -z {} -g {} -b {} -c {} -u {} -p {} -m {}".format(
+      parameters["feature-grp-name"], vlm_id, vlm_version, parameters["feature-grp-desc"], key_group_id, entitlement_id, \
+      parameters["part-no"], parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_onboarding_url"])
+    command_out = (os.popen(feature_group_string)).read()
+    feature_group_id = (get_out_helper(command_out))[3]
+
+    agreement_string = "oclip vlm-aggreement-create -x {} -y {} -e {} -z {} -g {} -u {} -p {} -m {}".format(parameters["agreement-name"], \
+      vlm_id, vlm_version, parameters["agreement-desc"], feature_group_id, parameters["sdc_creator"], parameters["sdc_password"], \
+      parameters["sdc_onboarding_url"])
+    command_out = (os.popen(agreement_string)).read()
+    agreement_id = (get_out_helper(command_out))[3]
+
+    submit_string = "oclip vlm-submit -x {} -y {} -u {} -p {} -m {}".format(vlm_id, vlm_version, parameters["sdc_creator"], \
+      parameters["sdc_password"], parameters["sdc_onboarding_url"])
+    os.system(submit_string)
+
+    output = [feature_group_id, agreement_id, vlm_version, vlm_id ]
+    return output
+
+def create_vsp(parameters, in_list):
+    vnfs = parameters["vnf"]
+    vsp_dict = {}
+    for name, value in vnfs.iteritems():
+        create_string = "oclip vsp-create -j {} -o {} -e {} -x {} -y {} -i {} -c {} -g {} -u {} -p {} -m {}".format( in_list[0], \
+          parameters["onboarding-method"], parameters["vendor-name" ], value.get("vsp-name"), value.get("vsp-desc"), in_list[1], \
+          in_list[2], in_list[3], parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_onboarding_url"] )
+        command_out = (os.popen(create_string)).read()
+        out_list = get_out_helper(command_out)
+        vsp_id = out_list[3]
+        vsp_version = out_list[5]
+
+        os.system("oclip vsp-add-artifact -x {} -y {} -z {} -u {} -p {} -m {}".format(vsp_id, vsp_version, value.get("path"), \
+          parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_onboarding_url"]))
+
+        os.system("oclip vsp-validate -x {} -y {} -u {} -p {} -m {}".format(vsp_id, vsp_version, parameters["sdc_creator"], \
+          parameters["sdc_password"], parameters["sdc_onboarding_url"]))
+
+        os.system("oclip vsp-submit -x {} -y {} -u {} -p {} -m {}".format(vsp_id, vsp_version, parameters["sdc_creator"], \
+          parameters["sdc_password"], parameters["sdc_onboarding_url"]))
+
+        os.system("oclip vsp-package -x {} -y {} -u {} -p {} -m {}".format(vsp_id, vsp_version, parameters["sdc_creator"], \
+          parameters["sdc_password"], parameters["sdc_onboarding_url"]))
+
+        vsp_ids[name] = vsp_id
+    return vsp_ids
+
+def create_vf_model(parameters, vsp_dict):
+    vnfs = parameters["vnfs"]
+    vf_dict = {}
+    for name, value in vnfs.iteritems():
+        create_string = "oclip vf-model-create -y {} -g {} -x {} -z {} -b {} -u {} -p {} -m {}".format(value.get("vf-description"), \
+          value.get("vsp-version"), value.get("vf-name"), parameters["vendor-name"], vsp_dict[name], \
+          parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_catalog_url"])
+        os.system(create_string)
+
+        output = (os.popen("oclip vf-model-list -m {} -u {} -p {} | grep {}".format(parameters["sdc_catalog_url"], \
+          parameters["sdc_creator"], parameters["sdc_password"], value.get("vf-name")))).read()
+        output = (get_out_helper_2(output))
+
+        vf_unique_id = output[1]
+
+        os.system("oclip vf-model-certify -b {} -r {} -u {} -p {} -m {}".format(vf_unique_id, value.get("vf-remarks"), \
+          parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_catalog_url"]))
+
+        #Check for new parameters after certification
+        output = (os.popen("oclip vf-model-list -m {} -u {} -p {} | grep {}".format(parameters["sdc_catalog_url"], \
+                              parameters["sdc_creator"], parameters["sdc_password"], value.get("vf-name")))).read()
+        output = (get_out_helper_2(output))
+
+        vf_dict[name] = output[1]
+
+    return vf_dict
+
+
+def create_service_model(parameters, vf_dict):
+    vnfs = parameters["vnfs"]
+
+    create_string = "oclip service-model-create -z {} -y {} -e {} -x {} -c {} -b {} -u {} -p {} -m {} |grep ID".format(parameters["project-code"], \
+    parameters["service-model-desc"], parameters["icon-id"], parameters["service-model-name"], parameters["category-display"], \
+    parameters["category"],parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_catalog_url"])
+
+    service_model_id = (get_out_helper_2((os.popen(create_string)).read()))[1]
+
+    for name, value in vnfs.iteritems():
+        os.system("oclip service-model-add-vf -x {} -b {} -y {} -z {} -u {} -p {} -m {}".format(service_model_id, \
+                   parameters["vf-version"], vf_dict[name], value.get("vf-name"), parameters["sdc_creator"], \
+                   parameters["sdc_password"], parameters["sdc_catalog_url"] ))
+
+    os.system("oclip service-model-test-request -b {} -r {} -u {} -p {} -m {}".format(service_model_id, parameters["service-test-remarks"], \
+    parameters["sdc_creator"], parameters["sdc_password"], parameters["sdc_catalog_url"]))
+
+    os.system("oclip service-model-test-start -b {} -u {} -p {} -m {}".format(service_model_id, parameters["sdc_tester"], \
+    parameters["sdc_password"], parameters["sdc_catalog_url"]))
+
+    os.system("oclip service-model-test-accept -b {} -r {} -u {} -p {} -m {}".format(service_model_id, parameters["service-accept-remarks"], \
+    parameters["sdc_tester"], parameters["sdc_password"], parameters["sdc_catalog_url"]))
+
+    #Get uniqueId for the service model
+    service_model_values = (os.popen("oclip service-model-list -u {} -p {} -m {} |grep {}".format(parameters["sdc_creator"], \
+      parameters["sdc_password"], parameters["sdc_catalog_url"], parameters["service-model-name"]))).read()
+    service_model_values = get_out_helper_2(service_model_values)
+    service_model_uniqueId = (service_model_values)[1]
+
+    os.system("oclip service-model-approve -b {} -r {} -u {} -p {} -m {}".format(service_model_uniqueId, parameters["service-approve-remarks"], \
+    parameters["sdc_governor"], parameters["sdc_password"], parameters["sdc_catalog_url"]))
+
+    os.system("oclip service-model-distribute -b {} -u {} -p {} -m {}".format(service_model_uniqueId, parameters["sdc_operator"], \
+    parameters["sdc_password"], parameters["sdc_catalog_url"]))
+
+    return service_model_values
 
 def register_cloud_helper(cloud_region, values, parameters):
     #Create Cloud
@@ -203,13 +335,14 @@
 #Run Functions
 parser = argparse.ArgumentParser()
 parser.add_argument('-f', action='store', dest='config_file_path', help='Store config file path')
-parser.add_argument('-t', action='store', dest='type', help='Store config file path')
+parser.add_argument('-t', action='store', dest='model', help='Store config file path')
 
 parser.add_argument('--version', action='version', version='%(prog)s 1.0')
 
 results = parser.parse_args()
 
 config_file_path = results.config_file_path
+model = results.model
 if config_file_path is None:
     sys.exit(1)
 config_file = open(config_file_path)
@@ -234,12 +367,17 @@
 # We just do run time automation 
 ns_package_output = ""
 
-if type == "sdc":
+if model == "sdc":
     print "use csar file is distributed by sdc"
-    # vnf_onboard_output = onboard_vnf(parameters)
-    # print vnf_onboard_output
-    # ns_onboard_out = onboard_ns(parameters)
-    # print ns_onboard_out
+    output = create_vlm(parameters)
+    vsp_dict = create_vsp(parameters, output)
+    vf_dict = create_vf_model(parameters, vsp_dict)
+    service_model_list = create_service_model(parameters, vf_dict)
+    #
+    vnf_onboard_output = onboard_vnf(parameters)
+    print vnf_onboard_output
+    ns_onboard_out = onboard_ns(parameters)
+    print ns_onboard_out
 else:
     print "use csar file is uploaded by local"
     vnf_package_output = create_vnf_package(parameters)
@@ -256,6 +394,7 @@
 
 # 7. VFC part
 ns_instance_id = create_ns(parameters, ns_package_output)
+ns_instance_id = "d0ecc83f-339f-4621-b565-07eb9090a379"
 print ns_instance_id
 instantiate_ns_output = instantiate_ns(parameters, ns_instance_id)
 print instantiate_ns_output
diff --git a/test/hpa_automation/tosca/vcpe_config.json b/test/hpa_automation/tosca/vcpe_config.json
index 3daba8a..811124d 100755
--- a/test/hpa_automation/tosca/vcpe_config.json
+++ b/test/hpa_automation/tosca/vcpe_config.json
@@ -4,9 +4,13 @@
     "aai_url" : "https://10.12.5.224:30233",
     "aai_username" : "AAI",
     "aai_password" : "AAI",
-    "sdc_catalog_url" : "http://10.12.6.235:30205",
+    "sdc_onboarding_url" : "http://10.12.5.202:8081",
+    "sdc_catalog_url" : "http://10.12.5.180:30205",
     "sdc_password" : "demo123456!",
     "sdc_creator" : "cs0008",
+    "sdc_tester" : "jm0007",
+    "sdc_governor" : "gv0001",
+    "sdc_operator" : "op0001",
 
     "multicloud_url" : "http://10.12.5.224:30280",
     "policy_url" : "https://10.12.6.235:30240",
@@ -93,36 +97,103 @@
     "owner-defined-type" : "t1",
     "cloud-zone" : "CloudZone",
 
+    "service_name" : "vCPE",
+    "customer_name" : "hpa_cust",
+    "subscriber_name" : "hpa_cust",
+
+    "//" : "Onboarding parameters",
+    "vendor-name" : "Intel",
+    "entitlement-pool-name" : "hpa-pool",
+    "entitlement-description" : "hpa-pool",
+    "start-date" : "04/23/2019",
+    "expiry-date" : "12/31/2040",
+    "key-group-name" : "hpa-key",
+    "key-group-type" : "Universal",
+    "feature-grp-name" : "hpa-feature",
+    "feature-grp-desc" : "hpa-feature",
+    "part-no" : "hpa-part",
+    "agreement-name" : "hpa-agreement",
+    "agreement-desc" : "hpa-agreement",
+
+    "onboarding-method" : "NetworkPackage",
+
+    "//" : "Be sure to include single quotes in parameters that have spaces",
+    "project-code" : "000000",
+    "service-model-name" : "vcpe-hpa",
+    "service-model-desc" : "'hpa service model'",
+    "icon-id" : "network_l_1-3",
+    "category-display" : "'Network L1-3'",
+    "category" : "'network l1-3'",
+
+    "service-test-remarks" : "test",
+    "service-accept-remarks" : "accepted",
+    "service-approve-remarks" : "approved",
+
     "//" : "#Parameters to vfc",
     "vfc-url": "http://10.12.6.88:30280",
     "vnfs":{
         "infra":{
             "path": "/root/oclip/dublin/infra.csar",
             "csar-id": "You need change it",
+            "vsp-name" : "infra-hpa-vsp",
+            "vsp-desc" : "infra-hpa-vsp-desc",
+            "vsp-version" : "1.0",
+            "vf-name" : "infra-hpa-vf",
+            "vf-description" : "infra-hpa-vf",
+            "vf-remarks" :"remarkss",
+            "vf-version" : "1.0",
             "key": "key2",
             "value": "value2"
         },
         "vgmux":{
             "path": "/root/oclip/dublin/vgmux.csar",
             "csar-id": "You need change it",
+            "vsp-name" : "vgmux-hpa-vsp",
+            "vsp-desc" : "vgmux-hpa-vsp-desc",
+            "vsp-version" : "1.0",
+            "vf-name" : "vgmux-hpa-vf",
+            "vf-description" : "vgmux-hpa-vf",
+            "vf-remarks" :"remarkss",
+            "vf-version" : "1.0",
             "key": "key2",
             "value": "value2"
         },
         "vbng":{
             "path": "/root/oclip/dublin/vbng.csar",
             "csar-id": "You need change it",
+            "vsp-name" : "vbng-hpa-vsp",
+            "vsp-desc" : "vbng-hpa-vsp-desc",
+            "vsp-version" : "1.0",
+            "vf-name" : "vbng-hpa-vf",
+            "vf-description" : "vbng-hpa-vf",
+            "vf-remarks" :"remarkss",
+            "vf-version" : "1.0",
             "key": "key2",
             "value": "value2"
         },
         "vbrgemu":{
             "path": "/root/oclip/dublin/vbrgemu.csar",
             "csar-id": "You need change it",
+            "vsp-name" : "vbrgemu-hpa-vsp",
+            "vsp-desc" : "vbgremu-hpa-vsp-desc",
+            "vsp-version" : "1.0",
+            "vf-name" : "vbgremu-hpa-vf",
+            "vf-description" : "vbgremu-hpa-vf",
+            "vf-remarks" :"remarkss",
+            "vf-version" : "1.0",
             "key": "key2",
             "value": "value2"
         },
         "vgw":{
 	    "path": "/opt/oclip/dublin/vgw.csar",
 	    "csar-id": "You need change it",
+            "vsp-name" : "vgw-hpa-vsp",
+            "vsp-desc" : "vgw-hpa-vsp-desc",
+            "vsp-version" : "1.0",
+            "vf-name" : "vgw-hpa-vf",
+            "vf-description" : "vgw-hpa-vf",
+            "vf-remarks" :"remarkss",
+            "vf-version" : "1.0",
 	    "key": "key2",
 	    "value": "value2"
 	}