-
Notifications
You must be signed in to change notification settings - Fork 91
Expand file tree
/
Copy pathdynamic_config_envoy_proxy.py
More file actions
87 lines (68 loc) · 3.67 KB
/
dynamic_config_envoy_proxy.py
File metadata and controls
87 lines (68 loc) · 3.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
"""Customized fixture to dynamically configure an Envoy Proxy."""
import pytest
import logging
from typing import Generator
from test.integration import integration_test_fixtures, common, utility
import envoy_proxy
from dynamic_config import dynamic_config_server
from collections.abc import Callable
from google.protobuf import message
@pytest.fixture()
def proxy_config() -> Generator[str, None, None]:
"""Yield the stock Envoy proxy configuration."""
yield "nighthawk/benchmarks/configurations/envoy_proxy.yaml"
class InjectDynamicHttpProxyIntegrationTestBase(envoy_proxy.InjectHttpProxyIntegrationTestBase):
"""Proxy and Test server fixture.
Fixture which spins up a Nighthawk test server, an Envoy proxy and a xDS configuration
task which dynamically configure the Envoy. Both will be listening for plain http traffic.
Attributes:
See base class.
"""
def __init__(self, request, server_config: str, proxy_config: str,
dynamic_config_generator: Callable[[str, list[utility.SocketAddress]],
message.Message]):
"""Initialize an InjectDynamicHttpProxyIntegrationTestBase.
Args:
request: The pytest `request` test fixture used to determine information
about the currently executing test case.
server_config: Path to the server configuration.
proxy_config: Path to the proxy configuration.
dynamic_config_generator: Function for generating settings for the dynamic configuration component.
"""
super(InjectDynamicHttpProxyIntegrationTestBase, self).__init__(request, server_config,
proxy_config)
self._dynamic_config_generator = dynamic_config_generator
def setUp(self):
"""Set up the injected Envoy proxy as well as the test server.
Assert that both started successfully, and return afterwards.
"""
super(InjectDynamicHttpProxyIntegrationTestBase, self).setUp()
available_endpoints = utility.parseUrisToSocketAddress(self.getAllTestServerRootUris())
test_dir = self.test_server.tmpdir
dynamic_config_settings = self._dynamic_config_generator(test_dir, available_endpoints)
self._dynamic_config_controller = dynamic_config_server.DynamicConfigController(
dynamic_config_settings)
assert (self._dynamic_config_controller.start())
logging.info("dynamic configuration running")
def tearDown(self, caplog):
"""Tear down the proxy and test server. Assert that both exit succesfully."""
super(InjectDynamicHttpProxyIntegrationTestBase, self).tearDown(caplog)
self._dynamic_config_controller.stop()
@pytest.fixture(params=integration_test_fixtures.determineIpVersionsFromEnvironment())
def inject_dynamic_envoy_http_proxy_fixture(request, server_config, proxy_config,
dynamic_config_generator, caplog):
"""Injects a dynamically configured Envoy proxy in front of the test server.
Args:
request: The pytest `request` test fixture used to determine information about the currently executing test case.
server_config: Path to the server configuration template.
proxy_config: Path to the proxy configuration template.
dynamic_config_generator: Function used to generate the settings for the configuration generator.
caplog: The pytest `caplog` test fixture used to examine logged messages.
Yields:
A successfully set up InjectDynamicHttpProxyIntegrationTestBase instance.
"""
fixture = InjectDynamicHttpProxyIntegrationTestBase(request, server_config, proxy_config,
dynamic_config_generator)
fixture.setUp()
yield fixture
fixture.tearDown(caplog)