summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main/resources/scripts/sdcBePy/tosca
diff options
context:
space:
mode:
authork.kedron <k.kedron@partner.samsung.com>2020-06-05 14:51:01 +0200
committerKrystian Kedron <k.kedron@partner.samsung.com>2020-06-24 09:21:00 +0000
commit16fe29ac226610f79c8da1f691437ec7fe6e79c4 (patch)
tree5b73d8f1724c561609c05fd2802ad80b7acfb4c0 /catalog-be/src/main/resources/scripts/sdcBePy/tosca
parentfca8a0b1af32083b8ea025135b120091aec9714f (diff)
Improvement sdc-BE-init python scripts
- Implemented retries when request fail - Moved configuration variables to the Properties file - Extended sdcBeProxy - Implemented script to run import/update (should fix deployment glitch) - Updated the import_Normatives recipes to use new script Issue-ID: SDC-2784 Signed-off-by: Krystian Kedron <k.kedron@partner.samsung.com> Change-Id: I83fab898783ad8d3b3d532af43d75bc54d033c33
Diffstat (limited to 'catalog-be/src/main/resources/scripts/sdcBePy/tosca')
-rw-r--r--catalog-be/src/main/resources/scripts/sdcBePy/tosca/data/beConfig.json5
-rw-r--r--catalog-be/src/main/resources/scripts/sdcBePy/tosca/imports/run.py29
-rw-r--r--catalog-be/src/main/resources/scripts/sdcBePy/tosca/main.py22
-rw-r--r--catalog-be/src/main/resources/scripts/sdcBePy/tosca/run.py29
-rw-r--r--catalog-be/src/main/resources/scripts/sdcBePy/tosca/upgrade/run.py29
5 files changed, 75 insertions, 39 deletions
diff --git a/catalog-be/src/main/resources/scripts/sdcBePy/tosca/data/beConfig.json b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/data/beConfig.json
index f8c740b94f..556e561153 100644
--- a/catalog-be/src/main/resources/scripts/sdcBePy/tosca/data/beConfig.json
+++ b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/data/beConfig.json
@@ -1,5 +1,8 @@
{
"beHost": "localhost",
"bePort": "8080",
- "adminUser": "jh0003"
+ "adminUser": "jh0003",
+ "resourceLen": 63,
+ "retryTime": 10,
+ "retryAttempt": 10
} \ No newline at end of file
diff --git a/catalog-be/src/main/resources/scripts/sdcBePy/tosca/imports/run.py b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/imports/run.py
index 4d4eeaff6e..9ac820071a 100644
--- a/catalog-be/src/main/resources/scripts/sdcBePy/tosca/imports/run.py
+++ b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/imports/run.py
@@ -1,32 +1,18 @@
#!/usr/bin/env python3
import os
-import sys
import sdcBePy.common.logger as logger
from sdcBePy.common.normative.main import process_element_list, process_type_list
-from sdcBePy.common.sdcBeProxy import SdcBeProxy
-from sdcBePy.tosca.main import get_args, usage
+from sdcBePy.tosca.main import parse_and_create_proxy
from sdcBePy.tosca.models.normativeElementsList import get_normative_element_candidate_list, \
get_normative_element_with_metadata_list
from sdcBePy.tosca.models.normativeTypesList import get_normative_type_candidate_list
-def main():
- scheme, be_host, be_port, admin_user, update_version, debug = get_args()
-
- if debug is False:
- print('Disabling debug mode')
- logger.debugFlag = debug
-
- try:
- sdc_be_proxy = SdcBeProxy(be_host, be_port, scheme, admin_user, debug)
- except AttributeError:
- usage()
- sys.exit(3)
-
+def main(sdc_be_proxy, update_version):
# use to run script form this dir (not like the command)
- # base_file_location = os.getcwd() + "/../../../../import/tosca/"
+ # base_file_location = os.getcwd() + "/../../../import/tosca/"
base_file_location = os.getcwd() + os.path.sep
logger.debug("working directory =" + base_file_location)
@@ -35,8 +21,13 @@ def main():
process_element_list(get_normative_element_with_metadata_list(base_file_location), sdc_be_proxy)
logger.log("Script end ->", "All normatives imported successfully!")
- logger.error_and_exit(0, None)
+ logger.print_and_exit(0, None)
+
+
+def run():
+ sdc_be_proxy, update_version = parse_and_create_proxy()
+ main(sdc_be_proxy, update_version)
if __name__ == "__main__":
- main()
+ run()
diff --git a/catalog-be/src/main/resources/scripts/sdcBePy/tosca/main.py b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/main.py
index 2535ba6d77..565ce7efdb 100644
--- a/catalog-be/src/main/resources/scripts/sdcBePy/tosca/main.py
+++ b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/main.py
@@ -3,6 +3,10 @@ import os
import sys
from argparse import ArgumentParser
+from sdcBePy.common import logger
+from sdcBePy.common.properties import init_properties
+from sdcBePy.common.sdcBeProxy import SdcBeProxy
+
def usage():
print(sys.argv[0],
@@ -53,4 +57,22 @@ def get_args():
print('scheme =', scheme, ',be host =', be_host, ', be port =', be_port, ', user =', admin_user,
', debug =', debug, ', update_version =', update_version)
+ init_properties(defaults["retryTime"], defaults["retryAttempt"], defaults["resourceLen"])
return scheme, be_host, be_port, admin_user, update_version, debug
+
+
+def parse_and_create_proxy():
+ scheme, be_host, be_port, admin_user, update_version, debug = get_args()
+
+ if debug is False:
+ print('Disabling debug mode')
+ logger.debugFlag = debug
+
+ try:
+ sdc_be_proxy = SdcBeProxy(be_host, be_port, scheme, admin_user, debug=debug)
+ except AttributeError:
+ usage()
+ sys.exit(3)
+
+ return sdc_be_proxy, update_version
+
diff --git a/catalog-be/src/main/resources/scripts/sdcBePy/tosca/run.py b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/run.py
new file mode 100644
index 0000000000..955acff930
--- /dev/null
+++ b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/run.py
@@ -0,0 +1,29 @@
+import json
+
+from sdcBePy import properties
+from sdcBePy.common.logger import print_and_exit
+
+from sdcBePy.tosca.imports.run import main as import_main
+from sdcBePy.tosca.main import parse_and_create_proxy
+from sdcBePy.tosca.upgrade.run import main as upgrade_main
+
+
+def run():
+ sdc_be_proxy, update_version = parse_and_create_proxy()
+
+ response = sdc_be_proxy.get_normatives()
+
+ resources = []
+ if response == 200:
+ resources = json.loads(sdc_be_proxy.get_response_from_buffer())["resources"]
+ else:
+ print_and_exit(response, "Can't get normatives!")
+
+ if len(resources) < properties.resource_len:
+ import_main(sdc_be_proxy, update_version)
+ else:
+ upgrade_main(sdc_be_proxy)
+
+
+if __name__ == '__main__':
+ run()
diff --git a/catalog-be/src/main/resources/scripts/sdcBePy/tosca/upgrade/run.py b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/upgrade/run.py
index 6d90a1c085..47acd05f5f 100644
--- a/catalog-be/src/main/resources/scripts/sdcBePy/tosca/upgrade/run.py
+++ b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/upgrade/run.py
@@ -1,35 +1,21 @@
#!/usr/bin/env python3
import os
-import sys
from sdcBePy.common import logger
-from sdcBePy.common.logger import error_and_exit
+from sdcBePy.common.logger import print_and_exit
from sdcBePy.common.normative.main import process_element_list, process_type_list
-from sdcBePy.common.sdcBeProxy import SdcBeProxy
-from sdcBePy.tosca.main import get_args, usage
+from sdcBePy.tosca.main import parse_and_create_proxy
from sdcBePy.tosca.models.normativeElementsList import get_normative_element_candidate_list, \
get_normative_element_with_metadata_list
from sdcBePy.tosca.models.normativeToUpdateList import TypesToUpdate, get_heat_and_normative_to_update_list, \
get_nfv_onap_sol_to_update_list
-def main():
- scheme, be_host, be_port, admin_user, _, debug = get_args()
-
+def main(sdc_be_proxy):
update_version = True
update_onap_version = False
- if debug is False:
- print('Disabling debug mode')
- logger.debugFlag = debug
-
- try:
- sdc_be_proxy = SdcBeProxy(be_host, be_port, scheme, admin_user, debug=debug)
- except AttributeError:
- usage()
- sys.exit(3)
-
# use to run script form this dir (not like the command)
# base_file_location = os.getcwd() + "/../../../../import/tosca/"
base_file_location = os.getcwd() + "/"
@@ -46,7 +32,7 @@ def main():
process_type_list(nfv_onap_sol_list, sdc_be_proxy, update_onap_version)
logger.log("Updating end ->", "All normatives updated successfully!")
- error_and_exit(0, None)
+ print_and_exit(0, None)
def get_all_types():
@@ -55,5 +41,10 @@ def get_all_types():
path + "/../data/onapTypesToUpgrade.json"])
+def run():
+ sdc_be_proxy, _ = parse_and_create_proxy()
+ main(sdc_be_proxy)
+
+
if __name__ == "__main__":
- main()
+ run()