fix(connection): probe the API port from base_url in is_alive
is_alive always opened port 443 on the hostname, so a firewall whose API is reached through base_url on another port (https://fw:8443) read as dead. The probe now takes host and port from base_url, falling back to the scheme's default port. Closes #15
This commit is contained in:
1 parent
e2cac52a12
commit
4e377923db
4 files changed
+50
-3
No files matched your search
@@ -164,6 +164,30 @@ class TestIsAlive:
|
||||
result = driver.is_alive()
|
||||
assert result == {"is_alive": False}
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("base_url", "expected"),
|
||||
[
|
||||
(None, ("opnsense.example.com", 443)),
|
||||
("https://fw.example.com:8443", ("fw.example.com", 8443)),
|
||||
("https://fw.example.com:8443/", ("fw.example.com", 8443)),
|
||||
("https://fw.example.com", ("fw.example.com", 443)),
|
||||
("http://fw.example.com", ("fw.example.com", 80)),
|
||||
("https://[2001:db8::1]:4443", ("2001:db8::1", 4443)),
|
||||
],
|
||||
)
|
||||
def test_probes_the_host_and_port_of_base_url(self, base_url, expected):
|
||||
"""#15: an API on another port than 443 must not read as dead."""
|
||||
args = {"verify": False}
|
||||
if base_url is not None:
|
||||
args["base_url"] = base_url
|
||||
drv = OPNsenseDriver("opnsense.example.com", "u", "p", optional_args=args)
|
||||
drv.session = MagicMock()
|
||||
with patch("napalm_opnsense.opnsense.socket.create_connection") as mock_conn:
|
||||
mock_conn.return_value.__enter__ = MagicMock(return_value=None)
|
||||
mock_conn.return_value.__exit__ = MagicMock(return_value=False)
|
||||
assert drv.is_alive() == {"is_alive": True}
|
||||
assert mock_conn.call_args.args[0] == expected
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# _get()
|
||||
|
||||
Reference in new issue
Block a user