summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-be/src/main')
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/onapTypesToUpgrade.json4
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/upgradeONAPNormative.py28
-rw-r--r--catalog-be/src/main/resources/scripts/import/tosca/upgradeONAPTypes.py104
3 files changed, 123 insertions, 13 deletions
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:])
+