diff options
author | k.kedron <k.kedron@partner.samsung.com> | 2020-02-28 14:26:07 +0100 |
---|---|---|
committer | Ofir Sonsino <ofir.sonsino@intl.att.com> | 2020-03-23 09:48:56 +0000 |
commit | 5944b441468500fffa7111b5dea9181461ae1303 (patch) | |
tree | 9b358b2d25a309c1d6dfd86227ec75b52b2ccefa /catalog-be/src/main/resources/scripts/import/tosca/upgradeNormative.py | |
parent | ec7da6aea30a1b73d1e0f5f75d2b6119ed8fa251 (diff) |
Refactoring the sdc-BE-init python scripts
Adjust to the correct python syntax.
Remove not used imports.
Also fixed:
- the indents
- checking that all normative imported correctly logic
Issue-ID: SDC-2784
Signed-off-by: Krystian Kedron <k.kedron@partner.samsung.com>
Change-Id: If7edc867f3cb591be157073fbc12b9842b200023
Diffstat (limited to 'catalog-be/src/main/resources/scripts/import/tosca/upgradeNormative.py')
-rw-r--r-- | catalog-be/src/main/resources/scripts/import/tosca/upgradeNormative.py | 109 |
1 files changed, 55 insertions, 54 deletions
diff --git a/catalog-be/src/main/resources/scripts/import/tosca/upgradeNormative.py b/catalog-be/src/main/resources/scripts/import/tosca/upgradeNormative.py index 36a5d1181a..c8f5ecf9e6 100644 --- a/catalog-be/src/main/resources/scripts/import/tosca/upgradeNormative.py +++ b/catalog-be/src/main/resources/scripts/import/tosca/upgradeNormative.py @@ -1,22 +1,18 @@ -import pycurl -import sys, getopt, os -from StringIO import StringIO -import json -import copy +import os import time + +import importCommon +from importAnnotationTypes import import_annotation_types from importCategoryTypes import importCategories -from upgradeHeatAndNormativeTypes import upgradeTypesPerConfigFile +from importCommon import * from importDataTypes import importDataTypes -from importPolicyTypes import importPolicyTypes from importGroupTypes import importGroupTypes from importNormativeCapabilities import importNormativeCapabilities -from importNormativeRelationships import importNormativeRelationships from importNormativeInterfaceLifecycleTypes import importNormativeInterfaceLifecycleType -from importAnnotationTypes import import_annotation_types - +from importNormativeRelationships import importNormativeRelationships +from importPolicyTypes import importPolicyTypes +from upgradeHeatAndNormativeTypes import upgradeTypesPerConfigFile -from importCommon import * -import importCommon ################################################################################################################################################################################################################################# # # @@ -31,99 +27,104 @@ import importCommon # # ################################################################################################################################################################################################################################# + def usage(): - print sys.argv[0], '[optional -s <scheme> | --scheme=<scheme>, default http] [-i <be host> | --ip=<be host>] [-p <be port> | --port=<be port> ] [-u <user userId> | --user=<user userId> ] [-d <true|false> | --debug=<true|false>]' + print sys.argv[0], \ + '[optional -s <scheme> | --scheme=<scheme>, default http] [-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): +def handleResults(results): print_frame_line() for result in results: print_name_and_return_code(result[0], result[1]) print_frame_line() - failedResults = filter(lambda x: x[1] == None or x[1] not in [200, 201, 409], results) - if (len(failedResults) > 0): + failed_results = filter(lambda x: x[1] is None or x[1] not in [200, 201, 409], results) + if len(list(failed_results)) > 0: error_and_exit(1, None) + def main(argv): print 'Number of arguments:', len(sys.argv), 'arguments.' - beHost = 'localhost' - bePort = '8080' - adminUser = 'jh0003' - debugf = None - updateversion = 'true' + be_host = 'localhost' + be_port = '8080' + admin_user = 'jh0003' + debug_f = None + update_version = 'true' importCommon.debugFlag = False scheme = 'http' try: - opts, args = getopt.getopt(argv,"i:p:u:d:h:s:",["ip=","port=","user=","debug=","scheme="]) + opts, args = getopt.getopt(argv, "i:p:u:d:h:s:", ["ip=", "port=", "user=", "debug=", "scheme="]) except getopt.GetoptError: usage() error_and_exit(2, 'Invalid input') for opt, arg in opts: - #print opt, arg + # print opt, arg if opt == '-h': usage() sys.exit(3) elif opt in ("-i", "--ip"): - beHost = arg + be_host = arg elif opt in ("-p", "--port"): - bePort = arg + be_port = arg elif opt in ("-u", "--user"): - adminUser = arg + admin_user = arg elif opt in ("-s", "--scheme"): scheme = arg elif opt in ("-d", "--debug"): print arg - debugf = bool(arg.lower() == "true" or arg.lower() == "yes") + debug_f = bool(arg.lower() == "true" or arg.lower() == "yes") - print 'scheme =',scheme,', be host =',beHost,', be port =', bePort,', user =', adminUser, ', debug =', debugf + print 'scheme =', scheme, ', be host =', be_host, ', be port =', be_port, ', user =', admin_user, ', debug =', debug_f - if (debugf != None): - print 'set debug mode to ' + str(debugf) - importCommon.debugFlag = debugf + if debug_f is not None: + print 'set debug mode to ' + str(debug_f) + importCommon.debugFlag = debug_f - if ( beHost == None ): + if be_host is None: usage() sys.exit(3) print sys.argv[0] - pathdir = os.path.dirname(os.path.realpath(sys.argv[0])) - debug("path dir =" + pathdir) + path_dir = os.path.dirname(os.path.realpath(sys.argv[0])) + debug("path dir =" + path_dir) - baseFileLocation = pathdir + "/../../../import/tosca/" + base_file_location = path_dir + "/../../../import/tosca/" - fileLocation = baseFileLocation + "categories/" - importCategories(scheme, beHost, bePort, adminUser, False, fileLocation) + file_location = base_file_location + "categories/" + importCategories(scheme, be_host, be_port, admin_user, False, file_location) - fileLocation = baseFileLocation + "relationship-types/" - importNormativeRelationships(scheme, beHost, bePort, adminUser, False, fileLocation) + file_location = base_file_location + "relationship-types/" + importNormativeRelationships(scheme, be_host, be_port, admin_user, False, file_location) - fileLocation = baseFileLocation + "data-types/" - importDataTypes(scheme, beHost, bePort, adminUser, False, fileLocation) + file_location = base_file_location + "data-types/" + importDataTypes(scheme, be_host, be_port, admin_user, False, file_location) - fileLocation = baseFileLocation + "policy-types/" - importPolicyTypes(scheme, beHost, bePort, adminUser, False, fileLocation) + file_location = base_file_location + "policy-types/" + importPolicyTypes(scheme, be_host, be_port, admin_user, False, file_location) - fileLocation = baseFileLocation + "capability-types/" - importNormativeCapabilities(scheme, beHost, bePort, adminUser, False, fileLocation) + file_location = base_file_location + "capability-types/" + importNormativeCapabilities(scheme, be_host, be_port, admin_user, False, file_location) - fileLocation = baseFileLocation + "group-types/" - importGroupTypes(scheme, beHost, bePort, adminUser, False, fileLocation) + file_location = base_file_location + "group-types/" + importGroupTypes(scheme, be_host, be_port, admin_user, False, file_location) - fileLocation = baseFileLocation + "interface-lifecycle-types/" - importNormativeInterfaceLifecycleType(scheme, beHost, bePort, adminUser, False, fileLocation) + file_location = base_file_location + "interface-lifecycle-types/" + importNormativeInterfaceLifecycleType(scheme, be_host, be_port, admin_user, False, file_location) - import_annotation_types(scheme, beHost, bePort, adminUser, False) + import_annotation_types(scheme, be_host, be_port, admin_user, False) print 'sleep until data type cache is updated' - time.sleep( 70 ) + time.sleep(70) - resultsHeat = upgradeTypesPerConfigFile(scheme, beHost, bePort, adminUser, baseFileLocation, updateversion) - handleResults(resultsHeat, 'false') + results_heat = upgradeTypesPerConfigFile(scheme, be_host, be_port, admin_user, base_file_location, update_version) + handleResults(results_heat) error_and_exit(0, None) + if __name__ == "__main__": - main(sys.argv[1:]) + main(sys.argv[1:]) |