-"""
-Represents A1s database and database access functions.
-"""
# ==================================================================================
# Copyright (c) 2019-2020 Nokia
# Copyright (c) 2018-2020 AT&T Intellectual Property.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==================================================================================
+"""
+Represents A1s database and database access functions.
+"""
+import distutils.util
import os
import time
from threading import Thread
from ricxappframe.xapp_sdl import SDLWrapper
from a1.exceptions import PolicyTypeNotFound, PolicyInstanceNotFound, PolicyTypeAlreadyExists, CantDeleteNonEmptyType
-
# constants
INSTANCE_DELETE_NO_RESP_TTL = int(os.environ.get("INSTANCE_DELETE_NO_RESP_TTL", 5))
INSTANCE_DELETE_RESP_TTL = int(os.environ.get("INSTANCE_DELETE_RESP_TTL", 5))
+USE_FAKE_SDL = bool(distutils.util.strtobool(os.environ.get("USE_FAKE_SDL", "False")))
A1NS = "A1m_ns"
TYPE_PREFIX = "a1.policy_type."
INSTANCE_PREFIX = "a1.policy_instance."
mdc_logger = Logger(name=__name__)
-SDL = SDLWrapper()
+if USE_FAKE_SDL:
+ mdc_logger.debug("Using fake SDL")
+SDL = SDLWrapper(use_fake_sdl=USE_FAKE_SDL)
# Internal helpers
key = _generate_type_key(policy_type_id)
if SDL.get(A1NS, key) is not None:
raise PolicyTypeAlreadyExists()
+ # overwrite ID in body to enforce consistency
+ body['policy_type_id'] = policy_type_id
SDL.set(A1NS, key, body)