Пример #1
0
def test_get_config_service(mockconsul):
    err_msg = "Error getting ConsulHandle when configuring dmaap plugin: {0}"
    _ch = ConsulHandle("http://{0}:{1}".format(CONSUL_HOST, CONSUL_PORT), None,
                       None, None)

    config = _ch.get_config(DBCL_KEY_NAME)

    DMAAP_USER = config['dmaap']['username']
    DMAAP_PASS = config['dmaap']['password']
    DMAAP_OWNER = config['dmaap']['owner']

    if 'protocol' in config['dmaap']:
        DMAAP_PROTOCOL = config['dmaap']['protocol']
    else:
        DMAAP_PROTOCOL = 'https'  # Default to https (service discovery should give us this but doesn't

    if 'path' in config['dmaap']:
        DMAAP_PATH = config['dmaap']['path']
    else:
        DMAAP_PATH = 'webapi'  # Should come from service discovery but Consul doesn't support it

    service_address, service_port = _ch.get_service(DBC_SERVICE_NAME)

    DMAAP_API_URL = '{0}://{1}:{2}/{3}'.format(DMAAP_PROTOCOL, service_address,
                                               service_port, DMAAP_PATH)
CONSUL_HOST = "consul"  # Should always be a local consul agent on Cloudify Manager
DBCL_KEY_NAME = "dmaap-plugin"  # Consul key containing DMaaP data bus credentials
# In the ONAP Kubernetes environment, bus controller address is always "dmaap-bc", on port 8080 (http) and 8443 (https)
ONAP_SERVICE_ADDRESS = "dmaap-bc"
HTTP_PORT = "8080"
HTTPS_PORT = "8443"

try:
    _ch = ConsulHandle("http://{0}:8500".format(CONSUL_HOST), None, None, None)
except Exception as e:
    raise NonRecoverableError(
        "Error getting ConsulHandle when configuring dmaap plugin: {0}".format(
            e))

try:
    config = _ch.get_config(DBCL_KEY_NAME)
except Exception as e:
    raise NonRecoverableError(
        "Error getting config for '{0}' from ConsulHandle when configuring dmaap plugin: {1}"
        .format(DBCL_KEY_NAME, e))

try:
    DMAAP_USER = config['dmaap']['username']
except Exception as e:
    raise NonRecoverableError(
        "Error setting DMAAP_USER while configuring dmaap plugin: {0}".format(
            e))

try:
    DMAAP_PASS = config['dmaap']['password']
except Exception as e: