async def deep_check():
    template = random.choice(
        list(XDS_TEMPLATES['default'].keys())
    )
    await discovery.response(
        mock_discovery_request(),
        xds_type=template
    )
    node = mock_discovery_request().node
    match_node(node_value=extract_node_key(node))
    return PlainTextResponse(f'Rendered {template} OK')
def test_loading_sources_t1(discovery_request, sources):
    expected = {
        'scopes': {
            'listeners': [{
                'name': 'ssh',
                'port': 22,
                'tcp': True,
                'target': 'httpbin-proxy',
                'service_clusters': ['T1']
            }],
            'default': [
                {
                    'name': 'httpbin-proxy',
                    'service_clusters': ['T1'],
                    'domains': ['example.local'],
                    'endpoints': [{
                        'address': 'httpbin.org',
                        'port': 443
                    }],
                },
            ]
        }
    }
    instances = match_node(node_value=extract_node_key(discovery_request.node))
    assert instances.dict() == expected
Exemple #3
0
def instances(
        service_cluster: str = Query(
            '*',
            title='The clients service cluster to emulate in this XDS request'
        ),
        modified:
    str = Query(
        'yes',
        title=
        'Whether the sources should run Modifiers/Global Modifiers prior to being returned'
    )):
    node = mock_discovery_request(service_cluster=service_cluster).node
    args = {
        'modify': yaml.safe_load(modified),
        'node_value': extract_node_key(node)
    }
    ret = match_node(**args)
    safe_response = jsonable_encoder(ret)
    return json_response_class(content=safe_response)
def make_context(node_value: str, template: XdsTemplate):
    """
    Creates context variables to be passed into either a jinja template,
    or as kwargs to a python template.
    """
    matches = match_node(node_value=node_value)
    context = {**template_context}

    for scope, instances in matches.scopes.items():
        if scope == 'default':
            context['instances'] = instances
        else:
            context[scope] = instances

    if not template.is_python_source:
        for variable in list(context):
            if variable in template.jinja_variables:
                continue
            context.pop(variable, None)

    stats.set('discovery.context.bytes', sys.getsizeof(context))
    return context
def test_loading_sources_wildcard(discovery_request, sources):
    expected = {
        'scopes': {
            'listeners': [{
                'name': 'ssh',
                'port': 22,
                'tcp': True,
                'target': 'httpbin-proxy',
                'service_clusters': ['T1']
            }],
            'default': [{
                'name':
                'google-proxy',
                'service_clusters': ['X1'],
                'domains': ['google.local'],
                'endpoints': [{
                    'address': 'google.com.au',
                    'port': 443,
                    'region': 'ap-southeast-2'
                }, {
                    'address': 'google.com',
                    'port': 443,
                    'region': 'us-west-1'
                }],
            }, {
                'name': 'httpbin-proxy',
                'service_clusters': ['T1'],
                'domains': ['example.local'],
                'endpoints': [{
                    'address': 'httpbin.org',
                    'port': 443
                }],
            }]
        }
    }
    discovery_request.node.cluster = '*'
    instances = match_node(node_value=extract_node_key(discovery_request.node))
    assert instances.dict() == expected
def test_loading_sources_x1(discovery_request, sources):
    expected = {
        'scopes': {
            'default': [{
                'name':
                'google-proxy',
                'service_clusters': ['X1'],
                'domains': ['google.local'],
                'endpoints': [{
                    'address': 'google.com.au',
                    'port': 443,
                    'region': 'ap-southeast-2'
                }, {
                    'address': 'google.com',
                    'port': 443,
                    'region': 'us-west-1'
                }],
            }]
        }
    }
    discovery_request.node.cluster = 'X1'
    instances = match_node(node_value=extract_node_key(discovery_request.node))
    assert instances.dict() == expected