Upgrade to SDL 2.0.2 00/2200/3 2.1.1
authorTommy Carpenter <tc677g@att.com>
Mon, 13 Jan 2020 14:51:27 +0000 (09:51 -0500)
committerTommy Carpenter <tc677g@att.com>
Tue, 14 Jan 2020 15:03:40 +0000 (10:03 -0500)
* Upgrades from sdl 1.0.0 to 2.0.2
* Delete a1test_helpers because SDL 2.0.2 provides the mockup we need
* Remove general catch all from A1

Change-Id: Ic130c524d110830c7f0ef3716991ae4a8ff87f5a
Signed-off-by: Tommy Carpenter <tc677g@att.com>
a1/controller.py
a1/data.py
container-tag.yaml
docs/release-notes.rst
integration_tests/a1mediator/Chart.yaml
setup.py
tests/a1test_helpers.py [deleted file]
tests/test_controller.py
tests/test_data.py

index f2fdfea..2cb9283 100644 (file)
@@ -17,7 +17,6 @@ Main a1 controller
 #   See the License for the specific language governing permissions and
 #   limitations under the License.
 # ==================================================================================
-from flask import Response
 from jsonschema import validate
 from jsonschema.exceptions import ValidationError
 import connexion
@@ -48,10 +47,8 @@ def _try_func_return(func):
         """
         # mdc_logger.exception(exc)  # waiting for https://jira.o-ran-sc.org/browse/RIC-39
         return "", 503
-    except BaseException:
-        # catch all, should never happen...
-        # mdc_logger.exception(exc)  # waiting for https://jira.o-ran-sc.org/browse/RIC-39
-        return Response(status=500)
+
+    # let other types of unexpected exceptions blow up and log
 
 
 # Healthcheck
index 1f09691..d737680 100644 (file)
@@ -67,10 +67,9 @@ class SDLWrapper:
 
     def find_and_get(self, prefix):
         """get all k v pairs that start with prefix"""
-        ret_dict = self.sdl.find_and_get(A1NS, "{0}".format(prefix), atomic=True)
-        found = {k: msgpack.unpackb(v, raw=False) for k, v in ret_dict.items()}
-        # TODO: upgrade to sdl 2.0.0 which does the sorting for us
-        return {k: found[k] for k in sorted(found)}
+        # note: SDL "*" usage is inconsistent with real python regex, where it would be ".*"
+        ret_dict = self.sdl.find_and_get(A1NS, "{0}*".format(prefix))
+        return {k: msgpack.unpackb(v, raw=False) for k, v in ret_dict.items()}
 
     def delete(self, key):
         """ delete a key"""
index de01844..b34dfd8 100644 (file)
@@ -1,4 +1,4 @@
 # The Jenkins job uses this string for the tag in the image name
 # for example nexus3.o-ran-sc.org:10004/my-image-name:my-tag
 ---
-tag: 2.1.0
+tag: 2.1.1
index 1d2b82d..ac3ad1d 100644 (file)
@@ -14,6 +14,15 @@ and this project adheres to `Semantic Versioning <http://semver.org/>`__.
    :depth: 3
    :local:
 
+[2.1.1] - 1/14/2020
+-------------------
+
+::
+
+    * Upgrades from sdl 1.0.0 to 2.0.2
+    * Delete a1test_helpers because SDL 2.0.2 provides the mockup we need
+    * Remove general catch all from A1
+
 [2.1.0] - 1/8/2020
 ------------------
 
@@ -25,8 +34,6 @@ and this project adheres to `Semantic Versioning <http://semver.org/>`__.
     * Integration tests have a copy of a dbaas helm chart, however the goal is to simplify that deployment per https://jira.o-ran-sc.org/browse/RIC-45
     * Unit tests have a mockup of SDL, however again the goal is to simplify as SDL grows per https://jira.o-ran-sc.org/browse/RIC-44
 
-
-
 [2.0.0] - 12/9/2019
 -------------------
 
index afb9d4f..d8c63c7 100644 (file)
@@ -1,4 +1,4 @@
 apiVersion: v1
 description: A1 Helm chart for Kubernetes
 name: a1mediator
-version: 2.1.0
+version: 2.1.1
index 9c6f0bc..0179fb0 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -18,7 +18,7 @@ from setuptools import setup, find_packages
 
 setup(
     name="a1",
-    version="2.1.0",
+    version="2.1.1",
     packages=find_packages(exclude=["tests.*", "tests"]),
     author="Tommy Carpenter",
     description="RIC A1 Mediator for policy/intent changes",
@@ -33,7 +33,7 @@ setup(
         "msgpack",
         "rmr>=2.2.0",
         "mdclogpy",
-        "ricsdl>=1.0.2,<2.0.0",
+        "ricsdl>=2.0.2,<3.0.0",
     ],
     package_data={"a1": ["openapi.yaml"]},
 )
diff --git a/tests/a1test_helpers.py b/tests/a1test_helpers.py
deleted file mode 100644 (file)
index 57e4251..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-# ==================================================================================
-#       Copyright (c) 2019-2020 Nokia
-#       Copyright (c) 2018-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 msgpack
-from ricsdl.exceptions import RejectedByBackend, NotConnected, BackendError
-
-
-class MockSDLWrapper:
-    """
-    Mock wrapper for SDL that uses a dict so we do not rely on Redis for unit tests.
-    Would be really nice if SDL itself came with a "standalone: dictionary" mode for this purpose...
-    """
-
-    def __init__(self):
-        self.POLICY_DATA = {}
-
-    def set(self, key, value):
-        """set a key"""
-
-        # these are for unit testing that the handler works on various SDL errors
-        if key == "a1.policy_type.111":
-            raise RejectedByBackend()
-        if key == "a1.policy_type.112":
-            raise NotConnected()
-        if key == "a1.policy_type.113":
-            raise BackendError()
-
-        self.POLICY_DATA[key] = msgpack.packb(value, use_bin_type=True)
-
-    def get(self, key):
-        """get a key"""
-        if key in self.POLICY_DATA:
-            return msgpack.unpackb(self.POLICY_DATA[key], raw=False)
-        return None
-
-    def find_and_get(self, prefix):
-        """get all k v pairs that start with prefix"""
-        return {k: msgpack.unpackb(v, raw=False) for k, v in self.POLICY_DATA.items() if k.startswith(prefix)}
-
-    def delete(self, key):
-        """ delete a key"""
-        del self.POLICY_DATA[key]
index 833fc6e..bbfe996 100644 (file)
@@ -20,8 +20,9 @@ tests for controller
 import time
 import json
 from rmr.rmr_mocks import rmr_mocks
+from ricsdl.syncstorage import SyncStorage
+from ricsdl.exceptions import RejectedByBackend, NotConnected, BackendError
 from a1 import a1rmr, data
-from .a1test_helpers import MockSDLWrapper
 
 RCV_ID = "test_receiver"
 ADM_CRTL_TID = 6660666
@@ -231,7 +232,7 @@ def _verify_instance_and_status(client, expected_instance, expected_status, expe
 def setup_module():
     """module level setup"""
 
-    data.SDL = MockSDLWrapper()  # patch SDL
+    data.SDL.sdl = SyncStorage(fake_db_backend="dict")
 
     def noop():
         pass
@@ -349,6 +350,18 @@ def test_bad_instances(client, monkeypatch, adm_type_good):
     assert res.status_code == 204
 
     # test 503 handlers
+
+    def monkey_set(key, value):
+        # set a key override function that throws sdl errors on certain keys
+        if key == "a1.policy_type.111":
+            raise RejectedByBackend()
+        if key == "a1.policy_type.112":
+            raise NotConnected()
+        if key == "a1.policy_type.113":
+            raise BackendError()
+
+    monkeypatch.setattr("a1.data.SDL.set", monkey_set)
+
     res = client.put("/a1-p/policytypes/111", json=adm_type_good)
     assert res.status_code == 503
     res = client.put("/a1-p/policytypes/112", json=adm_type_good)
index bf178ff..b148b23 100644 (file)
@@ -1,3 +1,6 @@
+"""
+tests data functions
+"""
 # ==================================================================================
 #       Copyright (c) 2019-2020 Nokia
 #       Copyright (c) 2018-2020 AT&T Intellectual Property.
 #   limitations under the License.
 # ==================================================================================
 from a1 import data
-from .a1test_helpers import MockSDLWrapper
+from ricsdl.syncstorage import SyncStorage
 
 
 def setup_module():
     """module level setup"""
-    data.SDL = MockSDLWrapper()  # patch SDL
+    data.SDL.sdl = SyncStorage(fake_db_backend="dict")
 
 
 def test_sdl_raw():