diff options
author | Gitelman, Tal (tg851x) <tg851x@intl.att.com> | 2018-03-14 20:04:22 +0200 |
---|---|---|
committer | Michael Lando <ml636r@att.com> | 2018-03-14 18:08:16 +0000 |
commit | b247b7b1d89aec6cf9bc46782b49903277b725e7 (patch) | |
tree | 039271c18495c812a2e4d1ad87b3e238e70f0727 | |
parent | 8b9114fc27e1849179e31c713bbd54c2119ee154 (diff) |
Onap normatives are imported always
Change-Id: I3f35be9732a4b0ddba268debe1766976402fa560
Issue-ID: SDC-1103
Signed-off-by: Gitelman, Tal (tg851x) <tg851x@intl.att.com>
4 files changed, 129 insertions, 14 deletions
diff --git a/catalog-be/sdc-backend-init/chef-repo/cookbooks/sdc-catalog-be-setup/recipes/3_import_Normatives.rb b/catalog-be/sdc-backend-init/chef-repo/cookbooks/sdc-catalog-be-setup/recipes/3_import_Normatives.rb index d5f0ff4095..a8d474b792 100644 --- a/catalog-be/sdc-backend-init/chef-repo/cookbooks/sdc-catalog-be-setup/recipes/3_import_Normatives.rb +++ b/catalog-be/sdc-backend-init/chef-repo/cookbooks/sdc-catalog-be-setup/recipes/3_import_Normatives.rb @@ -16,7 +16,12 @@ bash "excuting-import_Normatives" do # add --debug=true to the importNormativeAll.py arguments to enable debug check_normative="/tmp/check_normative.out" - curl -s -X GET -H "Content-Type: application/json;charset=UTF-8" -H "USER_ID: jh0003" -H "X-ECOMP-RequestID: cbe744a0-037b-458f-aab5-df6e543c4090" "http://#{be_ip}:8080/sdc2/rest/v1/screen" > ${check_normative} + status_code=$(curl -s -o ${check_normative} -w "%{http_code}\\n" -X GET -H 'Content-Type: application/json;charset=UTF-8' -H 'USER_ID: jh0003' -H 'X-ECOMP-RequestID: cbe744a0-037b-458f-aab5-df6e543c4090' "http://#{be_ip}:8080/sdc2/rest/v1/screen") + if [ "$status_code" != 200 ] ; then + exit "$status_code" + fi + + #curl -s -X GET -H "Content-Type: application/json;charset=UTF-8" -H "USER_ID: jh0003" -H "X-ECOMP-RequestID: cbe744a0-037b-458f-aab5-df6e543c4090" "http://#{be_ip}:8080/sdc2/rest/v1/screen" > ${check_normative} resources_len=`cat ${check_normative}| jq '.["resources"]|length'` mkdir -p /var/lib/jetty/logs diff --git a/catalog-be/src/main/resources/scripts/import/tosca/onapTypesToUpgrade.json b/catalog-be/src/main/resources/scripts/import/tosca/onapTypesToUpgrade.json new file mode 100644 index 0000000000..6045ddd6ff --- /dev/null +++ b/catalog-be/src/main/resources/scripts/import/tosca/onapTypesToUpgrade.json @@ -0,0 +1,4 @@ +{ + "onap": [ + ] +}
\ No newline at end of file diff --git a/catalog-be/src/main/resources/scripts/import/tosca/upgradeONAPNormative.py b/catalog-be/src/main/resources/scripts/import/tosca/upgradeONAPNormative.py index b272c2726c..21a477503c 100644 --- a/catalog-be/src/main/resources/scripts/import/tosca/upgradeONAPNormative.py +++ b/catalog-be/src/main/resources/scripts/import/tosca/upgradeONAPNormative.py @@ -11,7 +11,7 @@ from importPolicyTypes import importPolicyTypes from importGroupTypes import importGroupTypes from importNormativeCapabilities import importNormativeCapabilities from importNormativeInterfaceLifecycleTypes import importNormativeInterfaceLifecycleType -from importOnapTypes import importOnapTypes +from upgradeONAPTypes import upgradeOnapTypesPerConfigFile from importCommon import * @@ -33,15 +33,17 @@ import importCommon def usage(): print sys.argv[0], '[-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ] [-d <true|false> | --debug=<true|false>]' -def handleResults(results, updateversion): - printFrameLine() - for result in results: - printNameAndReturnCode(result[0], result[1]) - printFrameLine() +def handleResults(results): + if results is not None: + printFrameLine() + for result in results: + printNameAndReturnCode(result[0], result[1]) + + printFrameLine() - failedResults = filter(lambda x: x[1] == None or x[1] not in [200, 201, 409], results) - if (len(failedResults) > 0): - errorAndExit(1, None) + failedResults = filter(lambda x: x[1] == None or x[1] not in [200, 201, 409], results) + if (len(failedResults) > 0): + errorAndExit(1, None) def main(argv): print 'Number of arguments:', len(sys.argv), 'arguments.' @@ -51,6 +53,7 @@ def main(argv): adminUser = 'jh0003' debugf = None updateversion = 'true' + updateOnapVersion = 'false' importCommon.debugFlag = False scheme = 'http' @@ -115,11 +118,10 @@ def main(argv): time.sleep( 70 ) resultsHeat = upgradeTypesPerConfigFile(scheme, beHost, bePort, adminUser, baseFileLocation, updateversion) - handleResults(resultsHeat, 'false') + handleResults(resultsHeat) - fileLocation = baseFileLocation + "onap-types/" - resultsHeat = importOnapTypes(scheme, beHost, bePort, adminUser, fileLocation, updateversion) - handleResults(resultsHeat, updateversion) + resultsHeat = upgradeOnapTypesPerConfigFile(scheme, beHost, bePort, adminUser, baseFileLocation, updateOnapVersion) + handleResults(resultsHeat) errorAndExit(0, None) diff --git a/catalog-be/src/main/resources/scripts/import/tosca/upgradeONAPTypes.py b/catalog-be/src/main/resources/scripts/import/tosca/upgradeONAPTypes.py new file mode 100644 index 0000000000..edf5a194f6 --- /dev/null +++ b/catalog-be/src/main/resources/scripts/import/tosca/upgradeONAPTypes.py @@ -0,0 +1,104 @@ +import pycurl +import sys, getopt +from StringIO import StringIO +import json +import copy +from importCommon import * +from importNormativeTypes import * +import importCommon +import json + + +################################################################################################################################################################################################ +# # +# Upgrades all Heat and Normative types confiugred in "typesToUpgrade.json" file # +# # +# activation # +# python upgradeHeatAndNormativeTypes.py [-s <scheme> | --scheme=<scheme> ] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-f <input file> | --ifile=<input file> ] # +# # +# shortest activation (be host = localhost, be port = 8080): # +# python upgradeHeatAndNormativeTypes.py [-f <input file> | --ifile=<input file> ] # +# # +################################################################################################################################################################################################ +def upgradeOnapTypesPerConfigFile(scheme, beHost, bePort, adminUser, baseDir, updateversion): + responseCodes = [200, 201] + if (updateversion == 'false'): + responseCodes = [200, 201, 409] + with open("onapTypesToUpgrade.json", 'r') as stream: + try: + types = json.load(stream) + onapTypes = types["onap"] + debug(onapTypes) + onapFileDir = baseDir + "onap-types/" + debug(onapFileDir) + results = [] + for onapType in onapTypes: + result = createNormativeType(scheme, beHost, bePort, adminUser, onapFileDir, onapType.encode('ascii', 'ignore'), updateversion) + results.append(result) + if (result[1] == None or result[1] not in responseCodes): + print "Failed creating onap type " + onapType + ". " + str(result[1]) + except yaml.YAMLError as exc: + print(exc) + + + +def main(argv): + print 'Number of arguments:', len(sys.argv), 'arguments.' + + beHost = 'localhost' + bePort = '8080' + adminUser = 'jh0003' + updateversion = 'true' + scheme = 'http' + + try: + opts, args = getopt.getopt(argv, "i:p:u:v:h:s:", ["ip=", "port=", "user=", "updateversion=","scheme="]) + except getopt.GetoptError: + usage() + errorAndExit(2, 'Invalid input') + + for opt, arg in opts: + # print opt, arg + if opt == '-h': + usage() + sys.exit(3) + elif opt in ("-i", "--ip"): + beHost = arg + elif opt in ("-p", "--port"): + bePort = arg + elif opt in ("-u", "--user"): + adminUser = arg + elif opt in ("-s", "--scheme"): + scheme = arg + elif opt in ("-v", "--updateversion"): + if (arg.lower() == "false" or arg.lower() == "no"): + updateversion = 'false' + + print 'scheme =',scheme,', be host =',beHost, ', be port =', bePort, ', user =', adminUser + + if (beHost == None): + usage() + sys.exit(3) + + results = upgradeOnapTypesPerConfigFile(scheme, beHost, bePort, adminUser, "../../../import/tosca/", updateversion) + + print "-----------------------------" + for result in results: + print "{0:20} | {1:6}".format(result[0], result[1]) + print "-----------------------------" + + responseCodes = [200, 201] + + if (updateversion == 'false'): + responseCodes = [200, 201, 409] + + failedNormatives = filter(lambda x: x[1] == None or x[1] not in responseCodes, results) + if (len(failedNormatives) > 0): + errorAndExit(1, None) + else: + errorAndExit(0, None) + + +if __name__ == "__main__": + main(sys.argv[1:]) + |