Fix errors in the test
This commit is contained in:
parent
f7969c2deb
commit
f791897449
3 changed files with 79 additions and 38 deletions
16
.vscode/launch.json
vendored
16
.vscode/launch.json
vendored
|
|
@ -4,6 +4,22 @@
|
||||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "PyTest Current File",
|
||||||
|
"type": "python",
|
||||||
|
"request": "launch",
|
||||||
|
"module": "pytest",
|
||||||
|
"justMyCode": true,
|
||||||
|
"console": "integratedTerminal",
|
||||||
|
"cwd": "${workspaceFolder}/src",
|
||||||
|
"args": [
|
||||||
|
"-vv",
|
||||||
|
"${file}"
|
||||||
|
],
|
||||||
|
"env": {
|
||||||
|
"PYTHONPATH": "${cwd}/src"
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "Python: Current File",
|
"name": "Python: Current File",
|
||||||
"type": "python",
|
"type": "python",
|
||||||
|
|
|
||||||
|
|
@ -128,7 +128,14 @@ class Docker(ProcessorInterface):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
def inspect_network(self):
|
def inspect_network(self):
|
||||||
ha_proxy_network_name = next(iter(self.client.containers.get(socket.gethostname()).attrs["NetworkSettings"]["Networks"]))
|
try:
|
||||||
|
ha_proxy_network_name = next(iter(self.client.containers.get(socket.gethostname()).attrs["NetworkSettings"]["Networks"]))
|
||||||
|
except:
|
||||||
|
# HAProxy is not running in a container, get first container network
|
||||||
|
if len(self.client.containers.list()) == 0:
|
||||||
|
return
|
||||||
|
ha_proxy_network_name = next(iter(self.client.containers.get(self.client.containers.list()[0].name).attrs["NetworkSettings"]["Networks"]))
|
||||||
|
|
||||||
ha_proxy_network = self.client.networks.get(ha_proxy_network_name)
|
ha_proxy_network = self.client.networks.get(ha_proxy_network_name)
|
||||||
|
|
||||||
self.parsed_object = {}
|
self.parsed_object = {}
|
||||||
|
|
@ -192,6 +199,8 @@ class Kubernetes(ProcessorInterface):
|
||||||
|
|
||||||
self.parsed_object = {}
|
self.parsed_object = {}
|
||||||
for ingress in ret.items:
|
for ingress in ret.items:
|
||||||
|
if 'kubernetes.io/ingress.class' not in ingress.metadata.annotations:
|
||||||
|
continue
|
||||||
if ingress.metadata.annotations['kubernetes.io/ingress.class'] != "easyhaproxy-ingress":
|
if ingress.metadata.annotations['kubernetes.io/ingress.class'] != "easyhaproxy-ingress":
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,15 +6,24 @@ from functions import Functions
|
||||||
from processor import ProcessorInterface
|
from processor import ProcessorInterface
|
||||||
from processor import Docker
|
from processor import Docker
|
||||||
|
|
||||||
def _get_hydrated_object(parsed_objects, key):
|
|
||||||
assert key in parsed_objects.keys()
|
def _get_hydrated_object(parsed_objects, lookup_key):
|
||||||
hydrated_object = {}
|
hydrated_object = {}
|
||||||
for keys in parsed_objects[key]:
|
for key in parsed_objects:
|
||||||
if "easyhaproxy" in keys:
|
for keys in parsed_objects[key]:
|
||||||
hydrated_object[keys] = parsed_objects[key][keys]
|
if lookup_key in keys:
|
||||||
|
hydrated_object[keys] = parsed_objects[key][keys]
|
||||||
return hydrated_object
|
return hydrated_object
|
||||||
|
|
||||||
|
|
||||||
|
def _get_ip_host(parsed_objects, lookup_key):
|
||||||
|
hydrated_object = {}
|
||||||
|
for key in parsed_objects:
|
||||||
|
for keys in parsed_objects[key]:
|
||||||
|
if lookup_key in keys:
|
||||||
|
return key
|
||||||
|
|
||||||
|
|
||||||
def test_processor_docker():
|
def test_processor_docker():
|
||||||
try:
|
try:
|
||||||
client = docker.from_env()
|
client = docker.from_env()
|
||||||
|
|
@ -25,31 +34,31 @@ def test_processor_docker():
|
||||||
pytest.skip("I cannot run this test with other containers running.")
|
pytest.skip("I cannot run this test with other containers running.")
|
||||||
|
|
||||||
container = client.containers.run("byjg/static-httpserver",
|
container = client.containers.run("byjg/static-httpserver",
|
||||||
name="test_processor_docker",
|
name="test_processor_docker",
|
||||||
detach=True,
|
detach=True,
|
||||||
auto_remove=True,
|
auto_remove=True,
|
||||||
remove=True,
|
remove=True,
|
||||||
labels={
|
labels={
|
||||||
"easyhaproxy.http.port": "80",
|
"easyhaproxy.http.port": "80",
|
||||||
"easyhaproxy.http.localport": "8080",
|
"easyhaproxy.http.localport": "8080",
|
||||||
"easyhaproxy.http.host": "host1.local",
|
"easyhaproxy.http.host": "host1.local",
|
||||||
|
|
||||||
"easyhaproxy.http2.port": "90",
|
"easyhaproxy.http2.port": "90",
|
||||||
"easyhaproxy.http2.localport": "9000",
|
"easyhaproxy.http2.localport": "9000",
|
||||||
"easyhaproxy.http2.host": "host2.local",
|
"easyhaproxy.http2.host": "host2.local",
|
||||||
"easyhaproxy.http2.letsencrypt": "true",
|
"easyhaproxy.http2.letsencrypt": "true",
|
||||||
})
|
})
|
||||||
container2 = client.containers.run("byjg/static-httpserver",
|
container2 = client.containers.run("byjg/static-httpserver",
|
||||||
name="test2_processor_docker",
|
name="test2_processor_docker",
|
||||||
detach=True,
|
detach=True,
|
||||||
auto_remove=True,
|
auto_remove=True,
|
||||||
remove=True,
|
remove=True,
|
||||||
labels={
|
labels={
|
||||||
"easyhaproxy.ssl.port": "443",
|
"easyhaproxy.ssl.port": "443",
|
||||||
"easyhaproxy.ssl.localport": "8080",
|
"easyhaproxy.ssl.localport": "8080",
|
||||||
"easyhaproxy.ssl.host": "hostssl.local",
|
"easyhaproxy.ssl.host": "hostssl.local",
|
||||||
"easyhaproxy.ssl.sslcert": "U29tZSBQRU0gQ2VydGlmaWNhdGU="
|
"easyhaproxy.ssl.sslcert": "U29tZSBQRU0gQ2VydGlmaWNhdGU="
|
||||||
})
|
})
|
||||||
try:
|
try:
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
|
|
@ -66,27 +75,34 @@ def test_processor_docker():
|
||||||
'easyhaproxy.http2.localport': '9000',
|
'easyhaproxy.http2.localport': '9000',
|
||||||
'easyhaproxy.http2.port': '90',
|
'easyhaproxy.http2.port': '90',
|
||||||
'easyhaproxy.http2.letsencrypt': 'true',
|
'easyhaproxy.http2.letsencrypt': 'true',
|
||||||
} == _get_hydrated_object(static.get_parsed_object(), "test_processor_docker")
|
} == _get_hydrated_object(static.get_parsed_object(), "easyhaproxy.http")
|
||||||
assert {
|
assert {
|
||||||
'easyhaproxy.ssl.host': 'hostssl.local',
|
'easyhaproxy.ssl.host': 'hostssl.local',
|
||||||
'easyhaproxy.ssl.localport': '8080',
|
'easyhaproxy.ssl.localport': '8080',
|
||||||
'easyhaproxy.ssl.port': '443',
|
'easyhaproxy.ssl.port': '443',
|
||||||
'easyhaproxy.ssl.sslcert': 'U29tZSBQRU0gQ2VydGlmaWNhdGU='
|
'easyhaproxy.ssl.sslcert': 'U29tZSBQRU0gQ2VydGlmaWNhdGU='
|
||||||
} == _get_hydrated_object(static.get_parsed_object(), "test2_processor_docker")
|
} == _get_hydrated_object(static.get_parsed_object(), "easyhaproxy.ssl.")
|
||||||
|
|
||||||
assert static.get_hosts() is None
|
assert static.get_hosts() is None
|
||||||
assert static.get_certs() == {}
|
assert static.get_certs() == {}
|
||||||
|
|
||||||
haproxy_cfg = static.get_haproxy_conf()
|
haproxy_cfg = static.get_haproxy_conf()
|
||||||
assert haproxy_cfg == Functions.load(os.path.join(os.path.dirname(os.path.realpath(__file__)), "./expected/docker.txt"))
|
assert haproxy_cfg == Functions.load(os.path.join(os.path.dirname(os.path.realpath(__file__)), "./expected/docker.txt")).replace("test_processor_docker", _get_ip_host(
|
||||||
|
static.get_parsed_object(), "easyhaproxy.http")).replace("test2_processor_docker", _get_ip_host(static.get_parsed_object(), "easyhaproxy.ssl"))
|
||||||
|
|
||||||
assert static.get_letsencrypt_hosts() == ['host2.local']
|
assert static.get_letsencrypt_hosts() == ['host2.local']
|
||||||
assert static.get_hosts() == ['hostssl.local:443', 'host1.local:80', 'host2.local:90']
|
assert static.get_hosts() == [
|
||||||
assert static.get_certs() == {'hostssl.local.pem': 'Some PEM Certificate'}
|
'hostssl.local:443',
|
||||||
|
'host1.local:80',
|
||||||
|
'host2.local:90'
|
||||||
|
]
|
||||||
|
assert static.get_certs() == {
|
||||||
|
'hostssl.local.pem': 'Some PEM Certificate'
|
||||||
|
}
|
||||||
finally:
|
finally:
|
||||||
os.environ['EASYHAPROXY_LETSENCRYPT_EMAIL'] = ''
|
os.environ['EASYHAPROXY_LETSENCRYPT_EMAIL'] = ''
|
||||||
container.stop()
|
container.stop()
|
||||||
container2.stop()
|
container2.stop()
|
||||||
|
|
||||||
|
|
||||||
#test_processor_docker()
|
# test_processor_docker()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue