From: Lott, Christopher (cl778h) Date: Fri, 8 May 2020 17:34:23 +0000 (-0400) Subject: Use constants from rmr for message summary X-Git-Tag: 1.0.7~2^2 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F46%2F3646%2F1;p=ric-app%2Fqp-driver.git Use constants from rmr for message summary Message-summary dict keys are defined in the rmr module. Use them instead of hardcoding strings. Add Dockerfile to support unit testing on machines that don't have the RMR library, such as macs. Signed-off-by: Lott, Christopher (cl778h) Change-Id: I1d9ec036f41acd564b777f31cb2643e8b0ea5f37 --- diff --git a/.gitignore b/.gitignore index 9d5f770..59135fc 100644 --- a/.gitignore +++ b/.gitignore @@ -106,3 +106,8 @@ ENV/ # Test report xunit-reports coverage-reports + +# Eclipse +.project +.pydevproject +.settings diff --git a/Dockerfile-Unit-Test b/Dockerfile-Unit-Test new file mode 100644 index 0000000..29a31b9 --- /dev/null +++ b/Dockerfile-Unit-Test @@ -0,0 +1,35 @@ +# ================================================================================== +# 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. +# ================================================================================== +FROM python:3.8-alpine + +# sdl uses hiredis which needs gcc +RUN apk update && apk add gcc musl-dev + +# copy rmr libraries from builder image in lieu of an Alpine package +COPY --from=nexus3.o-ran-sc.org:10002/o-ran-sc/bldr-alpine3-rmr:4.0.5 /usr/local/lib64/librmr* /usr/local/lib64/ + +# Upgrade pip, install tox +RUN pip install --upgrade pip && pip install tox + +# copies +COPY setup.py tox.ini LICENSE.txt /tmp/ +COPY qpdriver/ /tmp/qpdriver +COPY tests/ /tmp/tests +RUN pip install /tmp + +# Run the unit tests +WORKDIR /tmp +RUN tox -e code,flake8 diff --git a/docs/developers-guide.rst b/docs/developers-guide.rst index bc8afd0..da078ff 100755 --- a/docs/developers-guide.rst +++ b/docs/developers-guide.rst @@ -13,10 +13,33 @@ Developers Guide Testing RMR Healthcheck ----------------------- The following instructions should deploy the QP Driver container in bare docker, and allow you -to test that the rmr healthcheck is working. +to test that the RMR healthcheck is working. :: docker build -t qpd:latest -f Dockerfile . docker run -d --net=host -e USE_FAKE_SDL=1 qpd:latest docker exec -it CONTAINER_ID /usr/local/bin/rmr_probe -h 127.0.0.1:4562 + +Unit Testing +------------ + +Running the unit tests requires the python packages ``tox`` and ``pytest``. + +The RMR library is also required during unit tests. If running directly from tox +(outside a Docker container), install RMR according to its instructions. + +Upon completion, view the test coverage like this: + +:: + + tox + open htmlcov/index.html + +Alternatively, if you cannot install RMR locally, you can run the unit +tests in Docker. This is somewhat less nice because you don't get the +pretty HTML report on coverage. + +:: + + docker build --no-cache -f Dockerfile-Unit-Test . diff --git a/docs/release-notes.rst b/docs/release-notes.rst index b012382..5b91566 100644 --- a/docs/release-notes.rst +++ b/docs/release-notes.rst @@ -11,11 +11,13 @@ The format is based on `Keep a Changelog `__ and this project adheres to `Semantic Versioning `__. -[1.0.5] - 2020-05-07 +[1.0.5] - 2020-05-08 -------------------- * Upgrade to RMR version 4.0.5 * Upgrade to framework version 1.1.0 +* Use constants from rmr module instead of hardcoded strings +* Add Dockerfile-Unit-Test to support testing [1.0.4] - 2020-05-05 diff --git a/qpdriver/main.py b/qpdriver/main.py index 5052353..000d3a5 100644 --- a/qpdriver/main.py +++ b/qpdriver/main.py @@ -18,7 +18,7 @@ qpdriver entrypoint module # ================================================================================== import json from os import getenv -from ricxappframe.xapp_frame import RMRXapp +from ricxappframe.xapp_frame import RMRXapp, rmr from qpdriver import data from qpdriver.exceptions import UENotFound @@ -40,7 +40,7 @@ def post_init(self): def default_handler(self, summary, sbuf): self.def_hand_called += 1 - self.logger.info("QP Driver received an unexpected message of type: {}, dropping.".format(summary["message type"])) + self.logger.info("QP Driver received an unexpected message of type: {}, dropping.".format(summary[rmr.RMR_MS_MSG_TYPE])) self.rmr_free(sbuf) @@ -56,7 +56,7 @@ def steering_req_handler(self, summary, sbuf): self.traffic_steering_requests += 1 ue_list = [] try: - req = json.loads(summary["payload"]) # input should be a json encoded as bytes + req = json.loads(summary[rmr.RMR_MS_PAYLOAD]) # input should be a json encoded as bytes ue_list = req["UEPredictionSet"] except (json.decoder.JSONDecodeError, KeyError): self.logger.debug("Received a TS Request but it was malformed!") diff --git a/tox.ini b/tox.ini index 276b22d..6ac2d1e 100644 --- a/tox.ini +++ b/tox.ini @@ -42,6 +42,11 @@ commands = flake8 setup.py qpdriver tests [flake8] extend-ignore = E501,E741,E731 +[testenv:clm] +# use pip to gather dependencies with versions for CLM analysis +whitelist_externals = sh +commands = sh -c 'pip freeze > requirements.txt' + # doc jobs [testenv:docs] whitelist_externals = echo