aboutsummaryrefslogtreecommitdiffstats
path: root/tests/mock_settings.py
diff options
context:
space:
mode:
authorAlex Shatov <alexs@att.com>2019-04-01 11:32:06 -0400
committerAlex Shatov <alexs@att.com>2019-04-01 11:32:06 -0400
commit9a4d3c5b8dc9c7697275cab38ee45b014dff9e55 (patch)
treed4d55bcc8bc237ee3199d0e6a13f5e7cd95fadea /tests/mock_settings.py
parentebc1a062328e53e97e4d24ed111534cfc567a809 (diff)
5.0.0 policy-handler - new PDP API or old PDP API4.0.0-ONAPdublin
- in R4 Dublin the policy-engine introduced a totally new API - policy-handler now has a startup option to either use the new PDP API or the old PDP API that was created-updated before the end of 2018 - see README.md and README_pdp_api_v0.md for instructions on how to setup the policy-handler running either with the new PDP API or the old (pdp_api_v0) PDP API - this is a massive refactoring that changed almost all the source files, but kept the old logic when using the old (pdp_api_v0) PDP API - all the code related to PDP API version is split into two subfolders = pdp_api/ contains the new PDP API source code = pdp_api_v0/ contains the old (2018) PDP API source code = pdp_client.py imports from either pdp_api or pdp_api_v0 = the rest of the code is only affected when it needs to branch the logic - logging to policy_handler.log now shows the path of the source file to allow tracing which PDP API is actually used - when the new PDP API is used, the policy-update flow is disabled = passive mode of operation = no web-socket = no periodic catch_up = no policy-filters = reduced web-API - only a single /policy_latest endpoint is available /policies_latest returns 404 /catch_up request is accepted, but ignored - on new PDP API: http /policy_latest returns the new data from the new PDP API with the following fields added by the policy-handler to keep other policy related parts intact in R4 (see pdp_api/policy_utils.py) = "policyName" = policy_id + "." + "policyVersion" + ".xml" = "policyVersion" = str("metadata"."policy-version") = "config" - is the renamed "properties" from the new PDP API response - unit tests are split into two subfolders as well = main/ for the new PDP API testing = pdp_api_v0/ for the old (2018) PDP API - removed the following line from the license text of changed files ECOMP is a trademark and service mark of AT&T Intellectual Property. - the new PDP API is expected to be extended and redesigned in R5 El Alto - on retiring the old PDP API - the intention is to be able to remove the pdp_api_v0/ subfolder and minimal related cleanup of the code that imports that as well as the cleanup of the config.py, etc. Change-Id: Ief9a2ae4541300308caaf97377f4ed051535dbe4 Signed-off-by: Alex Shatov <alexs@att.com> Issue-ID: DCAEGEN2-1128
Diffstat (limited to 'tests/mock_settings.py')
-rw-r--r--tests/mock_settings.py56
1 files changed, 37 insertions, 19 deletions
diff --git a/tests/mock_settings.py b/tests/mock_settings.py
index 8dec8e5..9e99561 100644
--- a/tests/mock_settings.py
+++ b/tests/mock_settings.py
@@ -14,12 +14,12 @@
# limitations under the License.
# ============LICENSE_END=========================================================
#
-# ECOMP is a trademark and service mark of AT&T Intellectual Property.
"""settings that are general to all tests"""
import copy
+import importlib
import json
-import logging
+import os
import sys
import uuid
from functools import wraps
@@ -29,7 +29,9 @@ from policyhandler.config import Config
from policyhandler.discovery import DiscoveryClient
from policyhandler.onap.audit import Audit
from policyhandler.service_activator import ServiceActivator
+from policyhandler.utils import Utils
+_LOGGER = Utils.get_logger(__file__)
def _fix_discover_config(func):
"""the decorator"""
@@ -38,7 +40,7 @@ def _fix_discover_config(func):
def mocked_discover_get_value(*_):
"""monkeypatch for get from consul"""
- return copy.deepcopy(Settings.mock_config)
+ return copy.deepcopy(MockSettings.mock_config)
@wraps(func)
def wrapper(*args, **kwargs):
@@ -54,49 +56,65 @@ def _fix_discover_config(func):
return func_result
return wrapper
-class Settings(object):
+class MockSettings(object):
"""init all locals"""
+ PDP_API_VERSION = "PDP_API_VERSION"
+ OLD_PDP_API_VERSION = "pdp_api_v0"
_loaded = False
- logger = None
mock_config = None
deploy_handler_instance_uuid = str(uuid.uuid4())
@staticmethod
def init():
"""init configs"""
- if Settings._loaded:
- Settings.logger.info("testing policy_handler with config: %s", Config.discovered_config)
+ if MockSettings._loaded:
+ _LOGGER.info("testing policy_handler with config: %s", Config.discovered_config)
return
- Settings._loaded = True
+ MockSettings._loaded = True
- Config.init_config()
-
- Config.consul_url = "http://unit-test-consul:850000"
+ Config.init_config("tests/etc_config.json")
with open("tests/mock_config.json", 'r') as config_json:
- Settings.mock_config = json.load(config_json)
+ MockSettings.mock_config = json.load(config_json)
- Settings.logger = logging.getLogger("policy_handler.unit_test")
- sys.stdout = LogWriter(Settings.logger.info)
- sys.stderr = LogWriter(Settings.logger.error)
+ sys.stdout = LogWriter(_LOGGER.info)
+ sys.stderr = LogWriter(_LOGGER.error)
print("print is expected to be in the log")
- Settings.logger.info("========== run_policy_handler ==========")
+ _LOGGER.info("========== run_policy_handler ==========")
Audit.init(Config.system_name, Config.LOGGER_CONFIG_FILE_PATH)
- Settings.rediscover_config()
+ MockSettings.rediscover_config()
@staticmethod
@_fix_discover_config
def rediscover_config(updated_config=None):
"""rediscover the config"""
if updated_config is not None:
- Settings.mock_config = copy.deepcopy(updated_config)
+ MockSettings.mock_config = copy.deepcopy(updated_config)
audit = Audit(req_message="rediscover_config")
Config.discover(audit)
ServiceActivator.determine_mode_of_operation(audit)
- Settings.logger.info("testing policy_handler with config: %s", Config.discovered_config)
+ _LOGGER.info("testing policy_handler with config: %s", Config.discovered_config)
audit.audit_done(" -- started")
+
+ @staticmethod
+ def setup_pdp_api(pdp_api_version=None):
+ """set the environment var for pdp_api"""
+ if Config._pdp_api_version == pdp_api_version:
+ _LOGGER.info("unchanged setup_pdp_api %s", pdp_api_version)
+ return
+
+ _LOGGER.info("setup_pdp_api %s -> %s", Config._pdp_api_version, pdp_api_version)
+
+ if pdp_api_version:
+ os.environ[MockSettings.PDP_API_VERSION] = pdp_api_version
+ elif MockSettings.PDP_API_VERSION in os.environ:
+ del os.environ[MockSettings.PDP_API_VERSION]
+ Config._pdp_api_version = pdp_api_version
+
+ importlib.reload(importlib.import_module("policyhandler.pdp_client"))
+ _LOGGER.info("done setup_pdp_api %s", Config._pdp_api_version)