From 1402489faba6767edffc4909a2f95a13a2bbd6da Mon Sep 17 00:00:00 2001 From: ebo Date: Wed, 8 Apr 2020 12:32:14 +0100 Subject: Update pnf-sw-upgrade module to latest engine v2.8.1 - Using loguru to follow new recommend standard - Renamed Yang model filename to comply with https://tools.ietf.org/html/rfc6020#section-5.2 - Renamed initialization data to reflect the target datastore Issue-ID: INT-1516 Signed-off-by: ebo Change-Id: Ifde9e832b6a308dc918e3a84e03bfd43ad0f9b63 --- .../modules/docker-compose.yml | 2 +- .../modules/pnf-sw-upgrade/data.xml | 12 ---- .../modules/pnf-sw-upgrade/model.yang | 78 ---------------------- .../modules/pnf-sw-upgrade/pnf-sw-upgrade.yang | 78 ++++++++++++++++++++++ .../modules/pnf-sw-upgrade/startup.xml | 12 ++++ .../modules/pnf-sw-upgrade/subscriber.py | 23 ++++--- 6 files changed, 103 insertions(+), 102 deletions(-) delete mode 100644 test/mocks/netconf-pnp-simulator/modules/pnf-sw-upgrade/data.xml delete mode 100644 test/mocks/netconf-pnp-simulator/modules/pnf-sw-upgrade/model.yang create mode 100644 test/mocks/netconf-pnp-simulator/modules/pnf-sw-upgrade/pnf-sw-upgrade.yang create mode 100644 test/mocks/netconf-pnp-simulator/modules/pnf-sw-upgrade/startup.xml (limited to 'test') diff --git a/test/mocks/netconf-pnp-simulator/modules/docker-compose.yml b/test/mocks/netconf-pnp-simulator/modules/docker-compose.yml index e8f2f9ae5..fcfcec403 100644 --- a/test/mocks/netconf-pnp-simulator/modules/docker-compose.yml +++ b/test/mocks/netconf-pnp-simulator/modules/docker-compose.yml @@ -2,7 +2,7 @@ version: '3' services: netconf-pnp-simulator: - image: nexus3.onap.org:10001/onap/integration/simulators/netconf-pnp-simulator:2.6.2 + image: nexus3.onap.org:10001/onap/integration/simulators/netconf-pnp-simulator:2.8.1 container_name: netconf-pnp-simulator restart: always ports: diff --git a/test/mocks/netconf-pnp-simulator/modules/pnf-sw-upgrade/data.xml b/test/mocks/netconf-pnp-simulator/modules/pnf-sw-upgrade/data.xml deleted file mode 100644 index 4f1e7bceb..000000000 --- a/test/mocks/netconf-pnp-simulator/modules/pnf-sw-upgrade/data.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - sw-id-1 - CREATED - test_software_1 - sftp://127.0.0.1/test_software_1.img - test_user - test_password - trial software update - - diff --git a/test/mocks/netconf-pnp-simulator/modules/pnf-sw-upgrade/model.yang b/test/mocks/netconf-pnp-simulator/modules/pnf-sw-upgrade/model.yang deleted file mode 100644 index 6d413065e..000000000 --- a/test/mocks/netconf-pnp-simulator/modules/pnf-sw-upgrade/model.yang +++ /dev/null @@ -1,78 +0,0 @@ -module pnf-sw-upgrade { - namespace "http://onap.org/pnf-sw-upgrade"; - prefix upgrade; - - import ietf-yang-types { - prefix yang; - } - - revision "2019-12-03" { - description - "initial version"; - } - - container software-upgrade { - config true; - list upgrade-package { - key "id"; - leaf id { - type string; - } - leaf current-status { - type enumeration { - enum CREATED; - enum INITIALIZED; - enum DOWNLOAD_IN_PROGRESS; - enum DOWNLOAD_COMPLETED; - enum ACTIVATION_IN_PROGRESS; - enum ACTIVATION_COMPLETED; - } - description - "List of possible states of the upgrade"; - } - leaf state-change-time { - mandatory false; - description - "Date and time of the last state change."; - type yang:date-and-time; - } - leaf action { - mandatory false; - type enumeration { - enum NONE; - enum PRE_CHECK; - enum DOWNLOAD_NE_SW; - enum ACTIVATE_NE_SW; - enum CANCEL; - } - description - "List of possible actions for the upgrade"; - } - leaf software-version { - type string; - description - "Possible name or release version of the UP"; - } - leaf uri { - type string; - description - "A URI that points to the directory where the UP can be found."; - } - leaf user { - type string; - description - "Indicates the user."; - } - leaf password { - type string; - description - "Indicates the password."; - } - leaf user-label { - type string; - description - "Free-text description of the UP."; - } - } - } -} diff --git a/test/mocks/netconf-pnp-simulator/modules/pnf-sw-upgrade/pnf-sw-upgrade.yang b/test/mocks/netconf-pnp-simulator/modules/pnf-sw-upgrade/pnf-sw-upgrade.yang new file mode 100644 index 000000000..6d413065e --- /dev/null +++ b/test/mocks/netconf-pnp-simulator/modules/pnf-sw-upgrade/pnf-sw-upgrade.yang @@ -0,0 +1,78 @@ +module pnf-sw-upgrade { + namespace "http://onap.org/pnf-sw-upgrade"; + prefix upgrade; + + import ietf-yang-types { + prefix yang; + } + + revision "2019-12-03" { + description + "initial version"; + } + + container software-upgrade { + config true; + list upgrade-package { + key "id"; + leaf id { + type string; + } + leaf current-status { + type enumeration { + enum CREATED; + enum INITIALIZED; + enum DOWNLOAD_IN_PROGRESS; + enum DOWNLOAD_COMPLETED; + enum ACTIVATION_IN_PROGRESS; + enum ACTIVATION_COMPLETED; + } + description + "List of possible states of the upgrade"; + } + leaf state-change-time { + mandatory false; + description + "Date and time of the last state change."; + type yang:date-and-time; + } + leaf action { + mandatory false; + type enumeration { + enum NONE; + enum PRE_CHECK; + enum DOWNLOAD_NE_SW; + enum ACTIVATE_NE_SW; + enum CANCEL; + } + description + "List of possible actions for the upgrade"; + } + leaf software-version { + type string; + description + "Possible name or release version of the UP"; + } + leaf uri { + type string; + description + "A URI that points to the directory where the UP can be found."; + } + leaf user { + type string; + description + "Indicates the user."; + } + leaf password { + type string; + description + "Indicates the password."; + } + leaf user-label { + type string; + description + "Free-text description of the UP."; + } + } + } +} diff --git a/test/mocks/netconf-pnp-simulator/modules/pnf-sw-upgrade/startup.xml b/test/mocks/netconf-pnp-simulator/modules/pnf-sw-upgrade/startup.xml new file mode 100644 index 000000000..4f1e7bceb --- /dev/null +++ b/test/mocks/netconf-pnp-simulator/modules/pnf-sw-upgrade/startup.xml @@ -0,0 +1,12 @@ + + + + sw-id-1 + CREATED + test_software_1 + sftp://127.0.0.1/test_software_1.img + test_user + test_password + trial software update + + diff --git a/test/mocks/netconf-pnp-simulator/modules/pnf-sw-upgrade/subscriber.py b/test/mocks/netconf-pnp-simulator/modules/pnf-sw-upgrade/subscriber.py index 810fe453e..0786637b0 100755 --- a/test/mocks/netconf-pnp-simulator/modules/pnf-sw-upgrade/subscriber.py +++ b/test/mocks/netconf-pnp-simulator/modules/pnf-sw-upgrade/subscriber.py @@ -27,6 +27,7 @@ from concurrent.futures import ThreadPoolExecutor from threading import Timer import sysrepo as sr +from loguru import logger YANG_MODULE_NAME = 'pnf-sw-upgrade' @@ -117,13 +118,13 @@ def main(): try: print_current_config(sess, YANG_MODULE_NAME) except Exception as e: - print(e) + logger.error(e) sr.global_loop() - print("Application exit requested, exiting.") + logger.info("Application exit requested, exiting.") except Exception as e: - print(e) + logger.error(e) # Function to be called for subscribed client of given session whenever configuration changes. @@ -138,7 +139,7 @@ def module_change_cb(sess, module_name, event, private_ctx): break handle_change(conn, change.oper(), change.old_val(), change.new_val()) except Exception as e: - print(e) + logger.error(e) return sr.SR_ERR_OK @@ -150,10 +151,10 @@ def print_current_config(session, module_name): values = session.get_items(select_xpath) if values is not None: - print("========== BEGIN CONFIG ==========") + logger.info("========== BEGIN CONFIG ==========") for i in range(values.val_cnt()): - print(values.val(i).to_string(), end='') - print("=========== END CONFIG ===========") + logger.info(values.val(i).to_string().strip()) + logger.info("=========== END CONFIG ===========") def handle_change(conn, op, old_val, new_val): @@ -161,7 +162,7 @@ def handle_change(conn, op, old_val, new_val): Handle individual changes on the model. """ if op == sr.SR_OP_CREATED: - print("CREATED: %s" % new_val.to_string()) + logger.info("CREATED: %s" % new_val.to_string()) xpath = new_val.xpath() last_node = xpath_ctx.last_node(xpath) # Warning: 'key_value' modifies 'xpath'! @@ -169,11 +170,11 @@ def handle_change(conn, op, old_val, new_val): if key_id and last_node == 'action': executor.submit(execute_action, conn, key_id, new_val.data().get_enum()) elif op == sr.SR_OP_DELETED: - print("DELETED: %s" % old_val.to_string()) + logger.info("DELETED: %s" % old_val.to_string()) elif op == sr.SR_OP_MODIFIED: - print("MODIFIED: %s to %s" % (old_val.to_string(), new_val.to_string())) + logger.info("MODIFIED: %s to %s" % (old_val.to_string(), new_val.to_string())) elif op == sr.SR_OP_MOVED: - print("MOVED: %s after %s" % (new_val.xpath(), old_val.xpath())) + logger.info("MOVED: %s after %s" % (new_val.xpath(), old_val.xpath())) def execute_action(conn, key_id, action): -- cgit 1.2.3-korg