diff options
29 files changed, 4831 insertions, 1004 deletions
@@ -1,19 +1,40 @@ -# policy_handler +# ONAP DCAE policy-handler + +See [wiki for DCAE gen2 architecture of policy-handling by DCAE-controller](https://wiki.onap.org/display/DW/DCAE+gen2+architecture+of+policy-handling+by+DCAE-controller) ## web-service for policies to be used by DCAE-Controller -- GET **/policy\_latest/***\<policy-id>* -- get the latest policy from policy-engine -- receives the **push notifications** from policy-engine through the web-socket, filters and gets the full policy-configs, and delivers that to deploy-handler +- GET `/policy_latest/<policy_id>` -- get the latest policy from policy-engine that is identified by `policy_id` +- POST `/policies_latest` -- gets the latest policies that match to the **policy-filter** provided in the body of the request. The policy-filter mimics the body of the /getConfig on policy-engine. + + sample request - policy-filter + +```json +{ + "configAttributes": { "key1":"value1" }, + "configName": "alex_config_name", + "onapName": "DCAE", + "policyName": "DCAE_alex.Config_alex_.*", + "unique": false +} +``` + +- GET `/healthcheck` - returns 200 OK and current run stats +- **web-socket** to **policy-engine** + - receives the **push notifications** of the changed and removed policies from the policy-engine, + - matches the policy-updates to policies and policy-filters found in deployment-handler, + - retrieves the full policy-bodies of the matched policies, + - delivers the policy-updates to deployment-handler ## manual http API -- GET **/catch_up** -- catch up with the latest state of the policy-engine -- GET **/policies_latest** -- get all the latest policies in policy-engine through web-service API -- GET **/shutdown** -- shutdown the server +- GET `/policies_latest` -- get all the latest policies from policy-engine that either have the policy_id or match to the policy-filter found in deployment-handler deployments +- GET `/catch_up` -- catch up with the latest state of the policy-engine +- GET `/shutdown` -- shutdown the server ---------- -## installation +## standalone installation `virtualenv policy_venv` @@ -37,18 +58,41 @@ ---------- -## configure +## local configure + +local config file `policy_handler/etc/config.json` contains: + +```json +{ + "wservice_port" : 25577, + "consul_url" : "http://consul:8500", + "policy_handler" : { + "system" : "policy_handler", + "tls" : { + "cert_directory" : "etc/tls/certs/", + "cacert" : "cacert.pem", + "private_key" : "key.pem", + "server_cert" : "cert.pem", + "server_ca_chain" : "ca_chain.pem" + } + }, + "logging" : {...} +} +``` -in folder `policy_handler`: +Field descriptions - - `config.json` contains - - `"policy_engine"` - the http connect info to ONAP **policy-engine** - - headers.ClientAuth : base64(<mech-id with namespace>:<password>) - - headers.Authorization : base64(<policy-engine server auth>) - - `"deploy_handler"` - the http connect info to _policy part_ of the **deploy-handler** - - `policy_engine.properties` contains config info for the client lib of ONAP **policy-engine** that receives push notifications from the ONAP **policy-engine** server - - CLIENT_ID is the mech-id with the namespace - need to register with policy-engine team thru email - - CLIENT_KEY is the base64 of the mech-id password - separate passwords for TEST versus PROD +- `wservice_port` - port of the policy-hanlder web-service +- `consul_url` - optional url for the consul agent +- `policy_handler` - local config for policy-handler application + - `system` - general system name of the policy-handler + - `tls` - tls settings for the https clients and server - required to enable tls + - `cert_directory` - relative path pointing to the folder with certificates + - `cacert` - file name for the ca-cert or ca-bundle file in pem format in cert_directory -- used by https clients + - `private_key` - file name for the private key in cert_directory -- used by https server + - `server_cert` - file name for the https server certificate file in pem format in cert_directory + - `server_ca_chain` - file name for the optional https server ca-chain certificates file in pem format in cert_directory -- used when the ca-chain is not included in the server_cert file +- `logging` - logging config for general logging ---------- @@ -72,24 +116,24 @@ in folder `policy_handler`: ### ```policyhandler/customize/``` folder -contains ```CustomizeBase``` and ```Customize``` classes +contains ```CustomizerBase``` and ```Customizer``` classes -- ```CustomizeBase``` defines the interface and the default=ONAP behavior +- ```CustomizerBase``` defines the interface and the default=ONAP behavior -- ```CustomizeBase``` is owned by ONAP and should not be changed by the company +- ```CustomizerBase``` is owned by ONAP and should not be changed by the company -- ```Customize``` inherits ```CustomizeBase``` +- ```Customizer``` inherits ```CustomizerBase``` -- policy-handler instantiates ```Customize``` to get the customized behavior +- policy-handler instantiates ```Customizer``` to get the customized behavior -- ```Customize``` is owned by the company and should be changed by the company -- ONAP is not going to change ```Customize``` +- ```Customizer``` is owned by the company and should be changed by the company +- ONAP is not going to change ```Customizer``` -- the methods of ```Customize``` are expected to be overridden by the company to change the behavior of the policy-handler +- the methods of ```Customizer``` are expected to be overridden by the company to change the behavior of the policy-handler -- samples are provided for methods in ```Customize``` class as the commented out lines +- samples are provided for methods in ```Customizer``` class as the commented out lines -- Company is allowed to add more files to customize/ folder if that is required for better structuring of their code as soon as it is invoked by the methods of ```Customize``` +- Company is allowed to add more files to customize/ folder if that is required for better structuring of their code as soon as it is invoked by the methods of ```Customizer``` here is an example of ```customizer.py``` diff --git a/etc/config.json b/etc/config.json index de7f6cc..ae5aa51 100644 --- a/etc/config.json +++ b/etc/config.json @@ -1,6 +1,7 @@ { "wservice_port" : 25577, "consul_url" : "http://consul:8500", + "consul_timeout_in_secs" : 60, "policy_handler" : { "system" : "policy_handler", "tls" : { diff --git a/policyhandler/config.py b/policyhandler/config.py index d94ed79..5184f7f 100644 --- a/policyhandler/config.py +++ b/policyhandler/config.py @@ -148,24 +148,43 @@ class Config(object): TLS_CA_MODE = "tls_ca_mode" TLS_WSS_CA_MODE = "tls_wss_ca_mode" TLS_CA_MODE_DO_NOT_VERIFY = "do_not_verify" + TIMEOUT_IN_SECS = "timeout_in_secs" + CONSUL_TIMEOUT_IN_SECS = "consul_timeout_in_secs" + WS_PING_INTERVAL_IN_SECS = "ws_ping_interval_in_secs" + DEFAULT_TIMEOUT_IN_SECS = 60 system_name = SERVICE_NAME_POLICY_HANDLER wservice_port = 25577 consul_url = "http://consul:8500" + consul_timeout_in_secs = DEFAULT_TIMEOUT_IN_SECS tls_cacert_file = None tls_server_cert_file = None tls_private_key_file = None + tls_server_ca_chain_file = None _local_config = Settings() discovered_config = Settings() @staticmethod + def _get_tls_file_path(tls_config, cert_directory, tls_name): + """calc file path and verify its existance""" + file_name = tls_config.get(tls_name) + if not file_name: + return None + tls_file_path = os.path.join(cert_directory, file_name) + if not os.path.isfile(tls_file_path) or not os.access(tls_file_path, os.R_OK): + Config._logger.error("invalid %s: %s", tls_name, tls_file_path) + return None + return tls_file_path + + @staticmethod def _set_tls_config(tls_config): """verify and set tls certs in config""" try: Config.tls_cacert_file = None Config.tls_server_cert_file = None Config.tls_private_key_file = None + Config.tls_server_ca_chain_file = None if not (tls_config and isinstance(tls_config, dict)): Config._logger.info("no tls in config: %s", json.dumps(tls_config)) @@ -174,43 +193,28 @@ class Config(object): cert_directory = tls_config.get("cert_directory") if not (cert_directory and isinstance(cert_directory, str)): - Config._logger.info("unexpected tls.cert_directory: %r", cert_directory) + Config._logger.warning("unexpected tls.cert_directory: %r", cert_directory) return cert_directory = os.path.join( os.path.dirname(os.path.dirname(os.path.realpath(__file__))), cert_directory) if not (cert_directory and os.path.isdir(cert_directory)): - Config._logger.info("ignoring invalid cert_directory: %s", cert_directory) + Config._logger.warning("ignoring invalid cert_directory: %s", cert_directory) return - cacert = tls_config.get("cacert") - if cacert: - tls_cacert_file = os.path.join(cert_directory, cacert) - if not os.path.isfile(tls_cacert_file): - Config._logger.error("invalid tls_cacert_file: %s", tls_cacert_file) - else: - Config.tls_cacert_file = tls_cacert_file - - server_cert = tls_config.get("server_cert") - if server_cert: - tls_server_cert_file = os.path.join(cert_directory, server_cert) - if not os.path.isfile(tls_server_cert_file): - Config._logger.error("invalid tls_server_cert_file: %s", tls_server_cert_file) - else: - Config.tls_server_cert_file = tls_server_cert_file - - private_key = tls_config.get("private_key") - if private_key: - tls_private_key_file = os.path.join(cert_directory, private_key) - if not os.path.isfile(tls_private_key_file): - Config._logger.error("invalid tls_private_key_file: %s", tls_private_key_file) - else: - Config.tls_private_key_file = tls_private_key_file + Config.tls_cacert_file = Config._get_tls_file_path(tls_config, cert_directory, "cacert") + Config.tls_server_cert_file = Config._get_tls_file_path(tls_config, cert_directory, + "server_cert") + Config.tls_private_key_file = Config._get_tls_file_path(tls_config, cert_directory, + "private_key") + Config.tls_server_ca_chain_file = Config._get_tls_file_path(tls_config, cert_directory, + "server_ca_chain") finally: Config._logger.info("tls_cacert_file = %s", Config.tls_cacert_file) Config._logger.info("tls_server_cert_file = %s", Config.tls_server_cert_file) Config._logger.info("tls_private_key_file = %s", Config.tls_private_key_file) + Config._logger.info("tls_server_ca_chain_file = %s", Config.tls_server_ca_chain_file) @staticmethod def init_config(file_path=None): @@ -239,6 +243,9 @@ class Config(object): Config.wservice_port = loaded_config.get(Config.FIELD_WSERVICE_PORT, Config.wservice_port) Config.consul_url = os.environ.get( "CONSUL_URL", loaded_config.get(Config.FIELD_CONSUL_URL, Config.consul_url)).rstrip("/") + Config.consul_timeout_in_secs = loaded_config.get(Config.CONSUL_TIMEOUT_IN_SECS) + if not Config.consul_timeout_in_secs or Config.consul_timeout_in_secs < 1: + Config.consul_timeout_in_secs = Config.DEFAULT_TIMEOUT_IN_SECS local_config = loaded_config.get(Config.SERVICE_NAME_POLICY_HANDLER, {}) Config.system_name = local_config.get(Config.FIELD_SYSTEM, Config.system_name) @@ -250,7 +257,7 @@ class Config(object): @staticmethod def discover(audit): - """bring and merge the config settings from the discovery service""" + """bring the config settings from the discovery service""" discovery_key = Config.system_name from .discovery import DiscoveryClient new_config = DiscoveryClient.get_value(audit, discovery_key) diff --git a/policyhandler/deploy_handler.py b/policyhandler/deploy_handler.py index b4b2468..0ffacba 100644 --- a/policyhandler/deploy_handler.py +++ b/policyhandler/deploy_handler.py @@ -145,6 +145,7 @@ class DeployHandler(object): """calling the deployment-handler web apis""" _logger = logging.getLogger("policy_handler.deploy_handler") DEFAULT_TARGET_ENTITY = "deployment_handler" + DEFAULT_TIMEOUT_IN_SECS = 60 _lazy_inited = False _lock = Lock() @@ -158,6 +159,7 @@ class DeployHandler(object): _target_entity = None _custom_kwargs = {} _server_instance_uuid = None + _timeout_in_secs = DEFAULT_TIMEOUT_IN_SECS server_instance_changed = False @staticmethod @@ -188,7 +190,8 @@ class DeployHandler(object): # "query" : { # "cfy_tenant_name" : "default_tenant" # }, - # "tls_ca_mode" : "cert_directory" + # "tls_ca_mode" : "cert_directory", + # "timeout_in_secs": 60 # } DeployHandler._target_entity = config_dh.get(TARGET_ENTITY, DeployHandler.DEFAULT_TARGET_ENTITY) @@ -204,6 +207,10 @@ class DeployHandler(object): DeployHandler._target_entity, DeployHandler._url, tls_ca_mode, json.dumps(DeployHandler._custom_kwargs)) + DeployHandler._timeout_in_secs = config_dh.get(Config.TIMEOUT_IN_SECS) + if not DeployHandler._timeout_in_secs or DeployHandler._timeout_in_secs < 1: + DeployHandler._timeout_in_secs = DeployHandler.DEFAULT_TIMEOUT_IN_SECS + if not DeployHandler._url: # discover routing to deployment-handler at consul-services if not isinstance(config_dh, dict): @@ -290,6 +297,7 @@ class DeployHandler(object): target_entity = DeployHandler._target_entity url = DeployHandler._url_policy params = deepcopy(DeployHandler._query) + timeout_in_secs = DeployHandler._timeout_in_secs custom_kwargs = deepcopy(DeployHandler._custom_kwargs) metrics = Metrics(aud_parent=audit, targetEntity="{} policy_update".format(target_entity), @@ -297,9 +305,9 @@ class DeployHandler(object): headers = {REQUEST_X_ECOMP_REQUESTID : metrics.request_id} log_action = "put to {} at {}".format(target_entity, url) - log_data = "msg={} headers={}, params={} custom_kwargs({})".format( + log_data = "msg={} headers={}, params={}, timeout_in_secs={}, custom_kwargs({})".format( json.dumps(message), json.dumps(headers), - json.dumps(params), json.dumps(custom_kwargs)) + json.dumps(params), timeout_in_secs, json.dumps(custom_kwargs)) log_line = log_action + " " + log_data DeployHandler._logger.info(log_line) @@ -315,7 +323,8 @@ class DeployHandler(object): res = None try: - res = session.put(url, json=message, headers=headers, params=params, **custom_kwargs) + res = session.put(url, json=message, headers=headers, params=params, + timeout=timeout_in_secs, **custom_kwargs) except Exception as ex: error_code = (AuditHttpCode.SERVICE_UNAVAILABLE_ERROR.value if isinstance(ex, requests.exceptions.RequestException) @@ -357,6 +366,7 @@ class DeployHandler(object): target_entity = DeployHandler._target_entity url = DeployHandler._url_policy params = deepcopy(DeployHandler._query) + timeout_in_secs = DeployHandler._timeout_in_secs custom_kwargs = deepcopy(DeployHandler._custom_kwargs) metrics = Metrics(aud_parent=audit, @@ -365,8 +375,8 @@ class DeployHandler(object): headers = {REQUEST_X_ECOMP_REQUESTID : metrics.request_id} log_action = "get from {} at {}".format(target_entity, url) - log_data = "headers={}, params={} custom_kwargs({})".format( - json.dumps(headers), json.dumps(params), json.dumps(custom_kwargs)) + log_data = "headers={}, params={}, timeout_in_secs={}, custom_kwargs({})".format( + json.dumps(headers), json.dumps(params), timeout_in_secs, json.dumps(custom_kwargs)) log_line = log_action + " " + log_data DeployHandler._logger.info(log_line) @@ -382,7 +392,8 @@ class DeployHandler(object): res = None try: - res = session.get(url, headers=headers, params=params, **custom_kwargs) + res = session.get(url, headers=headers, params=params, timeout=timeout_in_secs, + **custom_kwargs) except Exception as ex: error_code = (AuditHttpCode.SERVICE_UNAVAILABLE_ERROR.value if isinstance(ex, requests.exceptions.RequestException) @@ -412,7 +423,7 @@ class DeployHandler(object): policies = result.get(POLICIES, {}) policy_filters = result.get(POLICY_FILTERS, {}) if not policies and not policy_filters: - audit.set_http_status_code(AuditHttpCode.DATA_NOT_FOUND_ERROR.value) + audit.set_http_status_code(AuditHttpCode.DATA_NOT_FOUND_OK.value) DeployHandler._logger.warning(audit.warn( "found no deployed policies or policy-filters: {}".format(log_line), error_code=AuditResponseCode.DATA_ERROR)) diff --git a/policyhandler/discovery.py b/policyhandler/discovery.py index 5a35525..4c5b64e 100644 --- a/policyhandler/discovery.py +++ b/policyhandler/discovery.py @@ -56,7 +56,7 @@ class DiscoveryClient(object): @staticmethod def _discover_service(audit, service_name, service_path): """find the service record in consul""" - response = requests.get(service_path) + response = requests.get(service_path, timeout=Config.consul_timeout_in_secs) DiscoveryClient._logger.info(audit.info("response {} from {}: {}".format( response.status_code, service_path, response.text))) @@ -113,7 +113,7 @@ class DiscoveryClient(object): @staticmethod def _get_value_from_kv(url): """get the value from consul-kv at discovery url""" - response = requests.get(url) + response = requests.get(url, timeout=Config.consul_timeout_in_secs) response.raise_for_status() data = response.json() value = base64.b64decode(data[0]["Value"]).decode("utf-8") @@ -129,6 +129,7 @@ class DiscoveryClient(object): log_line = "get from {} at {}".format(DiscoveryClient.CONSUL_ENTITY, discovery_url) DiscoveryClient._logger.info(metrics.metrics_start(log_line)) + status_code = None try: status_code, value = DiscoveryClient._get_value_from_kv(discovery_url) except Exception as ex: diff --git a/policyhandler/onap/audit.py b/policyhandler/onap/audit.py index 1bee4a7..d63d0b2 100644 --- a/policyhandler/onap/audit.py +++ b/policyhandler/onap/audit.py @@ -64,10 +64,10 @@ ERROR_DESCRIPTION = "errorDescription" class AuditHttpCode(Enum): """audit http codes""" HTTP_OK = 200 + DATA_NOT_FOUND_OK = 204 PERMISSION_UNAUTHORIZED_ERROR = 401 PERMISSION_FORBIDDEN_ERROR = 403 RESPONSE_ERROR = 400 - DATA_NOT_FOUND_ERROR = 404 SERVER_INTERNAL_ERROR = 500 SERVICE_UNAVAILABLE_ERROR = 503 DATA_ERROR = 1030 @@ -88,7 +88,7 @@ class AuditResponseCode(Enum): def get_response_code(http_status_code): """calculates the response_code from max_http_status_code""" response_code = AuditResponseCode.UNKNOWN_ERROR - if http_status_code <= AuditHttpCode.HTTP_OK.value: + if http_status_code <= AuditHttpCode.DATA_NOT_FOUND_OK.value: response_code = AuditResponseCode.SUCCESS elif http_status_code in [AuditHttpCode.PERMISSION_UNAUTHORIZED_ERROR.value, @@ -99,8 +99,7 @@ class AuditResponseCode(Enum): elif http_status_code == AuditHttpCode.SERVER_INTERNAL_ERROR.value: response_code = AuditResponseCode.BUSINESS_PROCESS_ERROR elif http_status_code in [AuditHttpCode.DATA_ERROR.value, - AuditHttpCode.RESPONSE_ERROR.value, - AuditHttpCode.DATA_NOT_FOUND_ERROR.value]: + AuditHttpCode.RESPONSE_ERROR.value]: response_code = AuditResponseCode.DATA_ERROR elif http_status_code == AuditHttpCode.SCHEMA_ERROR.value: response_code = AuditResponseCode.SCHEMA_ERROR @@ -138,6 +137,7 @@ class _Audit(object): _hostname = os.environ.get(HOSTNAME) _health = Health() + _health_checkers = {} _py_ver = sys.version.replace("\n", "") _packages = [] @@ -167,6 +167,31 @@ class _Audit(object): pass + def __init__(self, job_name=None, request_id=None, req_message=None, **kwargs): + """create audit object per each request in the system + + :job_name: is the name of the audit job for health stats + :request_id: is the X-ECOMP-RequestID for tracing + :req_message: is the request message string for logging + :kwargs: - put any request related params into kwargs + """ + self.job_name = _Audit._key_format.sub('_', job_name or req_message or _Audit._service_name) + self.request_id = request_id + self.req_message = req_message or "" + self.kwargs = kwargs or {} + + self.max_http_status_code = 0 + self._lock = threading.Lock() + + + @staticmethod + def register_item_health(health_name, health_getter): + """ + register the health-checker for the additional item + by its health_name and the function health_getter that returns its health status as json + """ + _Audit._health_checkers[health_name] = health_getter + def health(self, full=False): """returns json for health check""" utcnow = datetime.utcnow() @@ -186,33 +211,21 @@ class _Audit(object): "process_memory" : ProcessInfo.process_memory() }, "stats" : _Audit._health.dump(), + "items" : dict((health_name, health_getter()) + for health_name, health_getter in _Audit._health_checkers.items()), "soft" : {"python" : _Audit._py_ver, "packages" : _Audit._packages} } - self.info("{} health: {}".format(_Audit._service_name, json.dumps(health))) + self.info("{} health: {}".format(_Audit._service_name, + json.dumps(health, sort_keys=True))) return health + def process_info(self): """get the debug info on all the threads and memory""" process_info = ProcessInfo.get_all() self.info("{} process_info: {}".format(_Audit._service_name, json.dumps(process_info))) return process_info - def __init__(self, job_name=None, request_id=None, req_message=None, **kwargs): - """create audit object per each request in the system - - :job_name: is the name of the audit job for health stats - :request_id: is the X-ECOMP-RequestID for tracing - :req_message: is the request message string for logging - :kwargs: - put any request related params into kwargs - """ - self.job_name = _Audit._key_format.sub('_', job_name or req_message or _Audit._service_name) - self.request_id = request_id - self.req_message = req_message or "" - self.kwargs = kwargs or {} - - self.max_http_status_code = 0 - self._lock = threading.Lock() - def merge_all_kwargs(self, **kwargs): """returns the merge of copy of self.kwargs with the param kwargs""" @@ -230,7 +243,7 @@ class _Audit(object): def reset_http_status_not_found(self): """resets the highest(worst) http status code if data not found""" with self._lock: - if self.max_http_status_code == AuditHttpCode.DATA_NOT_FOUND_ERROR.value: + if self.max_http_status_code == AuditHttpCode.DATA_NOT_FOUND_OK.value: self.max_http_status_code = 0 def get_max_http_status_code(self): @@ -252,25 +265,23 @@ class _Audit(object): == AuditResponseCode.get_response_code(status_code).value or self.get_max_http_status_code() >= AuditHttpCode.SERVER_INTERNAL_ERROR.value) - def _get_response_status(self, not_found_ok=None): + def _get_response_status(self): """calculates the response status fields from max_http_status_code""" max_http_status_code = self.get_max_http_status_code() response_code = AuditResponseCode.get_response_code(max_http_status_code) - success = ((response_code.value == AuditResponseCode.SUCCESS.value) - or (not_found_ok - and max_http_status_code == AuditHttpCode.DATA_NOT_FOUND_ERROR.value)) + success = (response_code.value == AuditResponseCode.SUCCESS.value) response_description = AuditResponseCode.get_human_text(response_code) return success, max_http_status_code, response_code, response_description def is_success(self): - """returns whether the response_code is success""" + """returns whether the response_code is success or 204 - not found""" success, _, _, _ = self._get_response_status() return success - def is_success_or_not_found(self): - """returns whether the response_code is success or 404 - not found""" - success, _, _, _ = self._get_response_status(not_found_ok=True) - return success + def is_not_found(self): + """returns whether the response_code is 204 - not found""" + max_http_status_code = self.get_max_http_status_code() + return max_http_status_code == AuditHttpCode.DATA_NOT_FOUND_OK.value def debug(self, log_line, **kwargs): """debug - the debug=lowest level of logging""" @@ -397,8 +408,8 @@ class Audit(_Audit): def audit_done(self, result=None, **kwargs): """debug+audit - the audit=top level of logging""" all_kwargs = self.merge_all_kwargs(**kwargs) - success, max_http_status_code, response_code, response_description = \ - self._get_response_status() + (success, max_http_status_code, + response_code, response_description) = self._get_response_status() log_line = "{0} {1}".format(self.req_message, result or "").strip() audit_func = None timer = _Audit.get_elapsed_time(self._started) @@ -461,8 +472,8 @@ class Metrics(_Audit): def metrics(self, log_line, **kwargs): """debug+metrics - the metrics=sub-audit level of logging""" all_kwargs = self.merge_all_kwargs(**kwargs) - success, max_http_status_code, response_code, response_description = \ - self._get_response_status() + (success, max_http_status_code, + response_code, response_description) = self._get_response_status() metrics_func = None timer = _Audit.get_elapsed_time(self._metrics_started) if success: diff --git a/policyhandler/policy_matcher.py b/policyhandler/policy_matcher.py index 71b5ce8..d0786ba 100644 --- a/policyhandler/policy_matcher.py +++ b/policyhandler/policy_matcher.py @@ -23,6 +23,7 @@ import logging import re from .deploy_handler import DeployHandler, PolicyUpdateMessage +from .onap.audit import AuditHttpCode, AuditResponseCode from .policy_consts import (ERRORED_POLICIES, LATEST_POLICIES, MATCHING_CONDITIONS, POLICY_BODY, POLICY_FILTER, POLICY_NAME, POLICY_VERSION, POLICY_VERSIONS) @@ -36,15 +37,32 @@ class PolicyMatcher(object): PENDING_UPDATE = "pending_update" @staticmethod - def get_latest_policies(audit): - """ - find the latest policies from policy-engine for the deployed policies and policy-filters - """ + def get_deployed_policies(audit): + """get the deployed policies and policy-filters""" deployed_policies, deployed_policy_filters = DeployHandler.get_deployed_policies(audit) + if audit.is_not_found(): + warning_txt = "got no deployed policies or policy-filters" + PolicyMatcher._logger.warning(warning_txt) + return {"warning": warning_txt}, None, None + if not audit.is_success() or (not deployed_policies and not deployed_policy_filters): error_txt = "failed to retrieve policies from deployment-handler" PolicyMatcher._logger.error(error_txt) + return {"error": error_txt}, None, None + + return None, deployed_policies, deployed_policy_filters + + + @staticmethod + def build_catch_up_message(audit, deployed_policies, deployed_policy_filters): + """ + find the latest policies from policy-engine for the deployed policies and policy-filters + """ + + if not (deployed_policies or deployed_policy_filters): + error_txt = "no deployed policies or policy-filters" + PolicyMatcher._logger.warning(error_txt) return {"error": error_txt}, None coarse_regex_patterns = PolicyMatcher.calc_coarse_patterns( @@ -54,7 +72,9 @@ class PolicyMatcher(object): error_txt = ("failed to construct the coarse_regex_patterns from " + "deployed_policies: {} and deployed_policy_filters: {}" .format(deployed_policies, deployed_policy_filters)) - PolicyMatcher._logger.error(error_txt) + PolicyMatcher._logger.error(audit.error( + error_txt, error_code=AuditResponseCode.DATA_ERROR)) + audit.set_http_status_code(AuditHttpCode.DATA_ERROR.value) return {"error": error_txt}, None pdp_response = PolicyRest.get_latest_policies( @@ -62,9 +82,9 @@ class PolicyMatcher(object): for policy_name_pattern in coarse_regex_patterns] ) - if not audit.is_success_or_not_found(): + if not audit.is_success(): error_txt = "failed to retrieve policies from policy-engine" - PolicyMatcher._logger.error(error_txt) + PolicyMatcher._logger.warning(error_txt) return {"error": error_txt}, None latest_policies = pdp_response.get(LATEST_POLICIES, {}) @@ -90,6 +110,7 @@ class PolicyMatcher(object): removed_policies, policy_filter_matches)) + @staticmethod def calc_coarse_patterns(audit, deployed_policies, deployed_policy_filters): """calculate the coarsed patterns on policy-names in policies and policy-filters""" @@ -109,6 +130,7 @@ class PolicyMatcher(object): coarse_regex.patterns))) return coarse_regex_patterns + @staticmethod def match_to_deployed_policies(audit, policies_updated, policies_removed): """match the policies_updated, policies_removed versus deployed policies""" @@ -125,6 +147,7 @@ class PolicyMatcher(object): return changed_policies, policies_removed, policy_filter_matches + @staticmethod def _match_policies(audit, policies, deployed_policies, deployed_policy_filters): """ @@ -174,6 +197,7 @@ class PolicyMatcher(object): return matching_policies, changed_policies, policy_filter_matches + @staticmethod def _match_policy_to_filter(audit, policy_id, policy, policy_filter_id, policy_filter): """Match the policy to the policy-filter""" @@ -218,7 +242,7 @@ class PolicyMatcher(object): filter_config_name = policy_filter.get("configName") policy_config_name = matching_conditions.get("ConfigName") - if filter_onap_name and filter_config_name != policy_config_name: + if filter_config_name and filter_config_name != policy_config_name: PolicyMatcher._logger.debug( audit.debug("not match by configName: {} != {}: {}" .format(policy_config_name, filter_config_name, log_line))) diff --git a/policyhandler/policy_receiver.py b/policyhandler/policy_receiver.py index 3ae25fc..249c1f7 100644 --- a/policyhandler/policy_receiver.py +++ b/policyhandler/policy_receiver.py @@ -28,14 +28,16 @@ passes the notifications to policy-updater import copy import json import logging -import os import ssl import time +import urllib.parse +from datetime import datetime from threading import Lock, Thread import websocket from .config import Config, Settings +from .onap.audit import Audit from .policy_consts import MATCHING_CONDITIONS, POLICY_NAME, POLICY_VERSION from .policy_updater import PolicyUpdater from .policy_utils import Utils @@ -48,8 +50,17 @@ POLICY_MATCHES = 'matches' class _PolicyReceiver(Thread): """web-socket to PolicyEngine""" _logger = logging.getLogger("policy_handler.policy_receiver") - - def __init__(self): + WS_STARTED = "started" + WS_START_COUNT = "start_count" + WS_CLOSE_COUNT = "close_count" + WS_ERROR_COUNT = "error_count" + WS_PONG_COUNT = "pong_count" + WS_MESSAGE_COUNT = "message_count" + WS_MESSAGE_TIMESTAMP = "message_timestamp" + WS_STATUS = "status" + WS_PING_INTERVAL_DEFAULT = 180 + + def __init__(self, audit): """web-socket inside the thread to receive policy notifications from PolicyEngine""" Thread.__init__(self, name="policy_receiver", daemon=True) @@ -62,14 +73,26 @@ class _PolicyReceiver(Thread): self._web_socket_sslopt = None self._tls_wss_ca_mode = None self._web_socket = None - self.reconfigure() - - self._policy_updater = PolicyUpdater(self.reconfigure) - self._policy_updater.start() - - def reconfigure(self): + self._ws_ping_interval_in_secs = _PolicyReceiver.WS_PING_INTERVAL_DEFAULT + self._web_socket_health = { + _PolicyReceiver.WS_START_COUNT: 0, + _PolicyReceiver.WS_CLOSE_COUNT: 0, + _PolicyReceiver.WS_ERROR_COUNT: 0, + _PolicyReceiver.WS_PONG_COUNT: 0, + _PolicyReceiver.WS_MESSAGE_COUNT: 0, + _PolicyReceiver.WS_STATUS: "created" + } + + Audit.register_item_health("web_socket_health", self._get_health) + self._reconfigure(audit) + + self._policy_updater = PolicyUpdater(self._reconfigure) + + def _reconfigure(self, audit): """configure and reconfigure the web-socket""" with self._lock: + _PolicyReceiver._logger.info(audit.info("web_socket_health {}".format( + json.dumps(self._get_health(), sort_keys=True)))) self._sleep_before_restarting = 5 self._settings.set_config(Config.discovered_config) changed, config = self._settings.get_by_key(Config.FIELD_POLICY_ENGINE) @@ -80,13 +103,19 @@ class _PolicyReceiver(Thread): prev_web_socket_url = self._web_socket_url prev_web_socket_sslopt = self._web_socket_sslopt + prev_ws_ping_interval_in_secs = self._ws_ping_interval_in_secs + self._web_socket_sslopt = None - resturl = (config.get("url", "").lower() - + config.get("path_notifications", "/pdp/notifications")) + resturl = urllib.parse.urljoin(config.get("url", "").lower().rstrip("/") + "/", + config.get("path_notifications", "/pdp/notifications")) self._tls_wss_ca_mode = config.get(Config.TLS_WSS_CA_MODE) + self._ws_ping_interval_in_secs = config.get(Config.WS_PING_INTERVAL_IN_SECS) + if not self._ws_ping_interval_in_secs or self._ws_ping_interval_in_secs < 60: + self._ws_ping_interval_in_secs = _PolicyReceiver.WS_PING_INTERVAL_DEFAULT + if resturl.startswith("https:"): self._web_socket_url = resturl.replace("https:", "wss:") @@ -101,17 +130,19 @@ class _PolicyReceiver(Thread): else: self._web_socket_url = resturl.replace("http:", "ws:") + log_changed = ( + "changed web_socket_url(%s) or tls_wss_ca_mode(%s)" + " or ws_ping_interval_in_secs(%s): %s" % + (self._web_socket_url, self._tls_wss_ca_mode, self._ws_ping_interval_in_secs, + self._settings)) if (self._web_socket_url == prev_web_socket_url - and Utils.are_the_same(prev_web_socket_sslopt, self._web_socket_sslopt)): - _PolicyReceiver._logger.info( - "not changed web_socket_url(%s) or tls_wss_ca_mode(%s): %s", - self._web_socket_url, self._tls_wss_ca_mode, self._settings) + and Utils.are_the_same(prev_web_socket_sslopt, self._web_socket_sslopt) + and prev_ws_ping_interval_in_secs == self._ws_ping_interval_in_secs): + _PolicyReceiver._logger.info(audit.info("not {}".format(log_changed))) self._settings.commit_change() return False - _PolicyReceiver._logger.info("changed web_socket_url(%s) or tls_wss_ca_mode(%s): %s", - self._web_socket_url, self._tls_wss_ca_mode, - self._settings) + _PolicyReceiver._logger.info(audit.info(log_changed)) self._settings.commit_change() self._stop_notifications() @@ -119,6 +150,8 @@ class _PolicyReceiver(Thread): def run(self): """listen on web-socket and pass the policy notifications to policy-updater""" + self._policy_updater.start() + _PolicyReceiver._logger.info("starting policy_receiver...") websocket.enableTrace(True) restarting = False while True: @@ -142,6 +175,7 @@ class _PolicyReceiver(Thread): web_socket_url = self._web_socket_url sslopt = copy.deepcopy(self._web_socket_sslopt) tls_wss_ca_mode = self._tls_wss_ca_mode + ws_ping_interval_in_secs = self._ws_ping_interval_in_secs _PolicyReceiver._logger.info( "connecting to policy-notifications at %s with sslopt(%s) tls_wss_ca_mode(%s)", @@ -149,13 +183,15 @@ class _PolicyReceiver(Thread): self._web_socket = websocket.WebSocketApp( web_socket_url, + on_open=self._on_ws_open, on_message=self._on_pdp_message, on_close=self._on_ws_close, - on_error=self._on_ws_error + on_error=self._on_ws_error, + on_pong=self._on_ws_pong ) _PolicyReceiver._logger.info("waiting for policy-notifications...") - self._web_socket.run_forever(sslopt=sslopt) + self._web_socket.run_forever(sslopt=sslopt, ping_interval=ws_ping_interval_in_secs) restarting = True _PolicyReceiver._logger.info("exit policy-receiver") @@ -175,9 +211,13 @@ class _PolicyReceiver(Thread): def _on_pdp_message(self, *args): """received the notification from PDP""" + self._web_socket_health[_PolicyReceiver.WS_MESSAGE_COUNT] += 1 + self._web_socket_health[_PolicyReceiver.WS_MESSAGE_TIMESTAMP] = str(datetime.utcnow()) try: message = args and args[-1] _PolicyReceiver._logger.info("Received notification message: %s", message) + _PolicyReceiver._logger.info("web_socket_health %s", + json.dumps(self._get_health(), sort_keys=True)) if not message: return message = json.loads(message) @@ -216,9 +256,47 @@ class _PolicyReceiver(Thread): _PolicyReceiver._logger.exception("policy-notification error %s", str(error)) self._sleep_before_restarting = 60 if isinstance(error, ssl.SSLError) else 5 + self._web_socket_health[_PolicyReceiver.WS_STATUS] = "error" + self._web_socket_health[_PolicyReceiver.WS_ERROR_COUNT] += 1 + self._web_socket_health["last_error"] = { + "error": str(error), "timestamp": str(datetime.utcnow()) + } + _PolicyReceiver._logger.info("web_socket_health %s", + json.dumps(self._get_health(), sort_keys=True)) + def _on_ws_close(self, code, reason): """restart web-socket on close""" - _PolicyReceiver._logger.info("lost connection(%s, %s) to PDP - restarting...", code, reason) + self._web_socket_health["last_closed"] = str(datetime.utcnow()) + self._web_socket_health[_PolicyReceiver.WS_STATUS] = "closed" + self._web_socket_health[_PolicyReceiver.WS_CLOSE_COUNT] += 1 + _PolicyReceiver._logger.info( + "lost connection(%s, %s) to PDP - restarting... web_socket_health %s", + code, reason, json.dumps(self._get_health(), sort_keys=True)) + + def _on_ws_open(self): + """started web-socket""" + self._web_socket_health[_PolicyReceiver.WS_STATUS] = _PolicyReceiver.WS_STARTED + self._web_socket_health[_PolicyReceiver.WS_START_COUNT] += 1 + self._web_socket_health[_PolicyReceiver.WS_STARTED] = datetime.utcnow() + _PolicyReceiver._logger.info("opened connection to PDP web_socket_health %s", + json.dumps(self._get_health(), sort_keys=True)) + + def _on_ws_pong(self, pong): + """pong = response to pinging the server of the web-socket""" + self._web_socket_health[_PolicyReceiver.WS_PONG_COUNT] += 1 + _PolicyReceiver._logger.info( + "pong(%s) from connection to PDP web_socket_health %s", + pong, json.dumps(self._get_health(), sort_keys=True)) + + def _get_health(self): + """returns the healthcheck of the web-socket as json""" + web_socket_health = copy.deepcopy(self._web_socket_health) + started = web_socket_health.get(_PolicyReceiver.WS_STARTED) + if started: + web_socket_health[_PolicyReceiver.WS_STARTED] = str(started) + web_socket_health["uptime"] = str(datetime.utcnow() - started) + return web_socket_health + def shutdown(self, audit): """Shutdown the policy-receiver""" @@ -237,11 +315,20 @@ class _PolicyReceiver(Thread): """need to bring the latest policies to DCAE-Controller""" self._policy_updater.catch_up(audit) + def is_running(self): + """check whether the policy-receiver and policy-updater are running""" + return self.is_alive() and self._policy_updater.is_alive() + class PolicyReceiver(object): """policy-receiver - static singleton wrapper""" _policy_receiver = None @staticmethod + def is_running(): + """check whether the policy-receiver runs""" + return PolicyReceiver._policy_receiver and PolicyReceiver._policy_receiver.is_running() + + @staticmethod def shutdown(audit): """Shutdown the notification-handler""" PolicyReceiver._policy_receiver.shutdown(audit) @@ -254,7 +341,7 @@ class PolicyReceiver(object): @staticmethod def run(audit): """Using policy-engine client to talk to policy engine""" - PolicyReceiver._policy_receiver = _PolicyReceiver() + PolicyReceiver._policy_receiver = _PolicyReceiver(audit) PolicyReceiver._policy_receiver.start() PolicyReceiver.catch_up(audit) diff --git a/policyhandler/policy_rest.py b/policyhandler/policy_rest.py index 0713b38..85dd914 100644 --- a/policyhandler/policy_rest.py +++ b/policyhandler/policy_rest.py @@ -22,6 +22,7 @@ import copy import json import logging import time +import urllib.parse from multiprocessing.dummy import Pool as ThreadPool from threading import Lock @@ -51,6 +52,7 @@ class PolicyRest(object): EXPECTED_VERSIONS = "expected_versions" IGNORE_POLICY_NAMES = "ignore_policy_names" + DEFAULT_TIMEOUT_IN_SECS = 60 _lock = Lock() _settings = Settings(Config.FIELD_POLICY_ENGINE, Config.POOL_CONNECTIONS, @@ -65,6 +67,7 @@ class PolicyRest(object): _thread_pool_size = 4 _policy_retry_count = 1 _policy_retry_sleep = 0 + _timeout_in_secs = DEFAULT_TIMEOUT_IN_SECS @staticmethod def _init(): @@ -85,8 +88,9 @@ class PolicyRest(object): 'http://', requests.adapters.HTTPAdapter(pool_connections=pool_size, pool_maxsize=pool_size)) - PolicyRest._url_get_config = (config.get("url", "") + config.get("path_api", "") - + PolicyRest.POLICY_GET_CONFIG) + get_config_path = urllib.parse.urljoin( + config.get("path_api", "pdp/api").strip("/") + "/", PolicyRest.POLICY_GET_CONFIG) + PolicyRest._url_get_config = urllib.parse.urljoin(config.get("url", ""), get_config_path) PolicyRest._headers = config.get("headers", {}) PolicyRest._target_entity = config.get("target_entity", Config.FIELD_POLICY_ENGINE) _, PolicyRest._thread_pool_size = PolicyRest._settings.get_by_key( @@ -101,12 +105,16 @@ class PolicyRest(object): tls_ca_mode = config.get(Config.TLS_CA_MODE) PolicyRest._custom_kwargs = Config.get_requests_kwargs(tls_ca_mode) + PolicyRest._timeout_in_secs = config.get(Config.TIMEOUT_IN_SECS) + if not PolicyRest._timeout_in_secs or PolicyRest._timeout_in_secs < 1: + PolicyRest._timeout_in_secs = PolicyRest.DEFAULT_TIMEOUT_IN_SECS - PolicyRest._logger.info("PDP(%s) url(%s) headers(%s) tls_ca_mode(%s) custom_kwargs(%s): %s", - PolicyRest._target_entity, PolicyRest._url_get_config, - Metrics.json_dumps(PolicyRest._headers), - tls_ca_mode, json.dumps(PolicyRest._custom_kwargs), - PolicyRest._settings) + PolicyRest._logger.info( + "PDP(%s) url(%s) headers(%s) tls_ca_mode(%s) timeout_in_secs(%s) custom_kwargs(%s): %s", + PolicyRest._target_entity, PolicyRest._url_get_config, + Metrics.json_dumps(PolicyRest._headers), tls_ca_mode, + PolicyRest._timeout_in_secs, json.dumps(PolicyRest._custom_kwargs), + PolicyRest._settings) PolicyRest._settings.commit_change() PolicyRest._lazy_inited = True @@ -144,6 +152,7 @@ class PolicyRest(object): session = PolicyRest._requests_session target_entity = PolicyRest._target_entity url = PolicyRest._url_get_config + timeout_in_secs = PolicyRest._timeout_in_secs headers = copy.deepcopy(PolicyRest._headers) custom_kwargs = copy.deepcopy(PolicyRest._custom_kwargs) @@ -152,15 +161,17 @@ class PolicyRest(object): headers[REQUEST_X_ECOMP_REQUESTID] = metrics.request_id log_action = "post to {} at {}".format(target_entity, url) - log_data = "msg={} headers={}, custom_kwargs({})".format( - json.dumps(json_body), Metrics.json_dumps(headers), json.dumps(custom_kwargs)) + log_data = "msg={} headers={}, custom_kwargs({}) timeout_in_secs({})".format( + json.dumps(json_body), Metrics.json_dumps(headers), json.dumps(custom_kwargs), + timeout_in_secs) log_line = log_action + " " + log_data PolicyRest._logger.info(metrics.metrics_start(log_line)) res = None try: - res = session.post(url, json=json_body, headers=headers, **custom_kwargs) + res = session.post(url, json=json_body, headers=headers, timeout=timeout_in_secs, + **custom_kwargs) except Exception as ex: error_code = (AuditHttpCode.SERVICE_UNAVAILABLE_ERROR.value if isinstance(ex, requests.exceptions.RequestException) @@ -195,12 +206,12 @@ class PolicyRest(object): res_data = res.json() if res_data and isinstance(res_data, list) and len(res_data) == 1: - rslt = res_data[0] - if rslt and not rslt.get(POLICY_NAME): + rslt = res_data[0] or {} + if not rslt.get(POLICY_NAME): res_data = None if rslt.get(PolicyRest.PDP_CONFIG_MESSAGE) == PolicyRest.PDP_NO_RESPONSE_RECEIVED: error_code = AuditHttpCode.SERVICE_UNAVAILABLE_ERROR.value - error_msg = "unexpected {0}".format(log_line) + error_msg = "{} unexpected {}".format(error_code, log_line) PolicyRest._logger.error(error_msg) metrics.set_http_status_code(error_code) @@ -222,8 +233,8 @@ class PolicyRest(object): if (rslt and not rslt.get(POLICY_NAME) and rslt.get(PolicyRest.PDP_CONFIG_STATUS) == PolicyRest.PDP_CONFIG_NOT_FOUND and rslt.get(PolicyRest.PDP_CONFIG_MESSAGE) == PolicyRest.PDP_DATA_NOT_FOUND): - status_code = AuditHttpCode.DATA_NOT_FOUND_ERROR.value - info_msg = "not found {0}".format(log_line) + status_code = AuditHttpCode.DATA_NOT_FOUND_OK.value + info_msg = "{} not found {}".format(status_code, log_line) PolicyRest._logger.info(info_msg) metrics.set_http_status_code(status_code) @@ -279,7 +290,8 @@ class PolicyRest(object): expect_policy_removed = (ignore_policy_names and not expected_versions) for retry in range(1, PolicyRest._policy_retry_count + 1): - PolicyRest._logger.debug(str_metrics) + PolicyRest._logger.debug("try(%s) retry_get_config(%s): %s", + retry, retry_get_config, str_metrics) done, latest_policy, status_code = PolicyRest._get_latest_policy_once( audit, policy_id, expected_versions, ignore_policy_names, @@ -289,16 +301,16 @@ class PolicyRest(object): break if retry == PolicyRest._policy_retry_count: - audit.warn("gave up retrying {} from PDP after #{} for policy_id={}" - .format(PolicyRest._url_get_config, retry, policy_id), - error_code=AuditResponseCode.DATA_ERROR) + PolicyRest._logger.error( + audit.error("gave up retrying after #{} for policy_id({}) from PDP {}" + .format(retry, policy_id, PolicyRest._url_get_config), + error_code=AuditResponseCode.DATA_ERROR)) break - audit.warn( - "retry #{} {} from PDP in {} secs for policy_id={}".format( - retry, PolicyRest._url_get_config, - PolicyRest._policy_retry_sleep, policy_id), - error_code=AuditResponseCode.DATA_ERROR) + PolicyRest._logger.warning(audit.warn( + "will retry({}) for policy_id({}) in {} secs from PDP {}".format( + retry, policy_id, PolicyRest._policy_retry_sleep, PolicyRest._url_get_config), + error_code=AuditResponseCode.DATA_ERROR)) time.sleep(PolicyRest._policy_retry_sleep) if (expect_policy_removed and not latest_policy @@ -308,10 +320,10 @@ class PolicyRest(object): audit.set_http_status_code(status_code) if not PolicyRest._validate_policy(latest_policy): - audit.set_http_status_code(AuditHttpCode.DATA_NOT_FOUND_ERROR.value) - audit.error( + audit.set_http_status_code(AuditHttpCode.DATA_NOT_FOUND_OK.value) + PolicyRest._logger.error(audit.error( "received invalid policy from PDP: {}".format(json.dumps(latest_policy)), - error_code=AuditResponseCode.DATA_ERROR) + error_code=AuditResponseCode.DATA_ERROR)) return latest_policy @@ -331,9 +343,10 @@ class PolicyRest(object): ) if not latest_policy and not expect_policy_removed: - audit.error("received unexpected policy data from PDP for policy_id={}: {}" - .format(policy_id, json.dumps(policy_bodies or [])), - error_code=AuditResponseCode.DATA_ERROR) + PolicyRest._logger.error( + audit.error("received unexpected policy data from PDP for policy_id={}: {}" + .format(policy_id, json.dumps(policy_bodies or [])), + error_code=AuditResponseCode.DATA_ERROR)) done = bool(latest_policy or (expect_policy_removed and not policy_bodies) @@ -411,6 +424,9 @@ class PolicyRest(object): policies = None apns_length = len(apns) + PolicyRest._logger.debug("apns_length(%s) policies_to_find %s", apns_length, + json.dumps(policies_to_find)) + if apns_length == 1: policies = [PolicyRest.get_latest_policy(apns[0])] else: @@ -419,8 +435,9 @@ class PolicyRest(object): pool.close() pool.join() - metrics_total.metrics("result get_latest_updated_policies {0}: {1} {2}" - .format(str_metrics, len(policies), json.dumps(policies))) + metrics_total.metrics("result({}) get_latest_updated_policies {}: {} {}" + .format(apns_length, str_metrics, + len(policies), json.dumps(policies))) updated_policies = dict((policy[POLICY_ID], policy) for policy in policies @@ -438,12 +455,12 @@ class PolicyRest(object): and policy_id not in removed_policies) PolicyRest._logger.debug( - "result updated_policies %s, removed_policies %s, errored_policies %s", - json.dumps(updated_policies), json.dumps(removed_policies), + "result(%s) updated_policies %s, removed_policies %s, errored_policies %s", + apns_length, json.dumps(updated_policies), json.dumps(removed_policies), json.dumps(errored_policies)) if errored_policies: - audit.set_http_status_code(AuditHttpCode.DATA_NOT_FOUND_ERROR.value) + audit.set_http_status_code(AuditHttpCode.DATA_ERROR.value) audit.error( "errored_policies in PDP: {}".format(json.dumps(errored_policies)), error_code=AuditResponseCode.DATA_ERROR) @@ -460,6 +477,7 @@ class PolicyRest(object): PolicyRest._logger.debug("%s", str_policy_filter) status_code, policy_bodies = PolicyRest._pdp_get_config(audit, policy_filter) + audit.set_http_status_code(status_code) PolicyRest._logger.debug("%s policy_bodies: %s %s", status_code, str_policy_filter, json.dumps(policy_bodies or [])) @@ -467,14 +485,13 @@ class PolicyRest(object): latest_policies = PolicyUtils.select_latest_policies(policy_bodies) if not latest_policies: - audit.set_http_status_code(AuditHttpCode.DATA_NOT_FOUND_ERROR.value) - audit.warn( + audit.set_http_status_code(AuditHttpCode.DATA_NOT_FOUND_OK.value) + PolicyRest._logger.warning(audit.warn( "received no policies from PDP for policy_filter {}: {}" .format(str_policy_filter, json.dumps(policy_bodies or [])), - error_code=AuditResponseCode.DATA_ERROR) + error_code=AuditResponseCode.DATA_ERROR)) return None, latest_policies - audit.set_http_status_code(status_code) valid_policies = {} errored_policies = {} for (policy_id, policy) in latest_policies.items(): diff --git a/policyhandler/policy_updater.py b/policyhandler/policy_updater.py index 235e2b6..fb6c8b6 100644 --- a/policyhandler/policy_updater.py +++ b/policyhandler/policy_updater.py @@ -106,9 +106,9 @@ class _PolicyUpdate(object): self._audit.req_message = req_message self._logger.info( - "pending request_id %s for %s policies_updated %s policies_removed %s", + "pending(%s) for %s policies_updated %s policies_removed %s", self._audit.request_id, req_message, - json.dumps(policies_updated), json.dumps(policies_removed)) + json.dumps(self._policies_updated), json.dumps(self._policies_removed)) class PolicyUpdater(Thread): @@ -178,13 +178,14 @@ class PolicyUpdater(Thread): if not self._aud_reconfigure: self._aud_reconfigure = Audit(req_message=Config.RECONFIGURE) PolicyUpdater._logger.info( - "reconfigure %s request_id %s", + "%s request_id %s", self._aud_reconfigure.req_message, self._aud_reconfigure.request_id ) self._run.set() def run(self): """wait and run the policy-update in thread""" + PolicyUpdater._logger.info("starting policy_updater...") self._run_reconfigure_timer() while True: PolicyUpdater._logger.info("waiting for policy-updates...") @@ -307,7 +308,7 @@ class PolicyUpdater(Thread): if DeployHandler.reconfigure(aud_reconfigure): reconfigure_result += " " + Config.DEPLOY_HANDLER - if self._reconfigure_receiver(): + if self._reconfigure_receiver(aud_reconfigure): reconfigure_result += " web-socket" reconfigure_result += " -- change: {}".format(Config.discovered_config) @@ -348,12 +349,24 @@ class PolicyUpdater(Thread): ) catch_up_result = "" try: + not_found_ok = None PolicyUpdater._logger.info(log_line) self._pause_catch_up_timer() - _, catch_up_message = PolicyMatcher.get_latest_policies(aud_catch_up) + _, policies, policy_filters = PolicyMatcher.get_deployed_policies(aud_catch_up) - if not catch_up_message or not aud_catch_up.is_success_or_not_found(): + catch_up_message = None + if aud_catch_up.is_not_found(): + not_found_ok = True + else: + _, catch_up_message = PolicyMatcher.build_catch_up_message( + aud_catch_up, policies, policy_filters) + + if not_found_ok: + catch_up_result = ("- not sending catch-up " + "- no deployed policies or policy-filters") + PolicyUpdater._logger.warning(catch_up_result) + elif not (catch_up_message and aud_catch_up.is_success()): catch_up_result = "- not sending catch-up to deployment-handler due to errors" PolicyUpdater._logger.warning(catch_up_result) elif catch_up_message.empty(): @@ -402,11 +415,14 @@ class PolicyUpdater(Thread): PolicyUpdater._logger.info(log_line) try: + not_found_ok = None (updated_policies, removed_policies, policy_filter_matches) = PolicyMatcher.match_to_deployed_policies( audit, policies_updated, policies_removed) - if updated_policies or removed_policies: + if audit.is_not_found(): + not_found_ok = True + elif updated_policies or removed_policies: updated_policies, removed_policies = PolicyRest.get_latest_updated_policies( (audit, [(policy_id, policy.get(POLICY_BODY, {}).get(POLICY_VERSION)) @@ -415,7 +431,11 @@ class PolicyUpdater(Thread): for policy_id, policy in removed_policies.items()] )) - if not audit.is_success_or_not_found(): + if not_found_ok: + result = ("- not sending policy-updates to deployment-handler " + "- no deployed policies or policy-filters") + PolicyUpdater._logger.warning(result) + elif not audit.is_success(): result = "- not sending policy-updates to deployment-handler due to errors" PolicyUpdater._logger.warning(result) elif not updated_policies and not removed_policies: diff --git a/policyhandler/web_server.py b/policyhandler/web_server.py index 24db468..73e7fbc 100644 --- a/policyhandler/web_server.py +++ b/policyhandler/web_server.py @@ -26,7 +26,7 @@ import cherrypy from .config import Config from .deploy_handler import PolicyUpdateMessage -from .onap.audit import Audit +from .onap.audit import Audit, AuditHttpCode from .policy_matcher import PolicyMatcher from .policy_receiver import PolicyReceiver from .policy_rest import PolicyRest @@ -34,21 +34,35 @@ from .policy_rest import PolicyRest class PolicyWeb(object): """run http API of policy-handler on 0.0.0.0:wservice_port - any incoming address""" + DATA_NOT_FOUND_ERROR = 404 HOST_INADDR_ANY = ".".join("0"*4) logger = logging.getLogger("policy_handler.policy_web") @staticmethod def run_forever(audit): """run the web-server of the policy-handler forever""" - PolicyWeb.logger.info("policy_handler web-server on port(%d)...", Config.wservice_port) cherrypy.config.update({"server.socket_host": PolicyWeb.HOST_INADDR_ANY, "server.socket_port": Config.wservice_port}) + + protocol = "http" + tls_info = "" + # if Config.tls_server_cert_file and Config.tls_private_key_file: + # cherrypy.server.ssl_module = 'builtin' + # cherrypy.server.ssl_certificate = Config.tls_server_cert_file + # cherrypy.server.ssl_private_key = Config.tls_private_key_file + # if Config.tls_server_ca_chain_file: + # cherrypy.server.ssl_certificate_chain = Config.tls_server_ca_chain_file + # protocol = "https" + # tls_info = "cert: {} {} {}".format(Config.tls_server_cert_file, + # Config.tls_private_key_file, + # Config.tls_server_ca_chain_file) + cherrypy.tree.mount(_PolicyWeb(), '/') - audit.info("running policy_handler web-server as {0}:{1}".format( - cherrypy.server.socket_host, cherrypy.server.socket_port)) - PolicyWeb.logger.info("running policy_handler web-server as %s:%d with config: %s", - cherrypy.server.socket_host, cherrypy.server.socket_port, - json.dumps(cherrypy.config)) + + PolicyWeb.logger.info( + "%s with config: %s", audit.info("running policy_handler as {}://{}:{} {}".format( + protocol, cherrypy.server.socket_host, cherrypy.server.socket_port, tls_info)), + json.dumps(cherrypy.config)) cherrypy.engine.start() class _PolicyWeb(object): @@ -67,17 +81,18 @@ class _PolicyWeb(object): req_info = _PolicyWeb._get_request_info(cherrypy.request) audit = Audit(job_name="get_latest_policy", req_message=req_info, headers=cherrypy.request.headers) - PolicyWeb.logger.info("%s policy_id=%s headers=%s", \ - req_info, policy_id, json.dumps(cherrypy.request.headers)) + PolicyWeb.logger.info("%s policy_id=%s headers=%s", + req_info, policy_id, json.dumps(cherrypy.request.headers)) latest_policy = PolicyRest.get_latest_policy((audit, policy_id, None, None)) or {} PolicyWeb.logger.info("res %s policy_id=%s latest_policy=%s", req_info, policy_id, json.dumps(latest_policy)) - success, http_status_code, _ = audit.audit_done(result=json.dumps(latest_policy)) - if not success: - cherrypy.response.status = http_status_code + _, http_status_code, _ = audit.audit_done(result=json.dumps(latest_policy)) + if http_status_code == AuditHttpCode.DATA_NOT_FOUND_OK.value: + http_status_code = PolicyWeb.DATA_NOT_FOUND_ERROR + cherrypy.response.status = http_status_code return latest_policy @@ -89,15 +104,20 @@ class _PolicyWeb(object): PolicyWeb.logger.info("%s", req_info) - result, policy_update = PolicyMatcher.get_latest_policies(audit) - if policy_update and isinstance(policy_update, PolicyUpdateMessage): - result["policy_update"] = policy_update.get_message() + result, policies, policy_filters = PolicyMatcher.get_deployed_policies(audit) + if not result: + result, policy_update = PolicyMatcher.build_catch_up_message( + audit, policies, policy_filters) + if policy_update and isinstance(policy_update, PolicyUpdateMessage): + result["policy_update"] = policy_update.get_message() - PolicyWeb.logger.info("result %s: %s", req_info, json.dumps(result)) + result_str = json.dumps(result, sort_keys=True) + PolicyWeb.logger.info("result %s: %s", req_info, result_str) - success, http_status_code, _ = audit.audit_done(result=json.dumps(result)) - if not success: - cherrypy.response.status = http_status_code + _, http_status_code, _ = audit.audit_done(result=result_str) + if http_status_code == AuditHttpCode.DATA_NOT_FOUND_OK.value: + http_status_code = PolicyWeb.DATA_NOT_FOUND_ERROR + cherrypy.response.status = http_status_code return result @@ -159,19 +179,21 @@ class _PolicyWeb(object): req_info = _PolicyWeb._get_request_info(cherrypy.request) audit = Audit(job_name="get_latest_policies", - req_message="{0}: {1}".format(req_info, str_policy_filter), \ - headers=cherrypy.request.headers) - PolicyWeb.logger.info("%s: policy_filter=%s headers=%s", \ - req_info, str_policy_filter, json.dumps(cherrypy.request.headers)) + req_message="{0}: {1}".format(req_info, str_policy_filter), + headers=cherrypy.request.headers) + PolicyWeb.logger.info("%s: policy_filter=%s headers=%s", + req_info, str_policy_filter, json.dumps(cherrypy.request.headers)) result = PolicyRest.get_latest_policies(audit, policy_filter=policy_filter) or {} + result_str = json.dumps(result, sort_keys=True) - PolicyWeb.logger.info("result %s: policy_filter=%s result=%s", \ - req_info, str_policy_filter, json.dumps(result)) + PolicyWeb.logger.info("result %s: policy_filter=%s result=%s", + req_info, str_policy_filter, result_str) - success, http_status_code, _ = audit.audit_done(result=json.dumps(result)) - if not success: - cherrypy.response.status = http_status_code + _, http_status_code, _ = audit.audit_done(result=result_str) + if http_status_code == AuditHttpCode.DATA_NOT_FOUND_OK.value: + http_status_code = PolicyWeb.DATA_NOT_FOUND_ERROR + cherrypy.response.status = http_status_code return result @@ -30,7 +30,7 @@ ECOMP is a trademark and service mark of AT&T Intellectual Property. <groupId>org.onap.dcaegen2.platform</groupId> <artifactId>policy-handler</artifactId> <name>dcaegen2-platform-policy-handler</name> - <version>4.4.0-SNAPSHOT</version> + <version>4.5.0-SNAPSHOT</version> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> diff --git a/requirements.txt b/requirements.txt index df9b56d..632dfe5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ CherryPy>=15.0.0,<16.0.0 psutil>=5.4.5,<6.0.0 requests>=2.18.4,<3.0.0 -websocket-client==0.49.0 +websocket-client==0.53.0 @@ -23,7 +23,7 @@ from setuptools import setup setup(
name='policyhandler',
description='DCAE-Controller policy-handler to communicate with policy-engine',
- version="4.4.0",
+ version="4.5.0",
author='Alex Shatov',
packages=['policyhandler'],
zip_safe=False,
@@ -31,7 +31,7 @@ setup( "CherryPy>=15.0.0,<16.0.0",
"psutil>=5.4.5,<6.0.0",
"requests>=2.18.4,<3.0.0",
- "websocket-client==0.49.0"
+ "websocket-client==0.53.0"
],
keywords='policy dcae controller',
classifiers=[
diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..0dcb2bb --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,299 @@ +# ============LICENSE_START======================================================= +# Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# 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. +# ============LICENSE_END========================================================= +# +# ECOMP is a trademark and service mark of AT&T Intellectual Property. +""" +startdard pytest file that contains the shared fixtures +https://docs.pytest.org/en/latest/fixture.html +""" +import base64 +import copy +import json + +import pytest + +from policyhandler.config import Config +from policyhandler.deploy_handler import DeployHandler +from policyhandler.discovery import DiscoveryClient +from policyhandler.onap.audit import Audit +from policyhandler.policy_consts import CATCH_UP, POLICY_NAME, TARGET_ENTITY +from policyhandler.policy_receiver import PolicyReceiver +from policyhandler.policy_rest import PolicyRest + +from .mock_deploy_handler import MockDeploymentHandler +from .mock_policy_engine import MockPolicyEngine +from .mock_settings import Settings +from .mock_tracker import MockHttpResponse, Tracker +from .mock_websocket import MockWebSocket + + +@pytest.fixture(autouse=True) +def _auto_test_cycle(request): + """log all the test starts and ends""" + if request.cls: + test_name = "%s::%s::%s" % (request.module.__name__, + request.cls.__name__, + request.function.__name__) + else: + test_name = "%s::%s" % (request.module.__name__, request.function.__name__) + + Tracker.reset(test_name) + if Settings.logger: + Settings.logger.info(">>>>>>> start %s", test_name) + yield _auto_test_cycle + if Settings.logger: + Settings.logger.info(">>>>>>> tracked messages: %s", Tracker.to_string()) + Settings.logger.info(">>>>>>> ended %s", test_name) + + +@pytest.fixture(scope="session", autouse=True) +def _auto_setup_policy_engine(): + """initialize the mock-policy-engine per the whole test session""" + Settings.init() + + Settings.logger.info("create _auto_setup_policy_engine") + MockPolicyEngine.init() + yield _auto_setup_policy_engine + Settings.logger.info("teardown _auto_setup_policy_engine") + + +@pytest.fixture() +def fix_pdp_post(monkeypatch): + """monkeyed request /getConfig to PDP""" + def monkeyed_policy_rest_post(uri, json=None, **kwargs): + """monkeypatch for the POST to policy-engine""" + res_json = MockPolicyEngine.get_config(json.get(POLICY_NAME)) + return MockHttpResponse("post", uri, res_json, json=json, **kwargs) + + Settings.logger.info("setup fix_pdp_post") + PolicyRest._lazy_init() + monkeypatch.setattr('policyhandler.policy_rest.PolicyRest._requests_session.post', + monkeyed_policy_rest_post) + yield fix_pdp_post + Settings.logger.info("teardown fix_pdp_post") + +@pytest.fixture() +def fix_deploy_handler(monkeypatch): + """monkeyed requests to deployment-handler""" + def monkeyed_deploy_handler_put(uri, **kwargs): + """monkeypatch for policy-update request.put to deploy_handler""" + return MockHttpResponse("put", uri, MockDeploymentHandler.default_response(), + **kwargs) + + def monkeyed_deploy_handler_get(uri, **kwargs): + """monkeypatch policy-update request.get to deploy_handler""" + return MockHttpResponse("get", uri, MockDeploymentHandler.get_deployed_policies(), + **kwargs) + + Settings.logger.info("setup fix_deploy_handler") + audit = None + if DeployHandler._lazy_inited is False: + audit = Audit(req_message="fix_deploy_handler") + DeployHandler._lazy_init(audit) + + monkeypatch.setattr('policyhandler.deploy_handler.DeployHandler._requests_session.put', + monkeyed_deploy_handler_put) + monkeypatch.setattr('policyhandler.deploy_handler.DeployHandler._requests_session.get', + monkeyed_deploy_handler_get) + + yield fix_deploy_handler + if audit: + audit.audit_done("teardown") + Settings.logger.info("teardown fix_deploy_handler") + + +@pytest.fixture() +def fix_cherrypy_engine_exit(monkeypatch): + """monkeyed cherrypy.engine.exit()""" + Settings.logger.info("setup fix_cherrypy_engine_exit") + + def monkeyed_cherrypy_engine_exit(): + """monkeypatch for deploy_handler""" + Settings.logger.info("cherrypy_engine_exit()") + + monkeypatch.setattr('policyhandler.web_server.cherrypy.engine.exit', + monkeyed_cherrypy_engine_exit) + yield fix_cherrypy_engine_exit + Settings.logger.info("teardown fix_cherrypy_engine_exit") + + +@pytest.fixture() +def fix_pdp_post_big(monkeypatch): + """monkeyed request /getConfig to PDP""" + def monkeyed_policy_rest_post(uri, **kwargs): + """monkeypatch for the POST to policy-engine""" + res_json = MockPolicyEngine.get_configs_all() + return MockHttpResponse("post", uri, res_json, **kwargs) + + Settings.logger.info("setup fix_pdp_post_big") + PolicyRest._lazy_init() + monkeypatch.setattr('policyhandler.policy_rest.PolicyRest._requests_session.post', + monkeyed_policy_rest_post) + yield fix_pdp_post_big + Settings.logger.info("teardown fix_pdp_post_big") + + +class MockException(Exception): + """mock exception""" + pass + + +@pytest.fixture() +def fix_pdp_post_boom(monkeypatch): + """monkeyed request /getConfig to PDP - exception""" + def monkeyed_policy_rest_post_boom(uri, **_): + """monkeypatch for the POST to policy-engine""" + raise MockException("fix_pdp_post_boom {}".format(uri)) + + Settings.logger.info("setup fix_pdp_post_boom") + PolicyRest._lazy_init() + monkeypatch.setattr('policyhandler.policy_rest.PolicyRest._requests_session.post', + monkeyed_policy_rest_post_boom) + yield fix_pdp_post_boom + Settings.logger.info("teardown fix_pdp_post_boom") + + +@pytest.fixture() +def fix_select_latest_policies_boom(monkeypatch): + """monkeyed exception""" + def monkeyed_boom(*args, **kwargs): + """monkeypatch for the select_latest_policies""" + raise MockException("monkeyed_boom") + + Settings.logger.info("setup fix_select_latest_policies_boom") + monkeypatch.setattr('policyhandler.policy_utils.PolicyUtils.select_latest_policies', + monkeyed_boom) + monkeypatch.setattr('policyhandler.policy_utils.PolicyUtils.select_latest_policy', + monkeyed_boom) + monkeypatch.setattr('policyhandler.policy_utils.PolicyUtils.extract_policy_id', + monkeyed_boom) + + yield fix_select_latest_policies_boom + Settings.logger.info("teardown fix_select_latest_policies_boom") + +@pytest.fixture() +def fix_discovery(monkeypatch): + """monkeyed discovery request.get""" + def monkeyed_discovery(uri): + """monkeypatch for get from consul""" + res_json = {} + dh_service = None + if Config.discovered_config: + _, dh_config = Config.discovered_config.get_by_key(Config.DEPLOY_HANDLER) + dh_config = dh_config and dh_config.get(TARGET_ENTITY) + if dh_service and uri == DiscoveryClient.CONSUL_SERVICE_MASK.format( + Config.consul_url, dh_service): + res_json = [{ + "ServiceAddress": "1.1.1.1", + "ServicePort": "123" + }] + elif uri == DiscoveryClient.CONSUL_KV_MASK.format( + Config.consul_url, Config.system_name): + res_json = [{"Value": base64.b64encode( + json.dumps(Settings.mock_config).encode()).decode("utf-8")}] + return MockHttpResponse("get", uri, res_json) + + Settings.logger.info("setup fix_discovery") + monkeypatch.setattr('policyhandler.discovery.requests.get', monkeyed_discovery) + yield fix_discovery + Settings.logger.info("teardown fix_discovery") + + +@pytest.fixture(scope="module") +def fix_auto_catch_up(): + """increase the frequency of auto catch_up""" + + Settings.logger.info("setup fix_auto_catch_up %s", json.dumps(Settings.mock_config)) + prev_config = copy.deepcopy(Settings.mock_config) + Settings.mock_config.get(Config.SERVICE_NAME_POLICY_HANDLER, {}) \ + .get(CATCH_UP, {})[Config.TIMER_INTERVAL] = 5 + Settings.logger.info("fix_auto_catch_up %s", json.dumps(Settings.mock_config)) + Settings.rediscover_config() + + yield fix_auto_catch_up + Settings.rediscover_config(prev_config) + Settings.logger.info("teardown fix_auto_catch_up") + + +@pytest.fixture() +def fix_deploy_handler_413(monkeypatch): + """monkeyed failed discovery request.get""" + def monkeyed_deploy_handler_put(uri, **kwargs): + """monkeypatch for deploy_handler""" + return MockHttpResponse( + "put", uri, + {"server_instance_uuid": Settings.deploy_handler_instance_uuid}, + status_code=413, **kwargs + ) + + def monkeyed_deploy_handler_get(uri, **kwargs): + """monkeypatch policy-update request.get to deploy_handler""" + return MockHttpResponse("get", uri, MockDeploymentHandler.get_deployed_policies(), + **kwargs) + + Settings.logger.info("setup fix_deploy_handler_413") + audit = None + if DeployHandler._lazy_inited is False: + audit = Audit(req_message="fix_deploy_handler_413") + DeployHandler._lazy_init(audit) + + monkeypatch.setattr('policyhandler.deploy_handler.DeployHandler._requests_session.put', + monkeyed_deploy_handler_put) + monkeypatch.setattr('policyhandler.deploy_handler.DeployHandler._requests_session.get', + monkeyed_deploy_handler_get) + + yield fix_deploy_handler_413 + if audit: + audit.audit_done("teardown") + Settings.logger.info("teardown fix_deploy_handler_413") + + +@pytest.fixture() +def fix_deploy_handler_404(monkeypatch): + """monkeyed failed discovery request.get""" + def monkeyed_deploy_handler_put(uri, **kwargs): + """monkeypatch for deploy_handler""" + return MockHttpResponse("put", uri, MockDeploymentHandler.default_response(), + **kwargs) + + def monkeyed_deploy_handler_get(uri, **kwargs): + """monkeypatch policy-update request.get to deploy_handler""" + return MockHttpResponse("get", uri, MockDeploymentHandler.default_response(), + **kwargs) + + Settings.logger.info("setup fix_deploy_handler_404") + audit = None + if DeployHandler._lazy_inited is False: + audit = Audit(req_message="fix_deploy_handler_404") + DeployHandler._lazy_init(audit) + + monkeypatch.setattr('policyhandler.deploy_handler.DeployHandler._requests_session.put', + monkeyed_deploy_handler_put) + monkeypatch.setattr('policyhandler.deploy_handler.DeployHandler._requests_session.get', + monkeyed_deploy_handler_get) + + yield fix_deploy_handler_404 + if audit: + audit.audit_done("teardown") + Settings.logger.info("teardown fix_deploy_handler_404") + +@pytest.fixture() +def fix_policy_receiver_websocket(monkeypatch): + """monkeyed websocket for policy_receiver""" + Settings.logger.info("setup fix_policy_receiver_websocket") + monkeypatch.setattr('policyhandler.policy_receiver.websocket', MockWebSocket) + yield fix_policy_receiver_websocket + Settings.logger.info("teardown fix_policy_receiver_websocket") diff --git a/tests/mock_config.json b/tests/mock_config.json index 7ec0ac6..ef02a15 100644 --- a/tests/mock_config.json +++ b/tests/mock_config.json @@ -6,13 +6,13 @@ "policy_retry_count" : 5, "policy_retry_sleep" : 5, "catch_up" : { - "interval" : 10 + "interval" : 3600 }, "reconfigure" : { - "interval" : 10 + "interval" : 3600 }, "policy_engine" : { - "url" : "https://pdp-server:8081", + "url" : "https://unit-test-pdp-server:8081000", "path_notifications" : "/pdp/notifications", "path_api" : "/pdp/api/", "headers" : { @@ -24,16 +24,19 @@ }, "target_entity" : "policy_engine", "tls_ca_mode" : "cert_directory", - "tls_wss_ca_mode" : "cert_directory" + "tls_wss_ca_mode" : "cert_directory", + "timeout_in_secs": 1, + "ws_ping_interval_in_secs": 1800 }, "deploy_handler" : { "target_entity" : "deployment_handler", - "url" : "http://deployment_handler:8188", + "url" : "http://unit-test-deployment_handler:8188000", "max_msg_length_mb" : 5, "query" : { "cfy_tenant_name" : "default_tenant" }, - "tls_ca_mode" : "cert_directory" + "tls_ca_mode" : "cert_directory", + "timeout_in_secs": 1 } } } diff --git a/tests/mock_deploy_handler.py b/tests/mock_deploy_handler.py new file mode 100644 index 0000000..ebbbfc7 --- /dev/null +++ b/tests/mock_deploy_handler.py @@ -0,0 +1,48 @@ +# ============LICENSE_START======================================================= +# Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# 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. +# ============LICENSE_END========================================================= +# +# ECOMP is a trademark and service mark of AT&T Intellectual Property. +"""mocking for the deployment-handler - shared by many tests""" + +from policyhandler.policy_consts import (POLICY_BODY, POLICY_ID, + POLICY_VERSION, POLICY_VERSIONS) + +from .mock_policy_engine import MockPolicyEngine +from .mock_settings import Settings + + +class MockDeploymentHandler(object): + """pretend this is the deployment-handler""" + + @staticmethod + def default_response(): + """generate the deployed policies message""" + return {"server_instance_uuid": Settings.deploy_handler_instance_uuid} + + @staticmethod + def get_deployed_policies(): + """generate the deployed policies message""" + response = MockDeploymentHandler.default_response() + policies = dict( + (policy_id, { + POLICY_ID: policy_id, + POLICY_VERSIONS: {policy.get(POLICY_BODY, {}).get(POLICY_VERSION, "999"): True}, + "pending_update": False}) + for policy_id, policy in ( + MockPolicyEngine.gen_all_policies_latest(version_offset=1).items())) + response["policies"] = policies + + return response diff --git a/tests/mock_expected.py b/tests/mock_expected.py new file mode 100644 index 0000000..c10215d --- /dev/null +++ b/tests/mock_expected.py @@ -0,0 +1,3013 @@ +# ============LICENSE_START======================================================= +# Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# 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. +# ============LICENSE_END========================================================= +# +# ECOMP is a trademark and service mark of AT&T Intellectual Property. +"""expected message history per test""" + + +HISTORY_EXPECTED = { + "tests.test_policy_rest::test_get_policy_latest" : [ + { + "request": { + "headers": { + "Accept": "application/json", + "Authorization": "Basic auth", + "ClientAuth": "Basic user", + "Content-Type": "application/json", + "Environment": "TEST", + "X-ECOMP-RequestID": "*" + }, + "json": { + "policyName": "test_scope_prefix.Config_sit" + }, + "method": "post", + "params": None, + "uri": "https://unit-test-pdp-server:8081000/pdp/api/getConfig" + }, + "res": "*", + "status_code": 200 + } + ], + "tests.test_policyhandler::WebServerTest::test_web_all_policies_latest": [ + { + "request": { + "headers": { + "X-ECOMP-RequestID": "*" + }, + "json": None, + "method": "get", + "params": { + "cfy_tenant_name": "default_tenant" + }, + "uri": "http://unit-test-deployment_handler:8188000/policy" + }, + "res": "*", + "status_code": 200 + }, + { + "request": { + "headers": { + "Accept": "application/json", + "Authorization": "Basic auth", + "ClientAuth": "Basic user", + "Content-Type": "application/json", + "Environment": "TEST", + "X-ECOMP-RequestID": "*" + }, + "json": { + "policyName": "test_scope_prefix.Config_.*" + }, + "method": "post", + "params": None, + "uri": "https://unit-test-pdp-server:8081000/pdp/api/getConfig" + }, + "res": "*", + "status_code": 200 + } + ], + "tests.test_policyhandler::WebServerTest::test_web_policies_latest": [ + { + "request": { + "headers": { + "Accept": "application/json", + "Authorization": "Basic auth", + "ClientAuth": "Basic user", + "Content-Type": "application/json", + "Environment": "TEST", + "X-ECOMP-RequestID": "*" + }, + "json": { + "policyName": "test_scope_prefix.Config_amet.*" + }, + "method": "post", + "params": None, + "uri": "https://unit-test-pdp-server:8081000/pdp/api/getConfig" + }, + "res": "*", + "status_code": 200 + } + ], + "tests.test_policyhandler::WebServerTest::test_web_policy_latest": [ + { + "request": { + "headers": { + "Accept": "application/json", + "Authorization": "Basic auth", + "ClientAuth": "Basic user", + "Content-Type": "application/json", + "Environment": "TEST", + "X-ECOMP-RequestID": "*" + }, + "json": { + "policyName": "test_scope_prefix.Config_sit" + }, + "method": "post", + "params": None, + "uri": "https://unit-test-pdp-server:8081000/pdp/api/getConfig" + }, + "res": "*", + "status_code": 200 + } + ], + "tests.test_policyhandler::WebServerTest::test_zzz_get_catch_up": [ + { + "request": { + "headers": { + "X-ECOMP-RequestID": "*" + }, + "json": None, + "method": "get", + "params": { + "cfy_tenant_name": "default_tenant" + }, + "uri": "http://unit-test-deployment_handler:8188000/policy" + }, + "res": "*", + "status_code": 200 + }, + { + "request": { + "headers": { + "Accept": "application/json", + "Authorization": "Basic auth", + "ClientAuth": "Basic user", + "Content-Type": "application/json", + "Environment": "TEST", + "X-ECOMP-RequestID": "*" + }, + "json": { + "policyName": "test_scope_prefix.Config_.*" + }, + "method": "post", + "params": None, + "uri": "https://unit-test-pdp-server:8081000/pdp/api/getConfig" + }, + "res": "*", + "status_code": 200 + }, + { + "request": { + "headers": { + "X-ECOMP-RequestID": "*" + }, + "json": { + "catch_up": True, + "latest_policies": { + "test_scope_prefix.Config_Lorem": { + "policy_body": { + "config": { + "policy_hello": "world!", + "policy_updated_from_ver": "0", + "policy_updated_to_ver": "1", + "updated_policy_id": "test_scope_prefix.Config_Lorem" + }, + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_Lorem.1.xml", + "policyVersion": "1", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_Lorem" + }, + "test_scope_prefix.Config_amet": { + "policy_body": { + "config": { + "policy_hello": "world!", + "policy_updated_from_ver": "4", + "policy_updated_to_ver": "5", + "updated_policy_id": "test_scope_prefix.Config_amet" + }, + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_amet.5.xml", + "policyVersion": "5", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_amet" + }, + "test_scope_prefix.Config_ametist": { + "policy_body": { + "config": { + "policy_hello": "world!", + "policy_updated_from_ver": "6", + "policy_updated_to_ver": "7", + "updated_policy_id": "test_scope_prefix.Config_ametist" + }, + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_ametist.7.xml", + "policyVersion": "7", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_ametist" + }, + "test_scope_prefix.Config_consectetur": { + "policy_body": { + "config": { + "policy_hello": "world!", + "policy_updated_from_ver": "5", + "policy_updated_to_ver": "6", + "updated_policy_id": "test_scope_prefix.Config_consectetur" + }, + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_consectetur.6.xml", + "policyVersion": "6", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_consectetur" + }, + "test_scope_prefix.Config_dolor": { + "policy_body": { + "config": { + "policy_hello": "world!", + "policy_updated_from_ver": "2", + "policy_updated_to_ver": "3", + "updated_policy_id": "test_scope_prefix.Config_dolor" + }, + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_dolor.3.xml", + "policyVersion": "3", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_dolor" + }, + "test_scope_prefix.Config_ipsum": { + "policy_body": { + "config": { + "policy_hello": "world!", + "policy_updated_from_ver": "1", + "policy_updated_to_ver": "2", + "updated_policy_id": "test_scope_prefix.Config_ipsum" + }, + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_ipsum.2.xml", + "policyVersion": "2", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_ipsum" + }, + "test_scope_prefix.Config_sit": { + "policy_body": { + "config": { + "policy_hello": "world!", + "policy_updated_from_ver": "3", + "policy_updated_to_ver": "4", + "updated_policy_id": "test_scope_prefix.Config_sit" + }, + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_sit.4.xml", + "policyVersion": "4", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_sit" + } + }, + "policy_filter_matches": { + "test_scope_prefix.Config_Lorem": {}, + "test_scope_prefix.Config_amet": {}, + "test_scope_prefix.Config_ametist": {}, + "test_scope_prefix.Config_consectetur": {}, + "test_scope_prefix.Config_dolor": {}, + "test_scope_prefix.Config_ipsum": {}, + "test_scope_prefix.Config_sit": {} + }, + "removed_policies": {} + }, + "method": "put", + "params": { + "cfy_tenant_name": "default_tenant" + }, + "uri": "http://unit-test-deployment_handler:8188000/policy" + }, + "res": "*", + "status_code": 200 + }, + { + "request": { + "headers": { + "X-ECOMP-RequestID": "*" + }, + "json": None, + "method": "get", + "params": { + "cfy_tenant_name": "default_tenant" + }, + "uri": "http://unit-test-deployment_handler:8188000/policy" + }, + "res": "*", + "status_code": 200 + }, + { + "request": { + "headers": { + "Accept": "application/json", + "Authorization": "Basic auth", + "ClientAuth": "Basic user", + "Content-Type": "application/json", + "Environment": "TEST", + "X-ECOMP-RequestID": "*" + }, + "json": { + "policyName": "test_scope_prefix.Config_.*" + }, + "method": "post", + "params": None, + "uri": "https://unit-test-pdp-server:8081000/pdp/api/getConfig" + }, + "res": "*", + "status_code": 200 + }, + { + "request": { + "headers": { + "X-ECOMP-RequestID": "*" + }, + "json": { + "catch_up": True, + "latest_policies": { + "test_scope_prefix.Config_Lorem": { + "policy_body": { + "config": { + "policy_hello": "world!", + "policy_updated_from_ver": "0", + "policy_updated_to_ver": "1", + "updated_policy_id": "test_scope_prefix.Config_Lorem" + }, + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_Lorem.1.xml", + "policyVersion": "1", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_Lorem" + }, + "test_scope_prefix.Config_amet": { + "policy_body": { + "config": { + "policy_hello": "world!", + "policy_updated_from_ver": "4", + "policy_updated_to_ver": "5", + "updated_policy_id": "test_scope_prefix.Config_amet" + }, + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_amet.5.xml", + "policyVersion": "5", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_amet" + }, + "test_scope_prefix.Config_ametist": { + "policy_body": { + "config": { + "policy_hello": "world!", + "policy_updated_from_ver": "6", + "policy_updated_to_ver": "7", + "updated_policy_id": "test_scope_prefix.Config_ametist" + }, + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_ametist.7.xml", + "policyVersion": "7", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_ametist" + }, + "test_scope_prefix.Config_consectetur": { + "policy_body": { + "config": { + "policy_hello": "world!", + "policy_updated_from_ver": "5", + "policy_updated_to_ver": "6", + "updated_policy_id": "test_scope_prefix.Config_consectetur" + }, + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_consectetur.6.xml", + "policyVersion": "6", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_consectetur" + }, + "test_scope_prefix.Config_dolor": { + "policy_body": { + "config": { + "policy_hello": "world!", + "policy_updated_from_ver": "2", + "policy_updated_to_ver": "3", + "updated_policy_id": "test_scope_prefix.Config_dolor" + }, + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_dolor.3.xml", + "policyVersion": "3", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_dolor" + }, + "test_scope_prefix.Config_ipsum": { + "policy_body": { + "config": { + "policy_hello": "world!", + "policy_updated_from_ver": "1", + "policy_updated_to_ver": "2", + "updated_policy_id": "test_scope_prefix.Config_ipsum" + }, + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_ipsum.2.xml", + "policyVersion": "2", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_ipsum" + }, + "test_scope_prefix.Config_sit": { + "policy_body": { + "config": { + "policy_hello": "world!", + "policy_updated_from_ver": "3", + "policy_updated_to_ver": "4", + "updated_policy_id": "test_scope_prefix.Config_sit" + }, + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_sit.4.xml", + "policyVersion": "4", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_sit" + } + }, + "policy_filter_matches": { + "test_scope_prefix.Config_Lorem": {}, + "test_scope_prefix.Config_amet": {}, + "test_scope_prefix.Config_ametist": {}, + "test_scope_prefix.Config_consectetur": {}, + "test_scope_prefix.Config_dolor": {}, + "test_scope_prefix.Config_ipsum": {}, + "test_scope_prefix.Config_sit": {} + }, + "removed_policies": {} + }, + "method": "put", + "params": { + "cfy_tenant_name": "default_tenant" + }, + "uri": "http://unit-test-deployment_handler:8188000/policy" + }, + "res": "*", + "status_code": 200 + } + ], + "tests.test_policyhandler::WebServerTest::test_zzz_policy_updates_and_catch_ups": [ + { + "request": { + "headers": { + "X-ECOMP-RequestID": "*" + }, + "json": None, + "method": "get", + "params": { + "cfy_tenant_name": "default_tenant" + }, + "uri": "http://unit-test-deployment_handler:8188000/policy" + }, + "res": "*", + "status_code": 200 + }, + { + "request": { + "headers": { + "Accept": "application/json", + "Authorization": "Basic auth", + "ClientAuth": "Basic user", + "Content-Type": "application/json", + "Environment": "TEST", + "X-ECOMP-RequestID": "*" + }, + "json": { + "policyName": "test_scope_prefix.Config_.*" + }, + "method": "post", + "params": None, + "uri": "https://unit-test-pdp-server:8081000/pdp/api/getConfig" + }, + "res": "*", + "status_code": 200 + }, + { + "request": { + "headers": { + "X-ECOMP-RequestID": "*" + }, + "json": { + "catch_up": True, + "latest_policies": { + "test_scope_prefix.Config_Lorem": { + "policy_body": { + "config": { + "policy_hello": "world!", + "policy_updated_from_ver": "0", + "policy_updated_to_ver": "1", + "updated_policy_id": "test_scope_prefix.Config_Lorem" + }, + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_Lorem.1.xml", + "policyVersion": "1", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_Lorem" + }, + "test_scope_prefix.Config_amet": { + "policy_body": { + "config": { + "policy_hello": "world!", + "policy_updated_from_ver": "4", + "policy_updated_to_ver": "5", + "updated_policy_id": "test_scope_prefix.Config_amet" + }, + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_amet.5.xml", + "policyVersion": "5", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_amet" + }, + "test_scope_prefix.Config_ametist": { + "policy_body": { + "config": { + "policy_hello": "world!", + "policy_updated_from_ver": "6", + "policy_updated_to_ver": "7", + "updated_policy_id": "test_scope_prefix.Config_ametist" + }, + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_ametist.7.xml", + "policyVersion": "7", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_ametist" + }, + "test_scope_prefix.Config_consectetur": { + "policy_body": { + "config": { + "policy_hello": "world!", + "policy_updated_from_ver": "5", + "policy_updated_to_ver": "6", + "updated_policy_id": "test_scope_prefix.Config_consectetur" + }, + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_consectetur.6.xml", + "policyVersion": "6", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_consectetur" + }, + "test_scope_prefix.Config_dolor": { + "policy_body": { + "config": { + "policy_hello": "world!", + "policy_updated_from_ver": "2", + "policy_updated_to_ver": "3", + "updated_policy_id": "test_scope_prefix.Config_dolor" + }, + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_dolor.3.xml", + "policyVersion": "3", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_dolor" + }, + "test_scope_prefix.Config_ipsum": { + "policy_body": { + "config": { + "policy_hello": "world!", + "policy_updated_from_ver": "1", + "policy_updated_to_ver": "2", + "updated_policy_id": "test_scope_prefix.Config_ipsum" + }, + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_ipsum.2.xml", + "policyVersion": "2", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_ipsum" + }, + "test_scope_prefix.Config_sit": { + "policy_body": { + "config": { + "policy_hello": "world!", + "policy_updated_from_ver": "3", + "policy_updated_to_ver": "4", + "updated_policy_id": "test_scope_prefix.Config_sit" + }, + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_sit.4.xml", + "policyVersion": "4", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_sit" + } + }, + "policy_filter_matches": { + "test_scope_prefix.Config_Lorem": {}, + "test_scope_prefix.Config_amet": {}, + "test_scope_prefix.Config_ametist": {}, + "test_scope_prefix.Config_consectetur": {}, + "test_scope_prefix.Config_dolor": {}, + "test_scope_prefix.Config_ipsum": {}, + "test_scope_prefix.Config_sit": {} + }, + "removed_policies": {} + }, + "method": "put", + "params": { + "cfy_tenant_name": "default_tenant" + }, + "uri": "http://unit-test-deployment_handler:8188000/policy" + }, + "res": "*", + "status_code": 200 + }, + { + "request": { + "headers": { + "X-ECOMP-RequestID": "*" + }, + "json": None, + "method": "get", + "params": { + "cfy_tenant_name": "default_tenant" + }, + "uri": "http://unit-test-deployment_handler:8188000/policy" + }, + "res": "*", + "status_code": 200 + }, + { + "request": { + "headers": { + "Accept": "application/json", + "Authorization": "Basic auth", + "ClientAuth": "Basic user", + "Content-Type": "application/json", + "Environment": "TEST", + "X-ECOMP-RequestID": "*" + }, + "json": { + "policyName": "test_scope_prefix.Config_ipsum" + }, + "method": "post", + "params": None, + "uri": "https://unit-test-pdp-server:8081000/pdp/api/getConfig" + }, + "res": "*", + "status_code": 200 + }, + { + "request": { + "headers": { + "Accept": "application/json", + "Authorization": "Basic auth", + "ClientAuth": "Basic user", + "Content-Type": "application/json", + "Environment": "TEST", + "X-ECOMP-RequestID": "*" + }, + "json": { + "policyName": "test_scope_prefix.Config_sit" + }, + "method": "post", + "params": None, + "uri": "https://unit-test-pdp-server:8081000/pdp/api/getConfig" + }, + "res": "*", + "status_code": 200 + }, + { + "request": { + "headers": { + "Accept": "application/json", + "Authorization": "Basic auth", + "ClientAuth": "Basic user", + "Content-Type": "application/json", + "Environment": "TEST", + "X-ECOMP-RequestID": "*" + }, + "json": { + "policyName": "test_scope_prefix.Config_consectetur" + }, + "method": "post", + "params": None, + "uri": "https://unit-test-pdp-server:8081000/pdp/api/getConfig" + }, + "res": "*", + "status_code": 200 + }, + { + "request": { + "headers": { + "X-ECOMP-RequestID": "*" + }, + "json": { + "catch_up": False, + "latest_policies": { + "test_scope_prefix.Config_consectetur": { + "policy_body": { + "config": { + "policy_hello": "world!", + "policy_updated_from_ver": "5", + "policy_updated_to_ver": "6", + "updated_policy_id": "test_scope_prefix.Config_consectetur" + }, + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_consectetur.6.xml", + "policyVersion": "6", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_consectetur" + }, + "test_scope_prefix.Config_ipsum": { + "policy_body": { + "config": { + "policy_hello": "world!", + "policy_updated_from_ver": "1", + "policy_updated_to_ver": "2", + "updated_policy_id": "test_scope_prefix.Config_ipsum" + }, + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_ipsum.2.xml", + "policyVersion": "2", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_ipsum" + }, + "test_scope_prefix.Config_sit": { + "policy_body": { + "config": { + "policy_hello": "world!", + "policy_updated_from_ver": "3", + "policy_updated_to_ver": "4", + "updated_policy_id": "test_scope_prefix.Config_sit" + }, + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_sit.4.xml", + "policyVersion": "4", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_sit" + } + }, + "policy_filter_matches": { + "test_scope_prefix.Config_consectetur": {}, + "test_scope_prefix.Config_ipsum": {}, + "test_scope_prefix.Config_sit": {} + }, + "removed_policies": {} + }, + "method": "put", + "params": { + "cfy_tenant_name": "default_tenant" + }, + "uri": "http://unit-test-deployment_handler:8188000/policy" + }, + "res": "*", + "status_code": 200 + } + ], + "tests.test_policyhandler::WebServerTest::test_zzzzz_shutdown": [ + { + "request": { + "headers": { + "X-ECOMP-RequestID": "*" + }, + "json": None, + "method": "get", + "params": { + "cfy_tenant_name": "default_tenant" + }, + "uri": "http://unit-test-deployment_handler:8188000/policy" + }, + "res": "*", + "status_code": 200 + }, + { + "request": { + "headers": { + "Accept": "application/json", + "Authorization": "Basic auth", + "ClientAuth": "Basic user", + "Content-Type": "application/json", + "Environment": "TEST", + "X-ECOMP-RequestID": "*" + }, + "json": { + "policyName": "test_scope_prefix.Config_.*" + }, + "method": "post", + "params": None, + "uri": "https://unit-test-pdp-server:8081000/pdp/api/getConfig" + }, + "res": "*", + "status_code": 200 + }, + { + "request": { + "headers": { + "X-ECOMP-RequestID": "*" + }, + "json": { + "catch_up": True, + "latest_policies": { + "test_scope_prefix.Config_Lorem": { + "policy_body": { + "config": { + "policy_hello": "world!", + "policy_updated_from_ver": "0", + "policy_updated_to_ver": "1", + "updated_policy_id": "test_scope_prefix.Config_Lorem" + }, + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_Lorem.1.xml", + "policyVersion": "1", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_Lorem" + }, + "test_scope_prefix.Config_amet": { + "policy_body": { + "config": { + "policy_hello": "world!", + "policy_updated_from_ver": "4", + "policy_updated_to_ver": "5", + "updated_policy_id": "test_scope_prefix.Config_amet" + }, + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_amet.5.xml", + "policyVersion": "5", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_amet" + }, + "test_scope_prefix.Config_ametist": { + "policy_body": { + "config": { + "policy_hello": "world!", + "policy_updated_from_ver": "6", + "policy_updated_to_ver": "7", + "updated_policy_id": "test_scope_prefix.Config_ametist" + }, + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_ametist.7.xml", + "policyVersion": "7", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_ametist" + }, + "test_scope_prefix.Config_consectetur": { + "policy_body": { + "config": { + "policy_hello": "world!", + "policy_updated_from_ver": "5", + "policy_updated_to_ver": "6", + "updated_policy_id": "test_scope_prefix.Config_consectetur" + }, + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_consectetur.6.xml", + "policyVersion": "6", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_consectetur" + }, + "test_scope_prefix.Config_dolor": { + "policy_body": { + "config": { + "policy_hello": "world!", + "policy_updated_from_ver": "2", + "policy_updated_to_ver": "3", + "updated_policy_id": "test_scope_prefix.Config_dolor" + }, + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_dolor.3.xml", + "policyVersion": "3", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_dolor" + }, + "test_scope_prefix.Config_ipsum": { + "policy_body": { + "config": { + "policy_hello": "world!", + "policy_updated_from_ver": "1", + "policy_updated_to_ver": "2", + "updated_policy_id": "test_scope_prefix.Config_ipsum" + }, + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_ipsum.2.xml", + "policyVersion": "2", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_ipsum" + }, + "test_scope_prefix.Config_sit": { + "policy_body": { + "config": { + "policy_hello": "world!", + "policy_updated_from_ver": "3", + "policy_updated_to_ver": "4", + "updated_policy_id": "test_scope_prefix.Config_sit" + }, + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_sit.4.xml", + "policyVersion": "4", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_sit" + } + }, + "policy_filter_matches": { + "test_scope_prefix.Config_Lorem": {}, + "test_scope_prefix.Config_amet": {}, + "test_scope_prefix.Config_ametist": {}, + "test_scope_prefix.Config_consectetur": {}, + "test_scope_prefix.Config_dolor": {}, + "test_scope_prefix.Config_ipsum": {}, + "test_scope_prefix.Config_sit": {} + }, + "removed_policies": {} + }, + "method": "put", + "params": { + "cfy_tenant_name": "default_tenant" + }, + "uri": "http://unit-test-deployment_handler:8188000/policy" + }, + "res": "*", + "status_code": 200 + }, + { + "request": { + "headers": { + "X-ECOMP-RequestID": "*" + }, + "json": None, + "method": "get", + "params": { + "cfy_tenant_name": "default_tenant" + }, + "uri": "http://unit-test-deployment_handler:8188000/policy" + }, + "res": "*", + "status_code": 200 + }, + { + "request": { + "headers": { + "Accept": "application/json", + "Authorization": "Basic auth", + "ClientAuth": "Basic user", + "Content-Type": "application/json", + "Environment": "TEST", + "X-ECOMP-RequestID": "*" + }, + "json": { + "policyName": "test_scope_prefix.Config_ipsum" + }, + "method": "post", + "params": None, + "uri": "https://unit-test-pdp-server:8081000/pdp/api/getConfig" + }, + "res": "*", + "status_code": 200 + }, + { + "request": { + "headers": { + "Accept": "application/json", + "Authorization": "Basic auth", + "ClientAuth": "Basic user", + "Content-Type": "application/json", + "Environment": "TEST", + "X-ECOMP-RequestID": "*" + }, + "json": { + "policyName": "test_scope_prefix.Config_sit" + }, + "method": "post", + "params": None, + "uri": "https://unit-test-pdp-server:8081000/pdp/api/getConfig" + }, + "res": "*", + "status_code": 200 + }, + { + "request": { + "headers": { + "Accept": "application/json", + "Authorization": "Basic auth", + "ClientAuth": "Basic user", + "Content-Type": "application/json", + "Environment": "TEST", + "X-ECOMP-RequestID": "*" + }, + "json": { + "policyName": "test_scope_prefix.Config_consectetur" + }, + "method": "post", + "params": None, + "uri": "https://unit-test-pdp-server:8081000/pdp/api/getConfig" + }, + "res": "*", + "status_code": 200 + }, + { + "request": { + "headers": { + "X-ECOMP-RequestID": "*" + }, + "json": { + "catch_up": False, + "latest_policies": { + "test_scope_prefix.Config_consectetur": { + "policy_body": { + "config": { + "policy_hello": "world!", + "policy_updated_from_ver": "5", + "policy_updated_to_ver": "6", + "updated_policy_id": "test_scope_prefix.Config_consectetur" + }, + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_consectetur.6.xml", + "policyVersion": "6", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_consectetur" + }, + "test_scope_prefix.Config_ipsum": { + "policy_body": { + "config": { + "policy_hello": "world!", + "policy_updated_from_ver": "1", + "policy_updated_to_ver": "2", + "updated_policy_id": "test_scope_prefix.Config_ipsum" + }, + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_ipsum.2.xml", + "policyVersion": "2", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_ipsum" + }, + "test_scope_prefix.Config_sit": { + "policy_body": { + "config": { + "policy_hello": "world!", + "policy_updated_from_ver": "3", + "policy_updated_to_ver": "4", + "updated_policy_id": "test_scope_prefix.Config_sit" + }, + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_sit.4.xml", + "policyVersion": "4", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_sit" + } + }, + "policy_filter_matches": { + "test_scope_prefix.Config_consectetur": {}, + "test_scope_prefix.Config_ipsum": {}, + "test_scope_prefix.Config_sit": {} + }, + "removed_policies": {} + }, + "method": "put", + "params": { + "cfy_tenant_name": "default_tenant" + }, + "uri": "http://unit-test-deployment_handler:8188000/policy" + }, + "res": "*", + "status_code": 200 + } + ], + "tests.test_policyhandler::WebServerTest::test_zzz_catch_up_on_deploy_handler_changed": [ + { + "request": { + "headers": { + "X-ECOMP-RequestID": "*" + }, + "json": None, + "method": "get", + "params": { + "cfy_tenant_name": "default_tenant" + }, + "uri": "http://unit-test-deployment_handler:8188000/policy" + }, + "res": "*", + "status_code": 200 + }, + { + "request": { + "headers": { + "Accept": "application/json", + "Authorization": "Basic auth", + "ClientAuth": "Basic user", + "Content-Type": "application/json", + "Environment": "TEST", + "X-ECOMP-RequestID": "*" + }, + "json": { + "policyName": "test_scope_prefix.Config_.*" + }, + "method": "post", + "params": None, + "uri": "https://unit-test-pdp-server:8081000/pdp/api/getConfig" + }, + "res": "*", + "status_code": 200 + }, + { + "request": { + "headers": { + "X-ECOMP-RequestID": "*" + }, + "json": { + "catch_up": True, + "latest_policies": { + "test_scope_prefix.Config_Lorem": { + "policy_body": { + "config": { + "policy_hello": "world!", + "policy_updated_from_ver": "0", + "policy_updated_to_ver": "1", + "updated_policy_id": "test_scope_prefix.Config_Lorem" + }, + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_Lorem.1.xml", + "policyVersion": "1", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_Lorem" + }, + "test_scope_prefix.Config_amet": { + "policy_body": { + "config": { + "policy_hello": "world!", + "policy_updated_from_ver": "4", + "policy_updated_to_ver": "5", + "updated_policy_id": "test_scope_prefix.Config_amet" + }, + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_amet.5.xml", + "policyVersion": "5", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_amet" + }, + "test_scope_prefix.Config_ametist": { + "policy_body": { + "config": { + "policy_hello": "world!", + "policy_updated_from_ver": "6", + "policy_updated_to_ver": "7", + "updated_policy_id": "test_scope_prefix.Config_ametist" + }, + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_ametist.7.xml", + "policyVersion": "7", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_ametist" + }, + "test_scope_prefix.Config_consectetur": { + "policy_body": { + "config": { + "policy_hello": "world!", + "policy_updated_from_ver": "5", + "policy_updated_to_ver": "6", + "updated_policy_id": "test_scope_prefix.Config_consectetur" + }, + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_consectetur.6.xml", + "policyVersion": "6", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_consectetur" + }, + "test_scope_prefix.Config_dolor": { + "policy_body": { + "config": { + "policy_hello": "world!", + "policy_updated_from_ver": "2", + "policy_updated_to_ver": "3", + "updated_policy_id": "test_scope_prefix.Config_dolor" + }, + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_dolor.3.xml", + "policyVersion": "3", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_dolor" + }, + "test_scope_prefix.Config_ipsum": { + "policy_body": { + "config": { + "policy_hello": "world!", + "policy_updated_from_ver": "1", + "policy_updated_to_ver": "2", + "updated_policy_id": "test_scope_prefix.Config_ipsum" + }, + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_ipsum.2.xml", + "policyVersion": "2", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_ipsum" + }, + "test_scope_prefix.Config_sit": { + "policy_body": { + "config": { + "policy_hello": "world!", + "policy_updated_from_ver": "3", + "policy_updated_to_ver": "4", + "updated_policy_id": "test_scope_prefix.Config_sit" + }, + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_sit.4.xml", + "policyVersion": "4", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_sit" + } + }, + "policy_filter_matches": { + "test_scope_prefix.Config_Lorem": {}, + "test_scope_prefix.Config_amet": {}, + "test_scope_prefix.Config_ametist": {}, + "test_scope_prefix.Config_consectetur": {}, + "test_scope_prefix.Config_dolor": {}, + "test_scope_prefix.Config_ipsum": {}, + "test_scope_prefix.Config_sit": {} + }, + "removed_policies": {} + }, + "method": "put", + "params": { + "cfy_tenant_name": "default_tenant" + }, + "uri": "http://unit-test-deployment_handler:8188000/policy" + }, + "res": "*", + "status_code": 200 + }, + { + "request": { + "headers": { + "X-ECOMP-RequestID": "*" + }, + "json": None, + "method": "get", + "params": { + "cfy_tenant_name": "default_tenant" + }, + "uri": "http://unit-test-deployment_handler:8188000/policy" + }, + "res": "*", + "status_code": 200 + }, + { + "request": { + "headers": { + "Accept": "application/json", + "Authorization": "Basic auth", + "ClientAuth": "Basic user", + "Content-Type": "application/json", + "Environment": "TEST", + "X-ECOMP-RequestID": "*" + }, + "json": { + "policyName": "test_scope_prefix.Config_ipsum" + }, + "method": "post", + "params": None, + "uri": "https://unit-test-pdp-server:8081000/pdp/api/getConfig" + }, + "res": "*", + "status_code": 200 + }, + { + "request": { + "headers": { + "X-ECOMP-RequestID": "*" + }, + "json": { + "catch_up": False, + "latest_policies": { + "test_scope_prefix.Config_ipsum": { + "policy_body": { + "config": { + "policy_hello": "world!", + "policy_updated_from_ver": "1", + "policy_updated_to_ver": "2", + "updated_policy_id": "test_scope_prefix.Config_ipsum" + }, + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_ipsum.2.xml", + "policyVersion": "2", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_ipsum" + } + }, + "policy_filter_matches": { + "test_scope_prefix.Config_ipsum": {} + }, + "removed_policies": {} + }, + "method": "put", + "params": { + "cfy_tenant_name": "default_tenant" + }, + "uri": "http://unit-test-deployment_handler:8188000/policy" + }, + "res": "*", + "status_code": 200 + }, + { + "request": { + "headers": { + "X-ECOMP-RequestID": "*" + }, + "json": None, + "method": "get", + "params": { + "cfy_tenant_name": "default_tenant" + }, + "uri": "http://unit-test-deployment_handler:8188000/policy" + }, + "res": "*", + "status_code": 200 + }, + { + "request": { + "headers": { + "Accept": "application/json", + "Authorization": "Basic auth", + "ClientAuth": "Basic user", + "Content-Type": "application/json", + "Environment": "TEST", + "X-ECOMP-RequestID": "*" + }, + "json": { + "policyName": "test_scope_prefix.Config_dolor" + }, + "method": "post", + "params": None, + "uri": "https://unit-test-pdp-server:8081000/pdp/api/getConfig" + }, + "res": "*", + "status_code": 200 + }, + { + "request": { + "headers": { + "Accept": "application/json", + "Authorization": "Basic auth", + "ClientAuth": "Basic user", + "Content-Type": "application/json", + "Environment": "TEST", + "X-ECOMP-RequestID": "*" + }, + "json": { + "policyName": "test_scope_prefix.Config_amet" + }, + "method": "post", + "params": None, + "uri": "https://unit-test-pdp-server:8081000/pdp/api/getConfig" + }, + "res": "*", + "status_code": 200 + }, + { + "request": { + "headers": { + "X-ECOMP-RequestID": "*" + }, + "json": { + "catch_up": False, + "latest_policies": { + "test_scope_prefix.Config_amet": { + "policy_body": { + "config": { + "policy_hello": "world!", + "policy_updated_from_ver": "4", + "policy_updated_to_ver": "5", + "updated_policy_id": "test_scope_prefix.Config_amet" + }, + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_amet.5.xml", + "policyVersion": "5", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_amet" + }, + "test_scope_prefix.Config_dolor": { + "policy_body": { + "config": { + "policy_hello": "world!", + "policy_updated_from_ver": "2", + "policy_updated_to_ver": "3", + "updated_policy_id": "test_scope_prefix.Config_dolor" + }, + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_dolor.3.xml", + "policyVersion": "3", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_dolor" + } + }, + "policy_filter_matches": { + "test_scope_prefix.Config_amet": {}, + "test_scope_prefix.Config_dolor": {} + }, + "removed_policies": {} + }, + "method": "put", + "params": { + "cfy_tenant_name": "default_tenant" + }, + "uri": "http://unit-test-deployment_handler:8188000/policy" + }, + "res": "*", + "status_code": 200 + }, + { + "request": { + "headers": { + "X-ECOMP-RequestID": "*" + }, + "json": None, + "method": "get", + "params": { + "cfy_tenant_name": "default_tenant" + }, + "uri": "http://unit-test-deployment_handler:8188000/policy" + }, + "res": "*", + "status_code": 200 + }, + { + "request": { + "headers": { + "Accept": "application/json", + "Authorization": "Basic auth", + "ClientAuth": "Basic user", + "Content-Type": "application/json", + "Environment": "TEST", + "X-ECOMP-RequestID": "*" + }, + "json": { + "policyName": "test_scope_prefix.Config_.*" + }, + "method": "post", + "params": None, + "uri": "https://unit-test-pdp-server:8081000/pdp/api/getConfig" + }, + "res": "*", + "status_code": 200 + }, + { + "request": { + "headers": { + "X-ECOMP-RequestID": "*" + }, + "json": { + "catch_up": True, + "latest_policies": { + "test_scope_prefix.Config_Lorem": { + "policy_body": { + "config": { + "policy_hello": "world!", + "policy_updated_from_ver": "0", + "policy_updated_to_ver": "1", + "updated_policy_id": "test_scope_prefix.Config_Lorem" + }, + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_Lorem.1.xml", + "policyVersion": "1", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_Lorem" + }, + "test_scope_prefix.Config_amet": { + "policy_body": { + "config": { + "policy_hello": "world!", + "policy_updated_from_ver": "4", + "policy_updated_to_ver": "5", + "updated_policy_id": "test_scope_prefix.Config_amet" + }, + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_amet.5.xml", + "policyVersion": "5", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_amet" + }, + "test_scope_prefix.Config_ametist": { + "policy_body": { + "config": { + "policy_hello": "world!", + "policy_updated_from_ver": "6", + "policy_updated_to_ver": "7", + "updated_policy_id": "test_scope_prefix.Config_ametist" + }, + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_ametist.7.xml", + "policyVersion": "7", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_ametist" + }, + "test_scope_prefix.Config_consectetur": { + "policy_body": { + "config": { + "policy_hello": "world!", + "policy_updated_from_ver": "5", + "policy_updated_to_ver": "6", + "updated_policy_id": "test_scope_prefix.Config_consectetur" + }, + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_consectetur.6.xml", + "policyVersion": "6", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_consectetur" + }, + "test_scope_prefix.Config_dolor": { + "policy_body": { + "config": { + "policy_hello": "world!", + "policy_updated_from_ver": "2", + "policy_updated_to_ver": "3", + "updated_policy_id": "test_scope_prefix.Config_dolor" + }, + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_dolor.3.xml", + "policyVersion": "3", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_dolor" + }, + "test_scope_prefix.Config_ipsum": { + "policy_body": { + "config": { + "policy_hello": "world!", + "policy_updated_from_ver": "1", + "policy_updated_to_ver": "2", + "updated_policy_id": "test_scope_prefix.Config_ipsum" + }, + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_ipsum.2.xml", + "policyVersion": "2", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_ipsum" + }, + "test_scope_prefix.Config_sit": { + "policy_body": { + "config": { + "policy_hello": "world!", + "policy_updated_from_ver": "3", + "policy_updated_to_ver": "4", + "updated_policy_id": "test_scope_prefix.Config_sit" + }, + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_sit.4.xml", + "policyVersion": "4", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_sit" + } + }, + "policy_filter_matches": { + "test_scope_prefix.Config_Lorem": {}, + "test_scope_prefix.Config_amet": {}, + "test_scope_prefix.Config_ametist": {}, + "test_scope_prefix.Config_consectetur": {}, + "test_scope_prefix.Config_dolor": {}, + "test_scope_prefix.Config_ipsum": {}, + "test_scope_prefix.Config_sit": {} + }, + "removed_policies": {} + }, + "method": "put", + "params": { + "cfy_tenant_name": "default_tenant" + }, + "uri": "http://unit-test-deployment_handler:8188000/policy" + }, + "res": "*", + "status_code": 200 + } + ], + "tests.test_pz_catch_up::test_catch_up_failed_dh": [ + { + "request": { + "headers": { + "X-ECOMP-RequestID": "*" + }, + "json": None, + "method": "get", + "params": { + "cfy_tenant_name": "default_tenant" + }, + "uri": "http://unit-test-deployment_handler:8188000/policy" + }, + "res": "*", + "status_code": 200 + }, + { + "request": { + "headers": { + "Accept": "application/json", + "Authorization": "Basic auth", + "ClientAuth": "Basic user", + "Content-Type": "application/json", + "Environment": "TEST", + "X-ECOMP-RequestID": "*" + }, + "json": { + "policyName": "test_scope_prefix.Config_.*" + }, + "method": "post", + "params": None, + "uri": "https://unit-test-pdp-server:8081000/pdp/api/getConfig" + }, + "res": "*", + "status_code": 200 + }, + { + "request": { + "headers": { + "X-ECOMP-RequestID": "*" + }, + "json": { + "catch_up": True, + "latest_policies": { + "test_scope_prefix.Config_Lorem": { + "policy_body": { + "config": "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789", + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_Lorem.1.xml", + "policyVersion": "1", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_Lorem" + }, + "test_scope_prefix.Config_amet": { + "policy_body": { + "config": "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789", + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_amet.5.xml", + "policyVersion": "5", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_amet" + }, + "test_scope_prefix.Config_ametist": { + "policy_body": { + "config": "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789", + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_ametist.7.xml", + "policyVersion": "7", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_ametist" + }, + "test_scope_prefix.Config_consectetur": { + "policy_body": { + "config": "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789", + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_consectetur.6.xml", + "policyVersion": "6", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_consectetur" + }, + "test_scope_prefix.Config_dolor": { + "policy_body": { + "config": "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789", + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_dolor.3.xml", + "policyVersion": "3", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_dolor" + }, + "test_scope_prefix.Config_ipsum": { + "policy_body": { + "config": "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789", + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_ipsum.2.xml", + "policyVersion": "2", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_ipsum" + }, + "test_scope_prefix.Config_sit": { + "policy_body": { + "config": "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789", + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_sit.4.xml", + "policyVersion": "4", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_sit" + } + }, + "policy_filter_matches": { + "test_scope_prefix.Config_Lorem": {}, + "test_scope_prefix.Config_amet": {}, + "test_scope_prefix.Config_ametist": {}, + "test_scope_prefix.Config_consectetur": {}, + "test_scope_prefix.Config_dolor": {}, + "test_scope_prefix.Config_ipsum": {}, + "test_scope_prefix.Config_sit": {} + }, + "removed_policies": {} + }, + "method": "put", + "params": { + "cfy_tenant_name": "default_tenant" + }, + "uri": "http://unit-test-deployment_handler:8188000/policy" + }, + "res": "*", + "status_code": 413 + }, + { + "request": { + "headers": { + "X-ECOMP-RequestID": "*" + }, + "json": None, + "method": "get", + "params": { + "cfy_tenant_name": "default_tenant" + }, + "uri": "http://unit-test-deployment_handler:8188000/policy" + }, + "res": "*", + "status_code": 200 + }, + { + "request": { + "headers": { + "Accept": "application/json", + "Authorization": "Basic auth", + "ClientAuth": "Basic user", + "Content-Type": "application/json", + "Environment": "TEST", + "X-ECOMP-RequestID": "*" + }, + "json": { + "policyName": "test_scope_prefix.Config_.*" + }, + "method": "post", + "params": None, + "uri": "https://unit-test-pdp-server:8081000/pdp/api/getConfig" + }, + "res": "*", + "status_code": 200 + }, + { + "request": { + "headers": { + "X-ECOMP-RequestID": "*" + }, + "json": { + "catch_up": True, + "latest_policies": { + "test_scope_prefix.Config_Lorem": { + "policy_body": { + "config": "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789", + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_Lorem.1.xml", + "policyVersion": "1", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_Lorem" + }, + "test_scope_prefix.Config_amet": { + "policy_body": { + "config": "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789", + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_amet.5.xml", + "policyVersion": "5", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_amet" + }, + "test_scope_prefix.Config_ametist": { + "policy_body": { + "config": "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789", + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_ametist.7.xml", + "policyVersion": "7", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_ametist" + }, + "test_scope_prefix.Config_consectetur": { + "policy_body": { + "config": "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789", + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_consectetur.6.xml", + "policyVersion": "6", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_consectetur" + }, + "test_scope_prefix.Config_dolor": { + "policy_body": { + "config": "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789", + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_dolor.3.xml", + "policyVersion": "3", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_dolor" + }, + "test_scope_prefix.Config_ipsum": { + "policy_body": { + "config": "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789", + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_ipsum.2.xml", + "policyVersion": "2", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_ipsum" + }, + "test_scope_prefix.Config_sit": { + "policy_body": { + "config": "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789", + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_sit.4.xml", + "policyVersion": "4", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_sit" + } + }, + "policy_filter_matches": { + "test_scope_prefix.Config_Lorem": {}, + "test_scope_prefix.Config_amet": {}, + "test_scope_prefix.Config_ametist": {}, + "test_scope_prefix.Config_consectetur": {}, + "test_scope_prefix.Config_dolor": {}, + "test_scope_prefix.Config_ipsum": {}, + "test_scope_prefix.Config_sit": {} + }, + "removed_policies": {} + }, + "method": "put", + "params": { + "cfy_tenant_name": "default_tenant" + }, + "uri": "http://unit-test-deployment_handler:8188000/policy" + }, + "res": "*", + "status_code": 413 + }, + { + "request": { + "headers": { + "X-ECOMP-RequestID": "*" + }, + "json": None, + "method": "get", + "params": { + "cfy_tenant_name": "default_tenant" + }, + "uri": "http://unit-test-deployment_handler:8188000/policy" + }, + "res": "*", + "status_code": 200 + }, + { + "request": { + "headers": { + "Accept": "application/json", + "Authorization": "Basic auth", + "ClientAuth": "Basic user", + "Content-Type": "application/json", + "Environment": "TEST", + "X-ECOMP-RequestID": "*" + }, + "json": { + "policyName": "test_scope_prefix.Config_.*" + }, + "method": "post", + "params": None, + "uri": "https://unit-test-pdp-server:8081000/pdp/api/getConfig" + }, + "res": "*", + "status_code": 200 + }, + { + "request": { + "headers": { + "X-ECOMP-RequestID": "*" + }, + "json": { + "catch_up": True, + "latest_policies": { + "test_scope_prefix.Config_Lorem": { + "policy_body": { + "config": "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789", + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_Lorem.1.xml", + "policyVersion": "1", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_Lorem" + }, + "test_scope_prefix.Config_amet": { + "policy_body": { + "config": "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789", + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_amet.5.xml", + "policyVersion": "5", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_amet" + }, + "test_scope_prefix.Config_ametist": { + "policy_body": { + "config": "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789", + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_ametist.7.xml", + "policyVersion": "7", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_ametist" + }, + "test_scope_prefix.Config_consectetur": { + "policy_body": { + "config": "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789", + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_consectetur.6.xml", + "policyVersion": "6", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_consectetur" + }, + "test_scope_prefix.Config_dolor": { + "policy_body": { + "config": "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789", + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_dolor.3.xml", + "policyVersion": "3", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_dolor" + }, + "test_scope_prefix.Config_ipsum": { + "policy_body": { + "config": "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789", + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_ipsum.2.xml", + "policyVersion": "2", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_ipsum" + }, + "test_scope_prefix.Config_sit": { + "policy_body": { + "config": "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789", + "matchingConditions": { + "ConfigName": "alex_config_name", + "ONAPName": "DCAE" + }, + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "policyName": "test_scope_prefix.Config_sit.4.xml", + "policyVersion": "4", + "property": None, + "responseAttributes": {}, + "type": "JSON" + }, + "policy_id": "test_scope_prefix.Config_sit" + } + }, + "policy_filter_matches": { + "test_scope_prefix.Config_Lorem": {}, + "test_scope_prefix.Config_amet": {}, + "test_scope_prefix.Config_ametist": {}, + "test_scope_prefix.Config_consectetur": {}, + "test_scope_prefix.Config_dolor": {}, + "test_scope_prefix.Config_ipsum": {}, + "test_scope_prefix.Config_sit": {} + }, + "removed_policies": {} + }, + "method": "put", + "params": { + "cfy_tenant_name": "default_tenant" + }, + "uri": "http://unit-test-deployment_handler:8188000/policy" + }, + "res": "*", + "status_code": 413 + } + ], + "tests.test_pz_catch_up::test_catch_up_dh_404": [ + { + "request": { + "headers": { + "X-ECOMP-RequestID": "*" + }, + "json": None, + "method": "get", + "params": { + "cfy_tenant_name": "default_tenant" + }, + "uri": "http://unit-test-deployment_handler:8188000/policy" + }, + "res": "*", + "status_code": 200 + }, + { + "request": { + "headers": { + "X-ECOMP-RequestID": "*" + }, + "json": None, + "method": "get", + "params": { + "cfy_tenant_name": "default_tenant" + }, + "uri": "http://unit-test-deployment_handler:8188000/policy" + }, + "res": "*", + "status_code": 200 + }, + { + "request": { + "headers": { + "X-ECOMP-RequestID": "*" + }, + "json": None, + "method": "get", + "params": { + "cfy_tenant_name": "default_tenant" + }, + "uri": "http://unit-test-deployment_handler:8188000/policy" + }, + "res": "*", + "status_code": 200 + } + ], + "tests.test_pz_pdp_boom::WebServerPDPBoomTest::test_web_all_policies_latest": [ + { + "request": { + "headers": { + "X-ECOMP-RequestID": "*" + }, + "json": None, + "method": "get", + "params": { + "cfy_tenant_name": "default_tenant" + }, + "uri": "http://unit-test-deployment_handler:8188000/policy" + }, + "res": "*", + "status_code": 200 + } + ], + "tests.test_pz_pdp_boom::WebServerPDPBoomTest::test_zzz_catch_up_on_deploy_handler_changed": [ + { + "request": { + "headers": { + "X-ECOMP-RequestID": "*" + }, + "json": None, + "method": "get", + "params": { + "cfy_tenant_name": "default_tenant" + }, + "uri": "http://unit-test-deployment_handler:8188000/policy" + }, + "res": "*", + "status_code": 200 + }, + { + "request": { + "headers": { + "X-ECOMP-RequestID": "*" + }, + "json": None, + "method": "get", + "params": { + "cfy_tenant_name": "default_tenant" + }, + "uri": "http://unit-test-deployment_handler:8188000/policy" + }, + "res": "*", + "status_code": 200 + }, + { + "request": { + "headers": { + "X-ECOMP-RequestID": "*" + }, + "json": None, + "method": "get", + "params": { + "cfy_tenant_name": "default_tenant" + }, + "uri": "http://unit-test-deployment_handler:8188000/policy" + }, + "res": "*", + "status_code": 200 + }, + { + "request": { + "headers": { + "X-ECOMP-RequestID": "*" + }, + "json": None, + "method": "get", + "params": { + "cfy_tenant_name": "default_tenant" + }, + "uri": "http://unit-test-deployment_handler:8188000/policy" + }, + "res": "*", + "status_code": 200 + } + ], + "tests.test_pz_pdp_boom::WebServerPDPBoomTest::test_zzz_get_catch_up": [ + { + "request": { + "headers": { + "X-ECOMP-RequestID": "*" + }, + "json": None, + "method": "get", + "params": { + "cfy_tenant_name": "default_tenant" + }, + "uri": "http://unit-test-deployment_handler:8188000/policy" + }, + "res": "*", + "status_code": 200 + }, + { + "request": { + "headers": { + "X-ECOMP-RequestID": "*" + }, + "json": None, + "method": "get", + "params": { + "cfy_tenant_name": "default_tenant" + }, + "uri": "http://unit-test-deployment_handler:8188000/policy" + }, + "res": "*", + "status_code": 200 + } + ], + "tests.test_pz_pdp_boom::WebServerPDPBoomTest::test_zzz_policy_updates_and_catch_ups": [ + { + "request": { + "headers": { + "X-ECOMP-RequestID": "*" + }, + "json": None, + "method": "get", + "params": { + "cfy_tenant_name": "default_tenant" + }, + "uri": "http://unit-test-deployment_handler:8188000/policy" + }, + "res": "*", + "status_code": 200 + }, + { + "request": { + "headers": { + "X-ECOMP-RequestID": "*" + }, + "json": None, + "method": "get", + "params": { + "cfy_tenant_name": "default_tenant" + }, + "uri": "http://unit-test-deployment_handler:8188000/policy" + }, + "res": "*", + "status_code": 200 + } + ], + "tests.test_pz_pdp_boom::WebServerPDPBoomTest::test_zzzzz_shutdown": [ + { + "request": { + "headers": { + "X-ECOMP-RequestID": "*" + }, + "json": None, + "method": "get", + "params": { + "cfy_tenant_name": "default_tenant" + }, + "uri": "http://unit-test-deployment_handler:8188000/policy" + }, + "res": "*", + "status_code": 200 + }, + { + "request": { + "headers": { + "X-ECOMP-RequestID": "*" + }, + "json": None, + "method": "get", + "params": { + "cfy_tenant_name": "default_tenant" + }, + "uri": "http://unit-test-deployment_handler:8188000/policy" + }, + "res": "*", + "status_code": 200 + } + ], + "tests.test_pz_ph_boom::WebServerInternalBoomTest::test_web_all_policies_latest": [ + { + "request": { + "headers": { + "X-ECOMP-RequestID": "*" + }, + "json": None, + "method": "get", + "params": { + "cfy_tenant_name": "default_tenant" + }, + "uri": "http://unit-test-deployment_handler:8188000/policy" + }, + "res": "*", + "status_code": 200 + }, + { + "request": { + "headers": { + "Accept": "application/json", + "Authorization": "Basic auth", + "ClientAuth": "Basic user", + "Content-Type": "application/json", + "Environment": "TEST", + "X-ECOMP-RequestID": "*" + }, + "json": { + "policyName": "test_scope_prefix.Config_.*" + }, + "method": "post", + "params": None, + "uri": "https://unit-test-pdp-server:8081000/pdp/api/getConfig" + }, + "res": "*", + "status_code": 200 + } + ], + "tests.test_pz_ph_boom::WebServerInternalBoomTest::test_web_policies_latest": [ + { + "request": { + "headers": { + "Accept": "application/json", + "Authorization": "Basic auth", + "ClientAuth": "Basic user", + "Content-Type": "application/json", + "Environment": "TEST", + "X-ECOMP-RequestID": "*" + }, + "json": { + "policyName": "test_scope_prefix.Config_amet.*" + }, + "method": "post", + "params": None, + "uri": "https://unit-test-pdp-server:8081000/pdp/api/getConfig" + }, + "res": "*", + "status_code": 200 + } + ], + "tests.test_pz_ph_boom::WebServerInternalBoomTest::test_web_policy_latest": [ + { + "request": { + "headers": { + "Accept": "application/json", + "Authorization": "Basic auth", + "ClientAuth": "Basic user", + "Content-Type": "application/json", + "Environment": "TEST", + "X-ECOMP-RequestID": "*" + }, + "json": { + "policyName": "test_scope_prefix.Config_sit" + }, + "method": "post", + "params": None, + "uri": "https://unit-test-pdp-server:8081000/pdp/api/getConfig" + }, + "res": "*", + "status_code": 200 + } + ], + "tests.test_pz_ph_boom::WebServerInternalBoomTest::test_zzz_catch_up_on_deploy_handler_changed": [ + { + "request": { + "headers": { + "X-ECOMP-RequestID": "*" + }, + "json": None, + "method": "get", + "params": { + "cfy_tenant_name": "default_tenant" + }, + "uri": "http://unit-test-deployment_handler:8188000/policy" + }, + "res": "*", + "status_code": 200 + }, + { + "request": { + "headers": { + "Accept": "application/json", + "Authorization": "Basic auth", + "ClientAuth": "Basic user", + "Content-Type": "application/json", + "Environment": "TEST", + "X-ECOMP-RequestID": "*" + }, + "json": { + "policyName": "test_scope_prefix.Config_.*" + }, + "method": "post", + "params": None, + "uri": "https://unit-test-pdp-server:8081000/pdp/api/getConfig" + }, + "res": "*", + "status_code": 200 + } + ], + "tests.test_pz_ph_boom::WebServerInternalBoomTest::test_zzz_get_catch_up": [ + { + "request": { + "headers": { + "X-ECOMP-RequestID": "*" + }, + "json": None, + "method": "get", + "params": { + "cfy_tenant_name": "default_tenant" + }, + "uri": "http://unit-test-deployment_handler:8188000/policy" + }, + "res": "*", + "status_code": 200 + }, + { + "request": { + "headers": { + "Accept": "application/json", + "Authorization": "Basic auth", + "ClientAuth": "Basic user", + "Content-Type": "application/json", + "Environment": "TEST", + "X-ECOMP-RequestID": "*" + }, + "json": { + "policyName": "test_scope_prefix.Config_.*" + }, + "method": "post", + "params": None, + "uri": "https://unit-test-pdp-server:8081000/pdp/api/getConfig" + }, + "res": "*", + "status_code": 200 + }, + { + "request": { + "headers": { + "X-ECOMP-RequestID": "*" + }, + "json": None, + "method": "get", + "params": { + "cfy_tenant_name": "default_tenant" + }, + "uri": "http://unit-test-deployment_handler:8188000/policy" + }, + "res": "*", + "status_code": 200 + }, + { + "request": { + "headers": { + "Accept": "application/json", + "Authorization": "Basic auth", + "ClientAuth": "Basic user", + "Content-Type": "application/json", + "Environment": "TEST", + "X-ECOMP-RequestID": "*" + }, + "json": { + "policyName": "test_scope_prefix.Config_.*" + }, + "method": "post", + "params": None, + "uri": "https://unit-test-pdp-server:8081000/pdp/api/getConfig" + }, + "res": "*", + "status_code": 200 + } + ], + "tests.test_pz_ph_boom::WebServerInternalBoomTest::test_zzz_policy_updates_and_catch_ups": [ + { + "request": { + "headers": { + "X-ECOMP-RequestID": "*" + }, + "json": None, + "method": "get", + "params": { + "cfy_tenant_name": "default_tenant" + }, + "uri": "http://unit-test-deployment_handler:8188000/policy" + }, + "res": "*", + "status_code": 200 + }, + { + "request": { + "headers": { + "Accept": "application/json", + "Authorization": "Basic auth", + "ClientAuth": "Basic user", + "Content-Type": "application/json", + "Environment": "TEST", + "X-ECOMP-RequestID": "*" + }, + "json": { + "policyName": "test_scope_prefix.Config_.*" + }, + "method": "post", + "params": None, + "uri": "https://unit-test-pdp-server:8081000/pdp/api/getConfig" + }, + "res": "*", + "status_code": 200 + } + ], + "tests.test_pz_ph_boom::WebServerInternalBoomTest::test_zzzzz_shutdown": [ + { + "request": { + "headers": { + "X-ECOMP-RequestID": "*" + }, + "json": None, + "method": "get", + "params": { + "cfy_tenant_name": "default_tenant" + }, + "uri": "http://unit-test-deployment_handler:8188000/policy" + }, + "res": "*", + "status_code": 200 + }, + { + "request": { + "headers": { + "Accept": "application/json", + "Authorization": "Basic auth", + "ClientAuth": "Basic user", + "Content-Type": "application/json", + "Environment": "TEST", + "X-ECOMP-RequestID": "*" + }, + "json": { + "policyName": "test_scope_prefix.Config_.*" + }, + "method": "post", + "params": None, + "uri": "https://unit-test-pdp-server:8081000/pdp/api/getConfig" + }, + "res": "*", + "status_code": 200 + } + ] +} diff --git a/tests/mock_policy_engine.py b/tests/mock_policy_engine.py new file mode 100644 index 0000000..d57d613 --- /dev/null +++ b/tests/mock_policy_engine.py @@ -0,0 +1,131 @@ +# ============LICENSE_START======================================================= +# Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# 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. +# ============LICENSE_END========================================================= +# +# ECOMP is a trademark and service mark of AT&T Intellectual Property. +"""mocking for the policy-engine - shared by many tests""" + +import copy +import json +import re + +from policyhandler.policy_consts import (POLICY_BODY, POLICY_CONFIG, POLICY_ID, + POLICY_NAME, POLICY_VERSION) +from policyhandler.policy_utils import PolicyUtils + +from .mock_settings import Settings + + +class MonkeyPolicyBody(object): + """policy body that policy-engine returns""" + @staticmethod + def create_policy_body(policy_id, policy_version=1): + """returns a fake policy-body""" + prev_ver = str(policy_version - 1) + this_ver = str(policy_version) + config = { + "policy_updated_from_ver": prev_ver, + "policy_updated_to_ver": this_ver, + "policy_hello": "world!", + "updated_policy_id": policy_id + } + return { + "policyConfigMessage": "Config Retrieved! ", + "policyConfigStatus": "CONFIG_RETRIEVED", + "type": "JSON", + POLICY_NAME: "{0}.{1}.xml".format(policy_id, this_ver), + POLICY_VERSION: this_ver, + POLICY_CONFIG: json.dumps(config, sort_keys=True), + "matchingConditions": { + "ONAPName": "DCAE", + "ConfigName": "alex_config_name" + }, + "responseAttributes": {}, + "property": None + } + + +class MockPolicyEngine(object): + """pretend this is the policy-engine""" + scope_prefix = "test_scope_prefix.Config_" + LOREM_IPSUM = """Lorem ipsum dolor sit amet consectetur ametist""".split() + LONG_TEXT = "0123456789" * 100 + _policies = [] + + _inited = False + + @staticmethod + def init(): + """init static vars""" + if MockPolicyEngine._inited: + return + MockPolicyEngine._inited = True + + MockPolicyEngine._policies = [ + MonkeyPolicyBody.create_policy_body( + MockPolicyEngine.scope_prefix + policy_id, policy_index + 1) + for policy_id in MockPolicyEngine.LOREM_IPSUM + for policy_index in range(1 + MockPolicyEngine.LOREM_IPSUM.index(policy_id))] + Settings.logger.info("MockPolicyEngine._policies: %s", + json.dumps(MockPolicyEngine._policies)) + + @staticmethod + def get_config(policy_name): + """find policy the way the policy-engine finds""" + if not policy_name: + return [] + return [copy.deepcopy(policy) + for policy in MockPolicyEngine._policies + if re.match(policy_name, policy[POLICY_NAME])] + + @staticmethod + def get_configs_all(): + """get all policies the way the policy-engine finds""" + policies = [copy.deepcopy(policy) + for policy in MockPolicyEngine._policies] + for policy in policies: + policy["config"] = MockPolicyEngine.LONG_TEXT + return policies + + @staticmethod + def get_policy_id(policy_index): + """get the policy_id by index""" + return (MockPolicyEngine.scope_prefix + + MockPolicyEngine.LOREM_IPSUM[ + policy_index % len(MockPolicyEngine.LOREM_IPSUM)]) + + @staticmethod + def gen_policy_latest(policy_index, version_offset=0): + """generate the policy response by policy_index = version - 1""" + policy_id = MockPolicyEngine.get_policy_id(policy_index) + policy = { + POLICY_ID: policy_id, + POLICY_BODY: MonkeyPolicyBody.create_policy_body( + policy_id, policy_index + 1 - version_offset) + } + return policy_id, PolicyUtils.parse_policy_config(policy) + + @staticmethod + def gen_all_policies_latest(version_offset=0): + """generate all latest policies""" + return dict(MockPolicyEngine.gen_policy_latest(policy_index, version_offset=version_offset) + for policy_index in range(len(MockPolicyEngine.LOREM_IPSUM))) + + @staticmethod + def gen_policies_latest(match_to_policy_name): + """generate all latest policies""" + return dict((k, v) + for k, v in MockPolicyEngine.gen_all_policies_latest().items() + if re.match(match_to_policy_name, k)) diff --git a/tests/mock_settings.py b/tests/mock_settings.py index 7e05ecf..80a003e 100644 --- a/tests/mock_settings.py +++ b/tests/mock_settings.py @@ -31,31 +31,6 @@ from policyhandler.discovery import DiscoveryClient from policyhandler.onap.audit import Audit -class MonkeyHttpResponse(object): - """Monkey http reposne""" - def __init__(self, headers): - self.headers = headers or {} - - -class MonkeyedResponse(object): - """Monkey response""" - def __init__(self, full_path, res_json, json_body=None, headers=None): - self.full_path = full_path - self.req_json = json_body or {} - self.status_code = 200 - self.request = MonkeyHttpResponse(headers) - self.res = res_json - self.text = json.dumps(self.res) - - def json(self): - """returns json of response""" - return self.res - - def raise_for_status(self): - """ignoring""" - pass - - def _fix_discover_config(func): """the decorator""" if not func: @@ -83,20 +58,21 @@ class Settings(object): """init all locals""" _loaded = False logger = None - RUN_TS = datetime.utcnow().isoformat()[:-3] + 'Z' mock_config = None deploy_handler_instance_uuid = str(uuid.uuid4()) @staticmethod - @_fix_discover_config def init(): """init configs""" if Settings._loaded: + Settings.logger.info("testing policy_handler with config: %s", Config.discovered_config) return Settings._loaded = True Config.init_config() + Config.consul_url = "http://unit-test-consul:850000" + with open("tests/mock_config.json", 'r') as config_json: Settings.mock_config = json.load(config_json) @@ -107,7 +83,16 @@ class Settings(object): print("print is expected to be in the log") Settings.logger.info("========== run_policy_handler ==========") Audit.init(Config.system_name, Config.LOGGER_CONFIG_FILE_PATH) - audit = Audit(req_message="start testing policy handler") + Settings.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) + + audit = Audit(req_message="rediscover_config") Config.discover(audit) diff --git a/tests/mock_tracker.py b/tests/mock_tracker.py new file mode 100644 index 0000000..4e69afd --- /dev/null +++ b/tests/mock_tracker.py @@ -0,0 +1,138 @@ +# ============LICENSE_START======================================================= +# Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# 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. +# ============LICENSE_END========================================================= +# +# ECOMP is a trademark and service mark of AT&T Intellectual Property. +"""record all the messages going outside policy-handler during testing""" + +import copy +import json + +from policyhandler.onap.audit import REQUEST_X_ECOMP_REQUESTID +from policyhandler.policy_utils import Utils + +from .mock_expected import HISTORY_EXPECTED +from .mock_settings import Settings + +RESPONSE = "res" + +class _MockHttpRequestInResponse(object): + """Mock http request in reponse object""" + def __init__(self, method, uri, **kwargs): + self.method = method + self.uri = uri + self.params = copy.deepcopy(kwargs.get("params")) + self.req_json = copy.deepcopy(kwargs.get("json")) + self.headers = copy.deepcopy(kwargs.get("headers")) + + def to_json(self): + """create json of the request""" + return { + "method": self.method, + "uri": self.uri, + "params": self.params, + "json": self.req_json, + "headers": self.headers + } + + +class MockHttpResponse(object): + """Mock http response based on request""" + def __init__(self, method, uri, res_json, **kwargs): + """create response based on request""" + self.request = _MockHttpRequestInResponse(method, uri, **kwargs) + + self.status_code = kwargs.get("status_code", 200) + self.res = copy.deepcopy(res_json) + self.text = json.dumps(self.res) + + self._track() + + def json(self): + """returns json of response""" + return self.res + + def raise_for_status(self): + """ignoring""" + pass + + def to_json(self): + """create json of the message""" + return { + "request": self.request.to_json(), + "status_code": self.status_code, + RESPONSE: self.res + } + + def _track(self): + """append the message to tracker's history""" + Tracker.track(self.to_json()) + + def __str__(self): + """stringify for logging""" + return json.dumps(self.to_json(), sort_keys=True) + + +class Tracker(object): + """record all the messages going outside policy-handler during testing""" + test_name = None + messages = [] + + @staticmethod + def reset(test_name): + """remove all the messages from history""" + Tracker.test_name = test_name + Tracker.messages.clear() + + @staticmethod + def track(message): + """append the tracked message to the history""" + message = copy.deepcopy(message) + Tracker.messages.append(message) + if Settings.logger: + Settings.logger.info("tracked_message: %s", json.dumps(message, sort_keys=True)) + + @staticmethod + def to_string(): + """stringify message history for logging""" + return json.dumps(Tracker.messages, sort_keys=True) + + @staticmethod + def _hide_volatiles(obj): + """hides the volatile field values""" + if not isinstance(obj, dict): + return obj + + for key, value in obj.items(): + if key in [REQUEST_X_ECOMP_REQUESTID, RESPONSE]: + obj[key] = "*" + elif isinstance(value, dict): + obj[key] = Tracker._hide_volatiles(value) + + return obj + + @staticmethod + def validate(): + """validate that the message history is as expected""" + Settings.logger.info("Tracker.validate(%s)", Tracker.test_name) + messages = [Tracker._hide_volatiles(copy.deepcopy(message)) + for message in Tracker.messages] + expected = HISTORY_EXPECTED.get(Tracker.test_name, []) + + Settings.logger.info("messages: %s", json.dumps(messages, sort_keys=True)) + Settings.logger.info("expected: %s", json.dumps(expected, sort_keys=True)) + assert Utils.are_the_same(messages, expected) + + Settings.logger.info("history valid for Tracker.validate(%s)", Tracker.test_name) diff --git a/tests/mock_websocket.py b/tests/mock_websocket.py new file mode 100644 index 0000000..ac64ed8 --- /dev/null +++ b/tests/mock_websocket.py @@ -0,0 +1,89 @@ +# ============LICENSE_START======================================================= +# Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# 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. +# ============LICENSE_END========================================================= +# +# ECOMP is a trademark and service mark of AT&T Intellectual Property. +"""mocking for the websocket - for testing of policy-engine""" + +import json +import time + +from policyhandler.policy_consts import POLICY_NAME +from policyhandler.policy_receiver import (LOADED_POLICIES, POLICY_VER, + REMOVED_POLICIES) + +from .mock_policy_engine import MockPolicyEngine +from .mock_settings import Settings + + +class MockWebSocket(object): + """Mock websocket""" + on_message = None + + @staticmethod + def send_notification(updated_indexes): + """fake notification through the web-socket""" + if not MockWebSocket.on_message: + return + message = { + LOADED_POLICIES: [ + {POLICY_NAME: "{0}.{1}.xml".format( + MockPolicyEngine.get_policy_id(policy_index), policy_index + 1), + POLICY_VER: str(policy_index + 1)} + for policy_index in updated_indexes or [] + ], + REMOVED_POLICIES : [] + } + message = json.dumps(message) + Settings.logger.info("send_notification: %s", message) + MockWebSocket.on_message(None, message) + + @staticmethod + def enableTrace(yes_no): + """ignore""" + pass + + class MockSocket(object): + """Mock websocket""" + def __init__(self): + self.connected = True + + class WebSocketApp(object): + """Mocked WebSocketApp""" + def __init__(self, web_socket_url, + on_open=None, on_message=None, on_close=None, on_error=None, on_pong=None): + self.web_socket_url = web_socket_url + self.on_open = on_open + self.on_message = MockWebSocket.on_message = on_message + self.on_close = on_close + self.on_error = on_error + self.on_pong = on_pong + self.sock = MockWebSocket.MockSocket() + Settings.logger.info("MockWebSocket for: %s", self.web_socket_url) + + def run_forever(self, sslopt=None): + """forever in the loop""" + Settings.logger.info("MockWebSocket run_forever with sslopt=%s...", + json.dumps(sslopt)) + counter = 0 + while self.sock.connected: + counter += 1 + Settings.logger.info("MockWebSocket sleep %s...", counter) + time.sleep(5) + Settings.logger.info("MockWebSocket exit %s", counter) + + def close(self): + """close socket""" + self.sock.connected = False diff --git a/tests/test_policy_rest.py b/tests/test_policy_rest.py new file mode 100644 index 0000000..ac2529a --- /dev/null +++ b/tests/test_policy_rest.py @@ -0,0 +1,47 @@ +# ============LICENSE_START======================================================= +# Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# 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. +# ============LICENSE_END========================================================= +# +# ECOMP is a trademark and service mark of AT&T Intellectual Property. +"""test policy_rest methods directly""" + +import json + +import pytest + +from policyhandler.onap.audit import Audit +from policyhandler.policy_rest import PolicyRest +from policyhandler.policy_utils import Utils + +from .mock_policy_engine import MockPolicyEngine +from .mock_settings import Settings +from .mock_tracker import Tracker + + +@pytest.mark.usefixtures("fix_pdp_post") +def test_get_policy_latest(): + """test /policy_latest/<policy-id>""" + policy_id, expected_policy = MockPolicyEngine.gen_policy_latest(3) + + audit = Audit(job_name="test_get_policy_latest", + req_message="get /policy_latest/{}".format(policy_id or "")) + policy_latest = PolicyRest.get_latest_policy((audit, policy_id, None, None)) or {} + audit.audit_done(result=json.dumps(policy_latest)) + + Settings.logger.info("expected_policy: %s", json.dumps(expected_policy)) + Settings.logger.info("policy_latest: %s", json.dumps(policy_latest)) + assert Utils.are_the_same(policy_latest, expected_policy) + + Tracker.validate() diff --git a/tests/test_policyhandler.py b/tests/test_policyhandler.py index c501c12..4743a6e 100644 --- a/tests/test_policyhandler.py +++ b/tests/test_policyhandler.py @@ -18,418 +18,24 @@ """test of the package for policy-handler of DCAE-Controller""" -import base64 -import copy import json -import re import time import uuid +import pytest import cherrypy from cherrypy.test.helper import CPWebCase -import pytest - -from policyhandler.config import Config -from policyhandler.deploy_handler import DeployHandler -from policyhandler.discovery import DiscoveryClient -from policyhandler.onap.audit import (REQUEST_X_ECOMP_REQUESTID, Audit, - AuditHttpCode) -from policyhandler.policy_consts import (LATEST_POLICIES, POLICY_BODY, - POLICY_CONFIG, POLICY_ID, POLICY_NAME, - POLICY_VERSION, POLICY_VERSIONS) -from policyhandler.policy_receiver import (LOADED_POLICIES, POLICY_VER, - REMOVED_POLICIES, PolicyReceiver) -from policyhandler.policy_rest import PolicyRest -from policyhandler.policy_utils import PolicyUtils, Utils +from policyhandler.onap.audit import REQUEST_X_ECOMP_REQUESTID, Audit +from policyhandler.policy_consts import LATEST_POLICIES, POLICY_NAME +from policyhandler.policy_receiver import PolicyReceiver +from policyhandler.policy_utils import Utils from policyhandler.web_server import _PolicyWeb -from .mock_settings import MonkeyedResponse, Settings - -Settings.init() - -class MonkeyPolicyBody(object): - """policy body that policy-engine returns""" - @staticmethod - def create_policy_body(policy_id, policy_version=1): - """returns a fake policy-body""" - prev_ver = str(policy_version - 1) - this_ver = str(policy_version) - config = { - "policy_updated_from_ver": prev_ver, - "policy_updated_to_ver": this_ver, - "policy_hello": "world!", - "policy_updated_ts": Settings.RUN_TS, - "updated_policy_id": policy_id - } - return { - "policyConfigMessage": "Config Retrieved! ", - "policyConfigStatus": "CONFIG_RETRIEVED", - "type": "JSON", - POLICY_NAME: "{0}.{1}.xml".format(policy_id, this_ver), - POLICY_VERSION: this_ver, - POLICY_CONFIG: json.dumps(config), - "matchingConditions": { - "ONAPName": "DCAE", - "ConfigName": "alex_config_name" - }, - "responseAttributes": {}, - "property": None - } - - -class MockPolicyEngine(object): - """pretend this is the policy-engine""" - scope_prefix = "test_scope_prefix.Config_" - LOREM_IPSUM = """Lorem ipsum dolor sit amet consectetur ametist""".split() - LONG_TEXT = "0123456789" * 100 - _policies = [] - - @staticmethod - def init(): - """init static vars""" - MockPolicyEngine._policies = [ - MonkeyPolicyBody.create_policy_body( - MockPolicyEngine.scope_prefix + policy_id, policy_index + 1) - for policy_id in MockPolicyEngine.LOREM_IPSUM - for policy_index in range(1 + MockPolicyEngine.LOREM_IPSUM.index(policy_id))] - Settings.logger.info("MockPolicyEngine._policies: %s", - json.dumps(MockPolicyEngine._policies)) - - @staticmethod - def get_config(policy_name): - """find policy the way the policy-engine finds""" - if not policy_name: - return [] - return [copy.deepcopy(policy) - for policy in MockPolicyEngine._policies - if re.match(policy_name, policy[POLICY_NAME])] - - @staticmethod - def get_configs_all(): - """get all policies the way the policy-engine finds""" - policies = [copy.deepcopy(policy) - for policy in MockPolicyEngine._policies] - for policy in policies: - policy["config"] = MockPolicyEngine.LONG_TEXT - return policies - - @staticmethod - def get_policy_id(policy_index): - """get the policy_id by index""" - return (MockPolicyEngine.scope_prefix - + MockPolicyEngine.LOREM_IPSUM[ - policy_index % len(MockPolicyEngine.LOREM_IPSUM)]) - - @staticmethod - def gen_policy_latest(policy_index, version_offset=0): - """generate the policy response by policy_index = version - 1""" - policy_id = MockPolicyEngine.get_policy_id(policy_index) - policy = { - POLICY_ID: policy_id, - POLICY_BODY: MonkeyPolicyBody.create_policy_body( - policy_id, policy_index + 1 - version_offset) - } - return policy_id, PolicyUtils.parse_policy_config(policy) - - @staticmethod - def gen_all_policies_latest(version_offset=0): - """generate all latest policies""" - return dict(MockPolicyEngine.gen_policy_latest(policy_index, version_offset=version_offset) - for policy_index in range(len(MockPolicyEngine.LOREM_IPSUM))) - - @staticmethod - def gen_policies_latest(match_to_policy_name): - """generate all latest policies""" - return dict((k, v) - for k, v in MockPolicyEngine.gen_all_policies_latest().items() - if re.match(match_to_policy_name, k)) - -MockPolicyEngine.init() - - -class MockDeploymentHandler(object): - """pretend this is the deployment-handler""" - - @staticmethod - def default_response(): - """generate the deployed policies message""" - return {"server_instance_uuid": Settings.deploy_handler_instance_uuid} - - @staticmethod - def get_deployed_policies(): - """generate the deployed policies message""" - response = MockDeploymentHandler.default_response() - policies = dict( - (policy_id, { - POLICY_ID: policy_id, - POLICY_VERSIONS: {policy.get(POLICY_BODY, {}).get(POLICY_VERSION, "999"): True}, - "pending_update": False}) - for policy_id, policy in (MockPolicyEngine.gen_all_policies_latest(version_offset=1) - .items())) - response["policies"] = policies - - return response - - -@pytest.fixture() -def fix_pdp_post(monkeypatch): - """monkeyed request /getConfig to PDP""" - def monkeyed_policy_rest_post(full_path, json=None, headers=None, **custom_kwargs): - """monkeypatch for the POST to policy-engine""" - res_json = MockPolicyEngine.get_config(json.get(POLICY_NAME)) - return MonkeyedResponse(full_path, res_json, json, headers) - - Settings.logger.info("setup fix_pdp_post") - PolicyRest._lazy_init() - monkeypatch.setattr('policyhandler.policy_rest.PolicyRest._requests_session.post', - monkeyed_policy_rest_post) - yield fix_pdp_post # provide the fixture value - Settings.logger.info("teardown fix_pdp_post") - - -@pytest.fixture() -def fix_pdp_post_big(monkeypatch): - """monkeyed request /getConfig to PDP""" - def monkeyed_policy_rest_post(full_path, json=None, headers=None, **custom_kwargs): - """monkeypatch for the POST to policy-engine""" - res_json = MockPolicyEngine.get_configs_all() - return MonkeyedResponse(full_path, res_json, json, headers) - - Settings.logger.info("setup fix_pdp_post_big") - PolicyRest._lazy_init() - monkeypatch.setattr('policyhandler.policy_rest.PolicyRest._requests_session.post', - monkeyed_policy_rest_post) - yield fix_pdp_post_big # provide the fixture value - Settings.logger.info("teardown fix_pdp_post_big") - - -class MockException(Exception): - """mock exception""" - pass - - -@pytest.fixture() -def fix_pdp_post_boom(monkeypatch): - """monkeyed request /getConfig to PDP - exception""" - def monkeyed_policy_rest_post_boom(full_path, json=None, headers=None, **custom_kwargs): - """monkeypatch for the POST to policy-engine""" - raise MockException("fix_pdp_post_boom") - - Settings.logger.info("setup fix_pdp_post_boom") - PolicyRest._lazy_init() - monkeypatch.setattr('policyhandler.policy_rest.PolicyRest._requests_session.post', - monkeyed_policy_rest_post_boom) - yield fix_pdp_post_boom - Settings.logger.info("teardown fix_pdp_post_boom") - -@staticmethod -def monkeyed_boom(*args, **kwargs): - """monkeypatch for the select_latest_policies""" - raise MockException("monkeyed_boom") - -@pytest.fixture() -def fix_select_latest_policies_boom(monkeypatch): - """monkeyed exception""" - - Settings.logger.info("setup fix_select_latest_policies_boom") - monkeypatch.setattr('policyhandler.policy_utils.PolicyUtils.select_latest_policies', - monkeyed_boom) - monkeypatch.setattr('policyhandler.policy_utils.PolicyUtils.select_latest_policy', - monkeyed_boom) - monkeypatch.setattr('policyhandler.policy_utils.PolicyUtils.extract_policy_id', - monkeyed_boom) - - yield fix_select_latest_policies_boom - Settings.logger.info("teardown fix_select_latest_policies_boom") - -@pytest.fixture() -def fix_discovery(monkeypatch): - """monkeyed discovery request.get""" - def monkeyed_discovery(full_path): - """monkeypatch for get from consul""" - res_json = {} - if full_path == DiscoveryClient.CONSUL_SERVICE_MASK.format( - Config.discovered_config.get_by_key(Config.DEPLOY_HANDLER)): - res_json = [{ - "ServiceAddress": "1.1.1.1", - "ServicePort": "123" - }] - elif full_path == DiscoveryClient.CONSUL_KV_MASK.format(Config.system_name): - res_json = [{"Value": base64.b64encode( - json.dumps(Settings.mock_config).encode()).decode("utf-8")}] - return MonkeyedResponse(full_path, res_json) - - Settings.logger.info("setup fix_discovery") - monkeypatch.setattr('policyhandler.discovery.requests.get', monkeyed_discovery) - yield fix_discovery # provide the fixture value - Settings.logger.info("teardown fix_discovery") - -@pytest.fixture() -def fix_deploy_handler(monkeypatch): - """monkeyed requests to deployment-handler""" - def monkeyed_deploy_handler_put(full_path, json=None, headers=None, - params=None, **custom_kwargs): - """monkeypatch for policy-update request.put to deploy_handler""" - return MonkeyedResponse(full_path, MockDeploymentHandler.default_response(), - json, headers) - - def monkeyed_deploy_handler_get(full_path, headers=None, params=None, **custom_kwargs): - """monkeypatch policy-update request.get to deploy_handler""" - return MonkeyedResponse(full_path, MockDeploymentHandler.get_deployed_policies(), - None, headers) - - Settings.logger.info("setup fix_deploy_handler") - audit = Audit(req_message="fix_deploy_handler") - DeployHandler._lazy_init(audit) - - monkeypatch.setattr('policyhandler.deploy_handler.DeployHandler._requests_session.put', - monkeyed_deploy_handler_put) - monkeypatch.setattr('policyhandler.deploy_handler.DeployHandler._requests_session.get', - monkeyed_deploy_handler_get) - - yield fix_deploy_handler # provide the fixture value - audit.audit_done("teardown") - Settings.logger.info("teardown fix_deploy_handler") - - -@pytest.fixture() -def fix_deploy_handler_fail(monkeypatch): - """monkeyed failed discovery request.get""" - def monkeyed_deploy_handler_put(full_path, json=None, headers=None, - params=None, **custom_kwargs): - """monkeypatch for deploy_handler""" - res = MonkeyedResponse( - full_path, - {"server_instance_uuid": Settings.deploy_handler_instance_uuid}, - json, headers - ) - res.status_code = 413 - return res - - def monkeyed_deploy_handler_get(full_path, headers=None, params=None, **custom_kwargs): - """monkeypatch policy-update request.get to deploy_handler""" - return MonkeyedResponse(full_path, MockDeploymentHandler.default_response(), - None, headers) - - @staticmethod - def monkeyed_deploy_handler_init(audit_ignore): - """monkeypatch for deploy_handler init""" - DeployHandler._url = None - - Settings.logger.info("setup fix_deploy_handler_fail") - config_catch_up = Config.discovered_config.get_by_key("catch_up") - Config.discovered_config.update("catch_up", {"interval": 1}) - - audit = Audit(req_message="fix_deploy_handler_fail") - DeployHandler._lazy_init(audit) - - monkeypatch.setattr('policyhandler.deploy_handler.DeployHandler._lazy_init', - monkeyed_deploy_handler_init) - monkeypatch.setattr('policyhandler.deploy_handler.DeployHandler._requests_session.put', - monkeyed_deploy_handler_put) - monkeypatch.setattr('policyhandler.deploy_handler.DeployHandler._requests_session.get', - monkeyed_deploy_handler_get) - - yield fix_deploy_handler_fail - audit.audit_done("teardown") - Settings.logger.info("teardown fix_deploy_handler_fail") - Config.discovered_config.update("catch_up", config_catch_up) - - -@pytest.fixture() -def fix_cherrypy_engine_exit(monkeypatch): - """monkeyed cherrypy.engine.exit()""" - Settings.logger.info("setup fix_cherrypy_engine_exit") - - def monkeyed_cherrypy_engine_exit(): - """monkeypatch for deploy_handler""" - Settings.logger.info("cherrypy_engine_exit()") - - monkeypatch.setattr('policyhandler.web_server.cherrypy.engine.exit', - monkeyed_cherrypy_engine_exit) - yield fix_cherrypy_engine_exit # provide the fixture value - Settings.logger.info("teardown fix_cherrypy_engine_exit") - - -class MonkeyedWebSocket(object): - """Monkey websocket""" - on_message = None - - @staticmethod - def send_notification(updated_indexes): - """fake notification through the web-socket""" - if not MonkeyedWebSocket.on_message: - return - message = { - LOADED_POLICIES: [ - {POLICY_NAME: "{0}.{1}.xml".format( - MockPolicyEngine.get_policy_id(policy_index), policy_index + 1), - POLICY_VER: str(policy_index + 1)} - for policy_index in updated_indexes or [] - ], - REMOVED_POLICIES : [] - } - message = json.dumps(message) - Settings.logger.info("send_notification: %s", message) - MonkeyedWebSocket.on_message(None, message) - - @staticmethod - def enableTrace(yes_no): - """ignore""" - pass - - class MonkeyedSocket(object): - """Monkey websocket""" - def __init__(self): - self.connected = True - - class WebSocketApp(object): - """Monkeyed WebSocketApp""" - def __init__(self, web_socket_url, on_message=None, on_close=None, on_error=None): - self.web_socket_url = web_socket_url - self.on_message = MonkeyedWebSocket.on_message = on_message - self.on_close = on_close - self.on_error = on_error - self.sock = MonkeyedWebSocket.MonkeyedSocket() - Settings.logger.info("MonkeyedWebSocket for: %s", self.web_socket_url) - - def run_forever(self): - """forever in the loop""" - counter = 0 - while self.sock.connected: - counter += 1 - Settings.logger.info("MonkeyedWebSocket sleep %s...", counter) - time.sleep(5) - Settings.logger.info("MonkeyedWebSocket exit %s", counter) - - def close(self): - """close socket""" - self.sock.connected = False - - -@pytest.fixture() -def fix_policy_receiver_websocket(monkeypatch): - """monkeyed websocket for policy_receiver""" - Settings.logger.info("setup fix_policy_receiver_websocket") - monkeypatch.setattr('policyhandler.policy_receiver.websocket', MonkeyedWebSocket) - yield fix_policy_receiver_websocket # provide the fixture value - Settings.logger.info("teardown fix_policy_receiver_websocket") - - -def test_get_policy_latest(fix_pdp_post, fix_discovery): - """test /policy_latest/<policy-id>""" - policy_id, expected_policy = MockPolicyEngine.gen_policy_latest(3) - - audit = Audit(job_name="test_get_policy_latest", - req_message="get /policy_latest/{0}".format(policy_id or "")) - policy_latest = PolicyRest.get_latest_policy((audit, policy_id, None, None)) or {} - audit.audit_done(result=json.dumps(policy_latest)) - - Settings.logger.info("expected_policy: %s", json.dumps(expected_policy)) - Settings.logger.info("policy_latest: %s", json.dumps(policy_latest)) - assert Utils.are_the_same(policy_latest, expected_policy) - +from .mock_policy_engine import MockPolicyEngine +from .mock_settings import Settings +from .mock_tracker import Tracker +from .mock_websocket import MockWebSocket @pytest.mark.usefixtures("fix_pdp_post", "fix_discovery") @@ -448,6 +54,8 @@ class WebServerTest(CPWebCase): Settings.logger.info("got healthcheck: %s", self.body) self.assertStatus('200 OK') + Tracker.validate() + def test_web_policy_latest(self): """test /policy_latest/<policy-id>""" policy_id, expected_policy = MockPolicyEngine.gen_policy_latest(3) @@ -464,6 +72,8 @@ class WebServerTest(CPWebCase): result = self.getPage("/healthcheck") Settings.logger.info("healthcheck result: %s", result) + Tracker.validate() + @pytest.mark.usefixtures("fix_deploy_handler") def test_web_all_policies_latest(self): """test GET /policies_latest""" @@ -485,6 +95,8 @@ class WebServerTest(CPWebCase): result = self.getPage("/healthcheck") Settings.logger.info("healthcheck result: %s", result) + Tracker.validate() + def test_web_policies_latest(self): """test POST /policies_latest with policyName""" match_to_policy_name = MockPolicyEngine.scope_prefix + "amet.*" @@ -511,334 +123,14 @@ class WebServerTest(CPWebCase): result = self.getPage("/healthcheck") Settings.logger.info("healthcheck result: %s", result) - @pytest.mark.usefixtures("fix_deploy_handler", "fix_policy_receiver_websocket") - def test_zzz_policy_updates_and_catch_ups(self): - """test run policy handler with policy updates and catchups""" - Settings.logger.info("start policy_updates_and_catch_ups") - audit = Audit(job_name="test_zzz_policy_updates_and_catch_ups", - req_message="start policy_updates_and_catch_ups") - PolicyReceiver.run(audit) - - Settings.logger.info("sleep before send_notification...") - time.sleep(2) - - MonkeyedWebSocket.send_notification([1, 3, 5]) - Settings.logger.info("sleep after send_notification...") - time.sleep(3) - - Settings.logger.info("sleep 30 before shutdown...") - time.sleep(30) - - result = self.getPage("/healthcheck") - Settings.logger.info("healthcheck result: %s", result) - - PolicyReceiver.shutdown(audit) - time.sleep(1) - - @pytest.mark.usefixtures("fix_deploy_handler", "fix_policy_receiver_websocket") - def test_zzz_catch_up_on_deploy_handler_changed(self): - """test run policy handler with deployment-handler changed underneath""" - Settings.logger.info("start zzz_catch_up_on_deploy_handler_changed") - audit = Audit(job_name="test_zzz_catch_up_on_deploy_handler_changed", - req_message="start zzz_catch_up_on_deploy_handler_changed") - PolicyReceiver.run(audit) - - Settings.logger.info("sleep before send_notification...") - time.sleep(2) - - MonkeyedWebSocket.send_notification([1]) - Settings.logger.info("sleep after send_notification...") - time.sleep(3) - - Settings.deploy_handler_instance_uuid = str(uuid.uuid4()) - Settings.logger.info("new deploy-handler uuid=%s", Settings.deploy_handler_instance_uuid) - - MonkeyedWebSocket.send_notification([2, 4]) - Settings.logger.info("sleep after send_notification...") - time.sleep(3) - - Settings.logger.info("sleep 5 before shutdown...") - time.sleep(5) - - result = self.getPage("/healthcheck") - Settings.logger.info("healthcheck result: %s", result) - - PolicyReceiver.shutdown(audit) - time.sleep(1) - - @pytest.mark.usefixtures("fix_deploy_handler", "fix_policy_receiver_websocket") - def test_zzz_get_catch_up(self): - """test /catch_up""" - Settings.logger.info("start /catch_up") - audit = Audit(job_name="test_zzz_get_catch_up", req_message="start /catch_up") - PolicyReceiver.run(audit) - time.sleep(5) - result = self.getPage("/catch_up") - Settings.logger.info("catch_up result: %s", result) - self.assertStatus('200 OK') - Settings.logger.info("got catch_up: %s", self.body) - - Settings.logger.info("sleep 5 before shutdown...") - time.sleep(5) - - result = self.getPage("/healthcheck") - Settings.logger.info("healthcheck result: %s", result) - - PolicyReceiver.shutdown(audit) - time.sleep(1) - - @pytest.mark.usefixtures( - "fix_deploy_handler", - "fix_policy_receiver_websocket", - "fix_cherrypy_engine_exit") - def test_zzzzz_shutdown(self): - """test shutdown""" - Settings.logger.info("start shutdown") - audit = Audit(job_name="test_zzzzz_shutdown", req_message="start shutdown") - PolicyReceiver.run(audit) - - Settings.logger.info("sleep before send_notification...") - time.sleep(2) - - MonkeyedWebSocket.send_notification([1, 3, 5]) - Settings.logger.info("sleep after send_notification...") - time.sleep(3) - - result = self.getPage("/healthcheck") - Settings.logger.info("healthcheck result: %s", result) - - WebServerTest.do_gc_test = False - Settings.logger.info("shutdown...") - audit.audit_done("shutdown") - result = self.getPage("/shutdown") - Settings.logger.info("shutdown result: %s", result) - self.assertStatus('200 OK') - Settings.logger.info("got shutdown: %s", self.body) - time.sleep(1) - - -@pytest.mark.usefixtures("fix_pdp_post_boom", "fix_discovery") -class WebServerPDPBoomTest(CPWebCase): - """testing the web-server - runs tests in alphabetical order of method names""" - def setup_server(): - """setup the web-server""" - cherrypy.tree.mount(_PolicyWeb(), '/') - - setup_server = staticmethod(setup_server) - - def test_web_healthcheck(self): - """test /healthcheck""" - result = self.getPage("/healthcheck") - Settings.logger.info("healthcheck result: %s", result) - Settings.logger.info("got healthcheck: %s", self.body) - self.assertStatus('200 OK') - - def test_web_policy_latest(self): - """test /policy_latest/<policy-id>""" - policy_id, _ = MockPolicyEngine.gen_policy_latest(3) - - self.getPage("/policy_latest/{0}".format(policy_id or "")) - self.assertStatus(AuditHttpCode.SERVER_INTERNAL_ERROR.value) - - result = self.getPage("/healthcheck") - Settings.logger.info("healthcheck result: %s", result) - - @pytest.mark.usefixtures("fix_deploy_handler") - def test_web_all_policies_latest(self): - """test GET /policies_latest""" - result = self.getPage("/policies_latest") - Settings.logger.info("result: %s", result) - Settings.logger.info("body: %s", self.body) - self.assertStatus(AuditHttpCode.SERVER_INTERNAL_ERROR.value) - - result = self.getPage("/healthcheck") - Settings.logger.info("healthcheck result: %s", result) - - def test_web_policies_latest(self): - """test POST /policies_latest with policyName""" - match_to_policy_name = MockPolicyEngine.scope_prefix + "amet.*" - - body = json.dumps({POLICY_NAME: match_to_policy_name}) - result = self.getPage("/policies_latest", method='POST', - body=body, - headers=[ - (REQUEST_X_ECOMP_REQUESTID, str(uuid.uuid4())), - ("Content-Type", "application/json"), - ('Content-Length', str(len(body))) - ]) - Settings.logger.info("result: %s", result) - Settings.logger.info("body: %s", self.body) - self.assertStatus(AuditHttpCode.SERVER_INTERNAL_ERROR.value) - - result = self.getPage("/healthcheck") - Settings.logger.info("healthcheck result: %s", result) + Tracker.validate() @pytest.mark.usefixtures("fix_deploy_handler", "fix_policy_receiver_websocket") def test_zzz_policy_updates_and_catch_ups(self): """test run policy handler with policy updates and catchups""" Settings.logger.info("start policy_updates_and_catch_ups") - audit = Audit(job_name="test_zzz_policy_updates_and_catch_ups", - req_message="start policy_updates_and_catch_ups") - PolicyReceiver.run(audit) - - Settings.logger.info("sleep before send_notification...") - time.sleep(2) - - MonkeyedWebSocket.send_notification([1, 3, 5]) - Settings.logger.info("sleep after send_notification...") - time.sleep(3) - - Settings.logger.info("sleep 30 before shutdown...") - time.sleep(30) - - result = self.getPage("/healthcheck") - Settings.logger.info("healthcheck result: %s", result) - - PolicyReceiver.shutdown(audit) - time.sleep(1) - - @pytest.mark.usefixtures("fix_deploy_handler", "fix_policy_receiver_websocket") - def test_zzz_catch_up_on_deploy_handler_changed(self): - """test run policy handler with deployment-handler changed underneath""" - Settings.logger.info("start zzz_catch_up_on_deploy_handler_changed") - audit = Audit(job_name="test_zzz_catch_up_on_deploy_handler_changed", - req_message="start zzz_catch_up_on_deploy_handler_changed") - PolicyReceiver.run(audit) - - Settings.logger.info("sleep before send_notification...") - time.sleep(2) - - MonkeyedWebSocket.send_notification([1]) - Settings.logger.info("sleep after send_notification...") - time.sleep(3) - - Settings.deploy_handler_instance_uuid = str(uuid.uuid4()) - Settings.logger.info("new deploy-handler uuid=%s", Settings.deploy_handler_instance_uuid) - - MonkeyedWebSocket.send_notification([2, 4]) - Settings.logger.info("sleep after send_notification...") - time.sleep(3) + assert not PolicyReceiver.is_running() - Settings.logger.info("sleep 5 before shutdown...") - time.sleep(5) - - result = self.getPage("/healthcheck") - Settings.logger.info("healthcheck result: %s", result) - - PolicyReceiver.shutdown(audit) - time.sleep(1) - - @pytest.mark.usefixtures("fix_deploy_handler", "fix_policy_receiver_websocket") - def test_zzz_get_catch_up(self): - """test /catch_up""" - Settings.logger.info("start /catch_up") - audit = Audit(job_name="test_zzz_get_catch_up", req_message="start /catch_up") - PolicyReceiver.run(audit) - time.sleep(5) - result = self.getPage("/catch_up") - Settings.logger.info("catch_up result: %s", result) - self.assertStatus('200 OK') - Settings.logger.info("got catch_up: %s", self.body) - - Settings.logger.info("sleep 5 before shutdown...") - time.sleep(5) - - result = self.getPage("/healthcheck") - Settings.logger.info("healthcheck result: %s", result) - - PolicyReceiver.shutdown(audit) - time.sleep(1) - - @pytest.mark.usefixtures( - "fix_deploy_handler", - "fix_policy_receiver_websocket", - "fix_cherrypy_engine_exit") - def test_zzzzz_shutdown(self): - """test shutdown""" - Settings.logger.info("start shutdown") - audit = Audit(job_name="test_zzzzz_shutdown", req_message="start shutdown") - PolicyReceiver.run(audit) - - Settings.logger.info("sleep before send_notification...") - time.sleep(2) - - MonkeyedWebSocket.send_notification([1, 3, 5]) - Settings.logger.info("sleep after send_notification...") - time.sleep(3) - - result = self.getPage("/healthcheck") - Settings.logger.info("healthcheck result: %s", result) - - WebServerPDPBoomTest.do_gc_test = False - Settings.logger.info("shutdown...") - audit.audit_done("shutdown") - result = self.getPage("/shutdown") - Settings.logger.info("shutdown result: %s", result) - self.assertStatus('200 OK') - Settings.logger.info("got shutdown: %s", self.body) - time.sleep(1) - - -@pytest.mark.usefixtures("fix_pdp_post", "fix_select_latest_policies_boom", "fix_discovery") -class WebServerInternalBoomTest(CPWebCase): - """testing the web-server - runs tests in alphabetical order of method names""" - def setup_server(): - """setup the web-server""" - cherrypy.tree.mount(_PolicyWeb(), '/') - - setup_server = staticmethod(setup_server) - - def test_web_healthcheck(self): - """test /healthcheck""" - result = self.getPage("/healthcheck") - Settings.logger.info("healthcheck result: %s", result) - Settings.logger.info("got healthcheck: %s", self.body) - self.assertStatus('200 OK') - - def test_web_policy_latest(self): - """test /policy_latest/<policy-id>""" - policy_id, _ = MockPolicyEngine.gen_policy_latest(3) - - self.getPage("/policy_latest/{0}".format(policy_id or "")) - self.assertStatus(AuditHttpCode.SERVER_INTERNAL_ERROR.value) - - result = self.getPage("/healthcheck") - Settings.logger.info("healthcheck result: %s", result) - - @pytest.mark.usefixtures("fix_deploy_handler") - def test_web_all_policies_latest(self): - """test GET /policies_latest""" - result = self.getPage("/policies_latest") - Settings.logger.info("result: %s", result) - Settings.logger.info("body: %s", self.body) - self.assertStatus(AuditHttpCode.SERVER_INTERNAL_ERROR.value) - - result = self.getPage("/healthcheck") - Settings.logger.info("healthcheck result: %s", result) - - def test_web_policies_latest(self): - """test POST /policies_latest with policyName""" - match_to_policy_name = MockPolicyEngine.scope_prefix + "amet.*" - - body = json.dumps({POLICY_NAME: match_to_policy_name}) - result = self.getPage("/policies_latest", method='POST', - body=body, - headers=[ - (REQUEST_X_ECOMP_REQUESTID, str(uuid.uuid4())), - ("Content-Type", "application/json"), - ('Content-Length', str(len(body))) - ]) - Settings.logger.info("result: %s", result) - Settings.logger.info("body: %s", self.body) - self.assertStatus(AuditHttpCode.SERVER_INTERNAL_ERROR.value) - - result = self.getPage("/healthcheck") - Settings.logger.info("healthcheck result: %s", result) - - @pytest.mark.usefixtures("fix_deploy_handler", "fix_policy_receiver_websocket") - def test_zzz_policy_updates_and_catch_ups(self): - """test run policy handler with policy updates and catchups""" - Settings.logger.info("start policy_updates_and_catch_ups") audit = Audit(job_name="test_zzz_policy_updates_and_catch_ups", req_message="start policy_updates_and_catch_ups") PolicyReceiver.run(audit) @@ -846,23 +138,27 @@ class WebServerInternalBoomTest(CPWebCase): Settings.logger.info("sleep before send_notification...") time.sleep(2) - MonkeyedWebSocket.send_notification([1, 3, 5]) + MockWebSocket.send_notification([1, 3, 5]) Settings.logger.info("sleep after send_notification...") time.sleep(3) - Settings.logger.info("sleep 30 before shutdown...") - time.sleep(30) + Settings.logger.info("sleep 10 before shutdown...") + time.sleep(10) result = self.getPage("/healthcheck") Settings.logger.info("healthcheck result: %s", result) PolicyReceiver.shutdown(audit) time.sleep(1) + assert not PolicyReceiver.is_running() + + Tracker.validate() @pytest.mark.usefixtures("fix_deploy_handler", "fix_policy_receiver_websocket") def test_zzz_catch_up_on_deploy_handler_changed(self): """test run policy handler with deployment-handler changed underneath""" Settings.logger.info("start zzz_catch_up_on_deploy_handler_changed") + assert not PolicyReceiver.is_running() audit = Audit(job_name="test_zzz_catch_up_on_deploy_handler_changed", req_message="start zzz_catch_up_on_deploy_handler_changed") PolicyReceiver.run(audit) @@ -870,14 +166,14 @@ class WebServerInternalBoomTest(CPWebCase): Settings.logger.info("sleep before send_notification...") time.sleep(2) - MonkeyedWebSocket.send_notification([1]) + MockWebSocket.send_notification([1]) Settings.logger.info("sleep after send_notification...") time.sleep(3) Settings.deploy_handler_instance_uuid = str(uuid.uuid4()) Settings.logger.info("new deploy-handler uuid=%s", Settings.deploy_handler_instance_uuid) - MonkeyedWebSocket.send_notification([2, 4]) + MockWebSocket.send_notification([2, 4]) Settings.logger.info("sleep after send_notification...") time.sleep(3) @@ -889,11 +185,15 @@ class WebServerInternalBoomTest(CPWebCase): PolicyReceiver.shutdown(audit) time.sleep(1) + assert not PolicyReceiver.is_running() + + Tracker.validate() @pytest.mark.usefixtures("fix_deploy_handler", "fix_policy_receiver_websocket") def test_zzz_get_catch_up(self): """test /catch_up""" Settings.logger.info("start /catch_up") + assert not PolicyReceiver.is_running() audit = Audit(job_name="test_zzz_get_catch_up", req_message="start /catch_up") PolicyReceiver.run(audit) time.sleep(5) @@ -910,6 +210,9 @@ class WebServerInternalBoomTest(CPWebCase): PolicyReceiver.shutdown(audit) time.sleep(1) + assert not PolicyReceiver.is_running() + + Tracker.validate() @pytest.mark.usefixtures( "fix_deploy_handler", @@ -918,20 +221,21 @@ class WebServerInternalBoomTest(CPWebCase): def test_zzzzz_shutdown(self): """test shutdown""" Settings.logger.info("start shutdown") + assert not PolicyReceiver.is_running() audit = Audit(job_name="test_zzzzz_shutdown", req_message="start shutdown") PolicyReceiver.run(audit) Settings.logger.info("sleep before send_notification...") time.sleep(2) - MonkeyedWebSocket.send_notification([1, 3, 5]) + MockWebSocket.send_notification([1, 3, 5]) Settings.logger.info("sleep after send_notification...") time.sleep(3) result = self.getPage("/healthcheck") Settings.logger.info("healthcheck result: %s", result) - WebServerInternalBoomTest.do_gc_test = False + WebServerTest.do_gc_test = False Settings.logger.info("shutdown...") audit.audit_done("shutdown") result = self.getPage("/shutdown") @@ -939,32 +243,6 @@ class WebServerInternalBoomTest(CPWebCase): self.assertStatus('200 OK') Settings.logger.info("got shutdown: %s", self.body) time.sleep(1) + assert not PolicyReceiver.is_running() - -@pytest.mark.usefixtures( - "fix_pdp_post_big", - "fix_deploy_handler_fail", - "fix_policy_receiver_websocket", - "fix_discovery" -) -def test_catch_ups_failed_dh(): - """test run policy handler with catchups and failed deployment-handler""" - Settings.logger.info("start test_catch_ups_failed_dh") - audit = Audit(job_name="test_catch_ups_failed_dh", - req_message="start test_catch_ups_failed_dh") - PolicyReceiver.run(audit) - - Settings.logger.info("sleep 50 before shutdown...") - time.sleep(50) - - health = audit.health(full=True) - audit.audit_done(result=json.dumps(health)) - - Settings.logger.info("healthcheck: %s", json.dumps(health)) - assert bool(health) - - PolicyReceiver.shutdown(audit) - time.sleep(1) - - health = audit.health(full=True) - Settings.logger.info("healthcheck: %s", json.dumps(health)) + Tracker.validate() diff --git a/tests/test_pz_catch_up.py b/tests/test_pz_catch_up.py new file mode 100644 index 0000000..89be9bb --- /dev/null +++ b/tests/test_pz_catch_up.py @@ -0,0 +1,96 @@ +# ============LICENSE_START======================================================= +# Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# 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. +# ============LICENSE_END========================================================= +# +# ECOMP is a trademark and service mark of AT&T Intellectual Property. +"""test policy catch_up methods directly""" + +import json +import time + +import pytest + +from policyhandler.onap.audit import Audit +from policyhandler.policy_receiver import PolicyReceiver + +from .mock_settings import Settings +from .mock_tracker import Tracker + + +@pytest.mark.usefixtures( + "fix_auto_catch_up", + "fix_discovery", + "fix_pdp_post_big", + "fix_deploy_handler_413", + "fix_policy_receiver_websocket" +) +def test_catch_up_failed_dh(): + """test run policy handler with catchups and failed deployment-handler""" + Settings.logger.info("start test_catch_up_failed_dh") + assert not PolicyReceiver.is_running() + audit = Audit(job_name="test_catch_up_failed_dh", + req_message="start test_catch_up_failed_dh") + PolicyReceiver.run(audit) + + Settings.logger.info("sleep 12 before shutdown...") + time.sleep(12) + + health = audit.health(full=True) + audit.audit_done(result=json.dumps(health)) + + Settings.logger.info("healthcheck: %s", json.dumps(health)) + assert bool(health) + + PolicyReceiver.shutdown(audit) + time.sleep(1) + assert not PolicyReceiver.is_running() + + health = audit.health(full=True) + Settings.logger.info("healthcheck: %s", json.dumps(health)) + + Tracker.validate() + +@pytest.mark.usefixtures( + "fix_auto_catch_up", + "fix_discovery", + "fix_pdp_post", + "fix_deploy_handler_404", + "fix_policy_receiver_websocket" +) +def test_catch_up_dh_404(): + """test run policy handler with catchups and failed deployment-handler""" + Settings.logger.info("start test_catch_up_dh_404") + assert not PolicyReceiver.is_running() + audit = Audit(job_name="test_catch_up_dh_404", + req_message="start test_catch_up_dh_404") + PolicyReceiver.run(audit) + + Settings.logger.info("sleep 12 before shutdown...") + time.sleep(12) + + health = audit.health(full=True) + audit.audit_done(result=json.dumps(health)) + + Settings.logger.info("healthcheck: %s", json.dumps(health)) + assert bool(health) + + PolicyReceiver.shutdown(audit) + time.sleep(1) + assert not PolicyReceiver.is_running() + + health = audit.health(full=True) + Settings.logger.info("healthcheck: %s", json.dumps(health)) + + Tracker.validate() diff --git a/tests/test_pz_pdp_boom.py b/tests/test_pz_pdp_boom.py new file mode 100644 index 0000000..1b6f150 --- /dev/null +++ b/tests/test_pz_pdp_boom.py @@ -0,0 +1,226 @@ +# ============LICENSE_START======================================================= +# Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# 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. +# ============LICENSE_END========================================================= +# +# ECOMP is a trademark and service mark of AT&T Intellectual Property. +"""test policyhandler web-server when pdp booms = fails""" + +import json +import time +import uuid + +import pytest +import cherrypy +from cherrypy.test.helper import CPWebCase + +from policyhandler.onap.audit import (REQUEST_X_ECOMP_REQUESTID, Audit, + AuditHttpCode) +from policyhandler.policy_consts import POLICY_NAME +from policyhandler.policy_receiver import PolicyReceiver +from policyhandler.web_server import _PolicyWeb + +from .mock_policy_engine import MockPolicyEngine +from .mock_settings import Settings +from .mock_tracker import Tracker +from .mock_websocket import MockWebSocket + + +@pytest.mark.usefixtures( + "fix_discovery", + "fix_pdp_post_boom" +) +class WebServerPDPBoomTest(CPWebCase): + """testing the web-server - runs tests in alphabetical order of method names""" + def setup_server(): + """setup the web-server""" + cherrypy.tree.mount(_PolicyWeb(), '/') + + setup_server = staticmethod(setup_server) + + def test_web_healthcheck(self): + """test /healthcheck""" + result = self.getPage("/healthcheck") + Settings.logger.info("healthcheck result: %s", result) + Settings.logger.info("got healthcheck: %s", self.body) + self.assertStatus('200 OK') + + Tracker.validate() + + def test_web_policy_latest(self): + """test /policy_latest/<policy-id>""" + policy_id, _ = MockPolicyEngine.gen_policy_latest(3) + + self.getPage("/policy_latest/{0}".format(policy_id or "")) + self.assertStatus(AuditHttpCode.SERVER_INTERNAL_ERROR.value) + + result = self.getPage("/healthcheck") + Settings.logger.info("healthcheck result: %s", result) + + Tracker.validate() + + @pytest.mark.usefixtures("fix_deploy_handler") + def test_web_all_policies_latest(self): + """test GET /policies_latest""" + result = self.getPage("/policies_latest") + Settings.logger.info("result: %s", result) + Settings.logger.info("body: %s", self.body) + self.assertStatus(AuditHttpCode.SERVER_INTERNAL_ERROR.value) + + result = self.getPage("/healthcheck") + Settings.logger.info("healthcheck result: %s", result) + + Tracker.validate() + + def test_web_policies_latest(self): + """test POST /policies_latest with policyName""" + match_to_policy_name = MockPolicyEngine.scope_prefix + "amet.*" + + body = json.dumps({POLICY_NAME: match_to_policy_name}) + result = self.getPage("/policies_latest", method='POST', + body=body, + headers=[ + (REQUEST_X_ECOMP_REQUESTID, str(uuid.uuid4())), + ("Content-Type", "application/json"), + ('Content-Length', str(len(body))) + ]) + Settings.logger.info("result: %s", result) + Settings.logger.info("body: %s", self.body) + self.assertStatus(AuditHttpCode.SERVER_INTERNAL_ERROR.value) + + result = self.getPage("/healthcheck") + Settings.logger.info("healthcheck result: %s", result) + + Tracker.validate() + + @pytest.mark.usefixtures("fix_deploy_handler", "fix_policy_receiver_websocket") + def test_zzz_policy_updates_and_catch_ups(self): + """test run policy handler with policy updates and catchups""" + Settings.logger.info("start policy_updates_and_catch_ups") + assert not PolicyReceiver.is_running() + audit = Audit(job_name="test_zzz_policy_updates_and_catch_ups", + req_message="start policy_updates_and_catch_ups") + PolicyReceiver.run(audit) + + Settings.logger.info("sleep before send_notification...") + time.sleep(2) + + MockWebSocket.send_notification([1, 3, 5]) + Settings.logger.info("sleep after send_notification...") + time.sleep(3) + + Settings.logger.info("sleep 10 before shutdown...") + time.sleep(10) + + result = self.getPage("/healthcheck") + Settings.logger.info("healthcheck result: %s", result) + + PolicyReceiver.shutdown(audit) + time.sleep(1) + assert not PolicyReceiver.is_running() + + Tracker.validate() + + @pytest.mark.usefixtures("fix_deploy_handler", "fix_policy_receiver_websocket") + def test_zzz_catch_up_on_deploy_handler_changed(self): + """test run policy handler with deployment-handler changed underneath""" + Settings.logger.info("start zzz_catch_up_on_deploy_handler_changed") + assert not PolicyReceiver.is_running() + audit = Audit(job_name="test_zzz_catch_up_on_deploy_handler_changed", + req_message="start zzz_catch_up_on_deploy_handler_changed") + PolicyReceiver.run(audit) + + Settings.logger.info("sleep before send_notification...") + time.sleep(2) + + MockWebSocket.send_notification([1]) + Settings.logger.info("sleep after send_notification...") + time.sleep(3) + + Settings.deploy_handler_instance_uuid = str(uuid.uuid4()) + Settings.logger.info("new deploy-handler uuid=%s", Settings.deploy_handler_instance_uuid) + + MockWebSocket.send_notification([2, 4]) + Settings.logger.info("sleep after send_notification...") + time.sleep(3) + + Settings.logger.info("sleep 5 before shutdown...") + time.sleep(5) + + result = self.getPage("/healthcheck") + Settings.logger.info("healthcheck result: %s", result) + + PolicyReceiver.shutdown(audit) + time.sleep(1) + assert not PolicyReceiver.is_running() + + Tracker.validate() + + @pytest.mark.usefixtures("fix_deploy_handler", "fix_policy_receiver_websocket") + def test_zzz_get_catch_up(self): + """test /catch_up""" + Settings.logger.info("start /catch_up") + assert not PolicyReceiver.is_running() + audit = Audit(job_name="test_zzz_get_catch_up", req_message="start /catch_up") + PolicyReceiver.run(audit) + time.sleep(5) + result = self.getPage("/catch_up") + Settings.logger.info("catch_up result: %s", result) + self.assertStatus('200 OK') + Settings.logger.info("got catch_up: %s", self.body) + + Settings.logger.info("sleep 5 before shutdown...") + time.sleep(5) + + result = self.getPage("/healthcheck") + Settings.logger.info("healthcheck result: %s", result) + + PolicyReceiver.shutdown(audit) + time.sleep(1) + assert not PolicyReceiver.is_running() + + Tracker.validate() + + @pytest.mark.usefixtures( + "fix_deploy_handler", + "fix_policy_receiver_websocket", + "fix_cherrypy_engine_exit") + def test_zzzzz_shutdown(self): + """test shutdown""" + Settings.logger.info("start shutdown") + assert not PolicyReceiver.is_running() + audit = Audit(job_name="test_zzzzz_shutdown", req_message="start shutdown") + PolicyReceiver.run(audit) + + Settings.logger.info("sleep before send_notification...") + time.sleep(2) + + MockWebSocket.send_notification([1, 3, 5]) + Settings.logger.info("sleep after send_notification...") + time.sleep(3) + + result = self.getPage("/healthcheck") + Settings.logger.info("healthcheck result: %s", result) + + WebServerPDPBoomTest.do_gc_test = False + Settings.logger.info("shutdown...") + audit.audit_done("shutdown") + result = self.getPage("/shutdown") + Settings.logger.info("shutdown result: %s", result) + self.assertStatus('200 OK') + Settings.logger.info("got shutdown: %s", self.body) + time.sleep(1) + assert not PolicyReceiver.is_running() + + Tracker.validate() diff --git a/tests/test_pz_ph_boom.py b/tests/test_pz_ph_boom.py new file mode 100644 index 0000000..c392b3a --- /dev/null +++ b/tests/test_pz_ph_boom.py @@ -0,0 +1,228 @@ +# ============LICENSE_START======================================================= +# Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# 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. +# ============LICENSE_END========================================================= +# +# ECOMP is a trademark and service mark of AT&T Intellectual Property. +"""test policyhandler web-server when the policy-handler booms = fails""" + +import json +import time +import uuid + + +import pytest +import cherrypy +from cherrypy.test.helper import CPWebCase + +from policyhandler.onap.audit import (REQUEST_X_ECOMP_REQUESTID, Audit, + AuditHttpCode) +from policyhandler.policy_consts import POLICY_NAME +from policyhandler.policy_receiver import PolicyReceiver +from policyhandler.web_server import _PolicyWeb + +from .mock_policy_engine import MockPolicyEngine +from .mock_settings import Settings +from .mock_tracker import Tracker +from .mock_websocket import MockWebSocket + + +@pytest.mark.usefixtures( + "fix_discovery", + "fix_pdp_post", + "fix_select_latest_policies_boom" +) +class WebServerInternalBoomTest(CPWebCase): + """testing the web-server - runs tests in alphabetical order of method names""" + def setup_server(): + """setup the web-server""" + cherrypy.tree.mount(_PolicyWeb(), '/') + + setup_server = staticmethod(setup_server) + + def test_web_healthcheck(self): + """test /healthcheck""" + result = self.getPage("/healthcheck") + Settings.logger.info("healthcheck result: %s", result) + Settings.logger.info("got healthcheck: %s", self.body) + self.assertStatus('200 OK') + + Tracker.validate() + + def test_web_policy_latest(self): + """test /policy_latest/<policy-id>""" + policy_id, _ = MockPolicyEngine.gen_policy_latest(3) + + self.getPage("/policy_latest/{0}".format(policy_id or "")) + self.assertStatus(AuditHttpCode.SERVER_INTERNAL_ERROR.value) + + result = self.getPage("/healthcheck") + Settings.logger.info("healthcheck result: %s", result) + + Tracker.validate() + + @pytest.mark.usefixtures("fix_deploy_handler") + def test_web_all_policies_latest(self): + """test GET /policies_latest""" + result = self.getPage("/policies_latest") + Settings.logger.info("result: %s", result) + Settings.logger.info("body: %s", self.body) + self.assertStatus(AuditHttpCode.SERVER_INTERNAL_ERROR.value) + + result = self.getPage("/healthcheck") + Settings.logger.info("healthcheck result: %s", result) + + Tracker.validate() + + def test_web_policies_latest(self): + """test POST /policies_latest with policyName""" + match_to_policy_name = MockPolicyEngine.scope_prefix + "amet.*" + + body = json.dumps({POLICY_NAME: match_to_policy_name}) + result = self.getPage("/policies_latest", method='POST', + body=body, + headers=[ + (REQUEST_X_ECOMP_REQUESTID, str(uuid.uuid4())), + ("Content-Type", "application/json"), + ('Content-Length', str(len(body))) + ]) + Settings.logger.info("result: %s", result) + Settings.logger.info("body: %s", self.body) + self.assertStatus(AuditHttpCode.SERVER_INTERNAL_ERROR.value) + + result = self.getPage("/healthcheck") + Settings.logger.info("healthcheck result: %s", result) + + Tracker.validate() + + @pytest.mark.usefixtures("fix_deploy_handler", "fix_policy_receiver_websocket") + def test_zzz_policy_updates_and_catch_ups(self): + """test run policy handler with policy updates and catchups""" + Settings.logger.info("start policy_updates_and_catch_ups") + assert not PolicyReceiver.is_running() + audit = Audit(job_name="test_zzz_policy_updates_and_catch_ups", + req_message="start policy_updates_and_catch_ups") + PolicyReceiver.run(audit) + + Settings.logger.info("sleep before send_notification...") + time.sleep(2) + + MockWebSocket.send_notification([1, 3, 5]) + Settings.logger.info("sleep after send_notification...") + time.sleep(3) + + Settings.logger.info("sleep 10 before shutdown...") + time.sleep(10) + + result = self.getPage("/healthcheck") + Settings.logger.info("healthcheck result: %s", result) + + PolicyReceiver.shutdown(audit) + time.sleep(1) + assert not PolicyReceiver.is_running() + + Tracker.validate() + + @pytest.mark.usefixtures("fix_deploy_handler", "fix_policy_receiver_websocket") + def test_zzz_catch_up_on_deploy_handler_changed(self): + """test run policy handler with deployment-handler changed underneath""" + Settings.logger.info("start zzz_catch_up_on_deploy_handler_changed") + assert not PolicyReceiver.is_running() + audit = Audit(job_name="test_zzz_catch_up_on_deploy_handler_changed", + req_message="start zzz_catch_up_on_deploy_handler_changed") + PolicyReceiver.run(audit) + + Settings.logger.info("sleep before send_notification...") + time.sleep(2) + + MockWebSocket.send_notification([1]) + Settings.logger.info("sleep after send_notification...") + time.sleep(3) + + Settings.deploy_handler_instance_uuid = str(uuid.uuid4()) + Settings.logger.info("new deploy-handler uuid=%s", Settings.deploy_handler_instance_uuid) + + MockWebSocket.send_notification([2, 4]) + Settings.logger.info("sleep after send_notification...") + time.sleep(3) + + Settings.logger.info("sleep 5 before shutdown...") + time.sleep(5) + + result = self.getPage("/healthcheck") + Settings.logger.info("healthcheck result: %s", result) + + PolicyReceiver.shutdown(audit) + time.sleep(1) + assert not PolicyReceiver.is_running() + + Tracker.validate() + + @pytest.mark.usefixtures("fix_deploy_handler", "fix_policy_receiver_websocket") + def test_zzz_get_catch_up(self): + """test /catch_up""" + Settings.logger.info("start /catch_up") + assert not PolicyReceiver.is_running() + audit = Audit(job_name="test_zzz_get_catch_up", req_message="start /catch_up") + PolicyReceiver.run(audit) + time.sleep(5) + result = self.getPage("/catch_up") + Settings.logger.info("catch_up result: %s", result) + self.assertStatus('200 OK') + Settings.logger.info("got catch_up: %s", self.body) + + Settings.logger.info("sleep 5 before shutdown...") + time.sleep(5) + + result = self.getPage("/healthcheck") + Settings.logger.info("healthcheck result: %s", result) + + PolicyReceiver.shutdown(audit) + time.sleep(1) + assert not PolicyReceiver.is_running() + + Tracker.validate() + + @pytest.mark.usefixtures( + "fix_deploy_handler", + "fix_policy_receiver_websocket", + "fix_cherrypy_engine_exit") + def test_zzzzz_shutdown(self): + """test shutdown""" + Settings.logger.info("start shutdown") + assert not PolicyReceiver.is_running() + audit = Audit(job_name="test_zzzzz_shutdown", req_message="start shutdown") + PolicyReceiver.run(audit) + + Settings.logger.info("sleep before send_notification...") + time.sleep(2) + + MockWebSocket.send_notification([1, 3, 5]) + Settings.logger.info("sleep after send_notification...") + time.sleep(3) + + result = self.getPage("/healthcheck") + Settings.logger.info("healthcheck result: %s", result) + + WebServerInternalBoomTest.do_gc_test = False + Settings.logger.info("shutdown...") + audit.audit_done("shutdown") + result = self.getPage("/shutdown") + Settings.logger.info("shutdown result: %s", result) + self.assertStatus('200 OK') + Settings.logger.info("got shutdown: %s", self.body) + time.sleep(1) + assert not PolicyReceiver.is_running() + + Tracker.validate() diff --git a/tests/test_zzz_memory.py b/tests/test_zzz_memory.py index e70cf59..e1b5af3 100644 --- a/tests/test_zzz_memory.py +++ b/tests/test_zzz_memory.py @@ -22,11 +22,12 @@ import gc import json import time +import pytest + from policyhandler.onap.audit import Audit, AuditHttpCode, Metrics from .mock_settings import Settings -Settings.init() class Node(object): """making the cycled objects""" @@ -66,7 +67,7 @@ def test_healthcheck_with_error(): audit.warn("debug from test_healthcheck_with_error") audit.info_requested("debug from test_healthcheck_with_error") if audit.is_success(): - audit.set_http_status_code(AuditHttpCode.DATA_NOT_FOUND_ERROR.value) + audit.set_http_status_code(AuditHttpCode.DATA_NOT_FOUND_OK.value) audit.set_http_status_code(AuditHttpCode.SERVER_INTERNAL_ERROR.value) metrics.metrics("test /healthcheck") diff --git a/version.properties b/version.properties index c162183..aae9468 100644 --- a/version.properties +++ b/version.properties @@ -1,5 +1,5 @@ major=4
-minor=4
+minor=5
patch=0
base_version=${major}.${minor}.${patch}
release_version=${base_version}
|