From 10cf02f453cbffea85455ff1c6fa018ecc5b8e3e Mon Sep 17 00:00:00 2001 From: "Lott, Christopher (cl778h)" Date: Mon, 29 Jun 2020 16:09:46 -0400 Subject: [PATCH] Add custom configuration-change handler to qp-d Listen for the configuration-change event and log the configuration data structure supplied to the handler. This is a new feature in the xapp framework as of version 1.3.0. Issue-ID: RICAPP-122 Signed-off-by: Lott, Christopher (cl778h) Change-Id: I6ce73d657dad6f99f077675d171f28bed1c5fac5 --- docs/release-notes.rst | 1 + qpdriver/main.py | 13 ++++++++++++- tests/conftest.py | 15 +++++++++++++++ tests/test_qpd.py | 20 ++++++++++++++++++++ tox.ini | 1 + 5 files changed, 49 insertions(+), 1 deletion(-) diff --git a/docs/release-notes.rst b/docs/release-notes.rst index e18d2ef..268b63c 100644 --- a/docs/release-notes.rst +++ b/docs/release-notes.rst @@ -15,6 +15,7 @@ and this project adheres to `Semantic Versioning `__. -------------------- * Send alarm on SDL failure (`RICAPP-117 `_) * Define configuration properties in xapp-descriptor controls section with JSON schema +* Add configuration-change handler method that logs the event * Requires RMR at version 4.1.2 or later * Requires xapp-frame-py at version 1.3.0 or later diff --git a/qpdriver/main.py b/qpdriver/main.py index a621e91..dd2d70f 100644 --- a/qpdriver/main.py +++ b/qpdriver/main.py @@ -45,6 +45,13 @@ def post_init(self): self.alarm_sdl = None +def handle_config_change(self, config): + """ + Function that runs at start and on every configuration file change. + """ + self.logger.debug("handle_config_change: config: {}".format(config)) + + def default_handler(self, summary, sbuf): """ Function that processes messages for which no handler is defined @@ -114,7 +121,11 @@ def start(thread=False): """ global rmr_xapp fake_sdl = getenv("USE_FAKE_SDL", None) - rmr_xapp = RMRXapp(default_handler, rmr_port=4560, post_init=post_init, use_fake_sdl=bool(fake_sdl)) + rmr_xapp = RMRXapp(default_handler, + config_handler=handle_config_change, + rmr_port=4560, + post_init=post_init, + use_fake_sdl=bool(fake_sdl)) rmr_xapp.register_callback(steering_req_handler, 30000) rmr_xapp.run(thread) diff --git a/tests/conftest.py b/tests/conftest.py index c9a12d8..9b53adc 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,3 +1,18 @@ +# ================================================================================== +# Copyright (c) 2020 AT&T Intellectual Property. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ================================================================================== import pytest diff --git a/tests/test_qpd.py b/tests/test_qpd.py index ef63727..31ad001 100644 --- a/tests/test_qpd.py +++ b/tests/test_qpd.py @@ -21,6 +21,8 @@ from ricxappframe.xapp_frame import Xapp, RMRXapp mock_ts_xapp = None mock_qp_xapp = None +# tox.ini sets env var to this value +config_file_path = "/tmp/config.json" """ these tests are not currently parallelizable (do not use this tox flag) @@ -30,6 +32,17 @@ mock_qp_xapp = None """ +def init_config_file(): + with open(config_file_path, "w") as file: + file.write('{ "example_int" : 0 }') + + +def write_config_file(): + # generate an inotify/config event + with open(config_file_path, "w") as file: + file.write('{ "example_int" : 1 }') + + def test_init_xapp(monkeypatch, ue_metrics, cell_metrics_1, cell_metrics_2, cell_metrics_3, ue_metrics_with_bad_cell): # monkeypatch post_init to set the data we want in SDL # the metrics arguments are JSON (dict) objects @@ -47,9 +60,16 @@ def test_init_xapp(monkeypatch, ue_metrics, cell_metrics_1, cell_metrics_2, cell # patch monkeypatch.setattr("qpdriver.main.post_init", fake_post_init) + # establish config + init_config_file() + # start qpd main.start(thread=True) + # wait a bit then update config + time.sleep(3) + write_config_file() + def test_rmr_flow(monkeypatch, qpd_to_qp, qpd_to_qp_bad_cell): """ diff --git a/tox.ini b/tox.ini index 5e95667..0cb4039 100644 --- a/tox.ini +++ b/tox.ini @@ -28,6 +28,7 @@ setenv = RMR_SEED_RT = tests/fixtures/test_local.rt RMR_ASYNC_CONN = 0 USE_FAKE_SDL = 1 + CONFIG_FILE = /tmp/config.json # add -s after pytest to stream the logs as they come in, rather than saving for the end commands = -- 2.16.6