From cb30f3a566b73c78c3ea666acfcd3f288098684a Mon Sep 17 00:00:00 2001 From: "k.kedron" Date: Thu, 5 Mar 2020 13:12:27 +0100 Subject: Refactoring the sdc-BE-init python scripts Deeper refactoring of python script: - create the python package with init script - support for python 3.x - reuse code - new design - support for .json conf file - update the docker chef script Issue-ID: SDC-2784 Signed-off-by: Krystian Kedron Change-Id: I02169eb7d0e3e90851ba1811536d1712c3b4145f --- .../scripts/sdcBePy/tosca/upgrade/__init__.py | 0 .../resources/scripts/sdcBePy/tosca/upgrade/run.py | 59 ++++++++++++++++++++++ .../sdcBePy/tosca/upgrade/runUpgradeNormative.py | 59 ++++++++++++++++++++++ 3 files changed, 118 insertions(+) create mode 100644 catalog-be/src/main/resources/scripts/sdcBePy/tosca/upgrade/__init__.py create mode 100644 catalog-be/src/main/resources/scripts/sdcBePy/tosca/upgrade/run.py create mode 100644 catalog-be/src/main/resources/scripts/sdcBePy/tosca/upgrade/runUpgradeNormative.py (limited to 'catalog-be/src/main/resources/scripts/sdcBePy/tosca/upgrade') diff --git a/catalog-be/src/main/resources/scripts/sdcBePy/tosca/upgrade/__init__.py b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/upgrade/__init__.py new file mode 100644 index 0000000000..e69de29bb2 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 new file mode 100644 index 0000000000..6d90a1c085 --- /dev/null +++ b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/upgrade/run.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python3 + +import os +import sys + +from sdcBePy.common import logger +from sdcBePy.common.logger import error_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.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() + + 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() + "/" + logger.debug("working directory =" + base_file_location) + process_element_list(get_normative_element_candidate_list(base_file_location), sdc_be_proxy) + process_element_list(get_normative_element_with_metadata_list(base_file_location), sdc_be_proxy) + + all_types = get_all_types() + + heat_and_normative_list = get_heat_and_normative_to_update_list(all_types, base_file_location) + process_type_list(heat_and_normative_list, sdc_be_proxy, update_version) + + nfv_onap_sol_list = get_nfv_onap_sol_to_update_list(all_types, base_file_location) + 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) + + +def get_all_types(): + path = os.path.dirname(__file__) + return TypesToUpdate([path + "/../data/typesToUpgrade.json", + path + "/../data/onapTypesToUpgrade.json"]) + + +if __name__ == "__main__": + main() diff --git a/catalog-be/src/main/resources/scripts/sdcBePy/tosca/upgrade/runUpgradeNormative.py b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/upgrade/runUpgradeNormative.py new file mode 100644 index 0000000000..4b0d0cc8a2 --- /dev/null +++ b/catalog-be/src/main/resources/scripts/sdcBePy/tosca/upgrade/runUpgradeNormative.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python3 + +from sdcBePy.tosca.imports.runNormativeType import run +from sdcBePy.tosca.models.normativeToUpdateList import get_heat, get_normative, get_nfv, get_onap, get_sol +from sdcBePy.tosca.models.normativeTypesList import get_heat1707, get_heat1702_3537, get_heat_version +from sdcBePy.tosca.upgrade.run import get_all_types + +all_types = get_all_types() + + +def run_upgrade_heat(): + normative_candidate = get_heat(all_types) + run(normative_candidate) + + +def run_upgrade_normative(): + normative_candidate = get_normative(all_types) + run(normative_candidate) + + +def run_upgrade_nfv(): + normative_candidate = get_nfv(all_types) + run(normative_candidate) + + +def run_upgrade_onap(): + normative_candidate = get_onap(all_types) + run(normative_candidate) + + +def run_upgrade_sol(): + normative_candidate = get_sol(all_types) + run(normative_candidate) + + +def run_upgrade_heat1707(): + normative_candidate = get_heat1707() + run(normative_candidate) + + +def run_upgrade_heat1707_3537(): + normative_candidate = get_heat1702_3537() + run(normative_candidate) + + +def run_upgrade_heat_version(): + normative_candidate = get_heat_version() + run(normative_candidate) + + +if __name__ == '__main__': + run_upgrade_heat() + # run_upgrade_normative() + # run_upgrade_nfv() + # run_upgrade_onap() + # run_upgrade_sol() + # run_upgrade_heat1707() + # run_upgrade_heat1707_3537() + # run_upgrade_heat_version() -- cgit 1.2.3-korg