From a39f4e82cef0414f510cf20e25864ac04cc8f055 Mon Sep 17 00:00:00 2001 From: Alex Shatov Date: Wed, 5 Dec 2018 15:23:50 -0500 Subject: 4.5.0 policy-handler - multi change DCAEGEN2-853: - stop reporting the absence of policies or updates as error - this is an expected result == INFO or WARNING DCAEGEN2-903: preparation for TLS on the web-server of policy-handler DCAEGEN2-930: - configurable timeouts for http requests from policy-handler - added configurable pinging on the web-socket to PDP - added healthcheck info on the web-socket - upgraded websocket-client lib to 0.53.0 DCAEGEN2-1017: fixed a bug on policy-filter matching by filter_config_name - refactored and enhanced the unit-tests Change-Id: I111ddc57bb978554ef376cbf916965b6667dad9b Signed-off-by: Alex Shatov Issue-ID: DCAEGEN2-853 Issue-ID: DCAEGEN2-903 Issue-ID: DCAEGEN2-930 Issue-ID: DCAEGEN2-1017 --- tests/conftest.py | 299 +++++ tests/mock_config.json | 15 +- tests/mock_deploy_handler.py | 48 + tests/mock_expected.py | 3013 ++++++++++++++++++++++++++++++++++++++++++ tests/mock_policy_engine.py | 131 ++ tests/mock_settings.py | 41 +- tests/mock_tracker.py | 138 ++ tests/mock_websocket.py | 89 ++ tests/test_policy_rest.py | 47 + tests/test_policyhandler.py | 798 +---------- tests/test_pz_catch_up.py | 96 ++ tests/test_pz_pdp_boom.py | 226 ++++ tests/test_pz_ph_boom.py | 228 ++++ tests/test_zzz_memory.py | 5 +- 14 files changed, 4378 insertions(+), 796 deletions(-) create mode 100644 tests/conftest.py create mode 100644 tests/mock_deploy_handler.py create mode 100644 tests/mock_expected.py create mode 100644 tests/mock_policy_engine.py create mode 100644 tests/mock_tracker.py create mode 100644 tests/mock_websocket.py create mode 100644 tests/test_policy_rest.py create mode 100644 tests/test_pz_catch_up.py create mode 100644 tests/test_pz_pdp_boom.py create mode 100644 tests/test_pz_ph_boom.py (limited to 'tests') 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, 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, 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, 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, _ = 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, _ = 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, _ = 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, _ = 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") -- cgit 1.2.3-korg