예제 #1
0
def run_policy_handler():
    """main run function for policy-handler"""
    Config.init_config()

    from policyhandler import LogWriter
    from policyhandler.policy_receiver import PolicyReceiver
    from policyhandler.service_activator import ServiceActivator
    from policyhandler.web_server import PolicyWeb

    logger = Utils.get_logger(__file__)
    sys.stdout = LogWriter(logger.info)
    sys.stderr = LogWriter(logger.error)

    logger.info("========== run_policy_handler ========== %s", __package__)
    Audit.init(Config.system_name, Config.LOGGER_CONFIG_FILE_PATH)

    audit = Audit(req_message="start policy handler")

    Config.discover(audit)
    ServiceActivator.determine_mode_of_operation(audit)
    logger.info(
        audit.info("starting policy_handler with config: {}".format(
            Config.discovered_config)))

    PolicyReceiver.run(audit)
    PolicyWeb.run_forever(audit)
예제 #2
0
standard pytest file that contains the shared fixtures
https://docs.pytest.org/en/latest/fixture.html
"""

import time

import pytest
from policyhandler import pdp_client
from policyhandler.deploy_handler import DeployHandler
from policyhandler.onap.audit import Audit
from policyhandler.pdp_api.dmaap_mr import DmaapMr
from policyhandler.utils import Utils

from ..mock_tracker import MockHttpResponse

_LOGGER = Utils.get_logger(__file__)


@pytest.fixture()
def fix_pdp_post(monkeypatch):
    """monkeyed request /decision/v1 to PDP"""
    def monkeyed_policy_rest_post(uri, json=None, **kwargs):
        """monkeypatch for the POST to policy-engine"""
        return MockHttpResponse("post", uri, json=json, **kwargs)

    _LOGGER.info("setup fix_pdp_post")
    pdp_client.PolicyRest._lazy_inited = False
    pdp_client.PolicyRest._lazy_init()
    monkeypatch.setattr(
        'policyhandler.pdp_client.PolicyRest._requests_session.post',
        monkeyed_policy_rest_post)