Skip to content

Commit f75a718

Browse files
Eshan PatelPrabhakar Kumar
authored andcommitted
Fixes an issue related to communicating with MATLAB on Windows through the FQDN mode of addressing in certain cloud environments where FQDN resolution is not possible.
1 parent aee1078 commit f75a718

File tree

3 files changed

+29
-12
lines changed

3 files changed

+29
-12
lines changed

matlab_proxy/util/__init__.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -228,18 +228,13 @@ def get_access_url(app):
228228
access_protocol = "https" if ssl_context else "http"
229229

230230
# When host interface is set to 0.0.0.0, in a windows system, the server will not be accessible.
231-
# Setting the value to fqdn, will allow it be remotely and locally accessible.
231+
# Setting the value to 127.0.0.1, will allow it be remotely and locally accessible.
232232

233233
# NOTE: When windows container support is introduced this will need to be tweaked accordingly.
234234
if host_interface == "0.0.0.0" and system.is_windows():
235-
import socket
235+
host_interface = "127.0.0.1"
236236

237-
hostname = socket.gethostname()
238-
fqdn = socket.getfqdn(hostname)
239-
240-
url = f"{access_protocol}://{fqdn}:{port}{base_url}"
241-
else:
242-
url = f"{access_protocol}://{host_interface}:{port}{base_url}"
237+
url = f"{access_protocol}://{host_interface}:{port}{base_url}"
243238

244239
return url
245240

matlab_proxy/util/mwi/embedded_connector/request.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,10 @@ async def get_state(mwi_server_url, headers=None):
104104

105105
if not resp["messages"]["PingResponse"][0]["messageFaults"]:
106106
return "up"
107-
except Exception:
107+
except Exception as err:
108+
logger.debug(
109+
f"{err}: Embbeded connector is currently not responding to ping requests."
110+
)
108111
pass
109112

110113
return "down"

tests/test_app.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import asyncio
44
import json
5+
import platform
56
import time
67
import datetime
78

@@ -657,9 +658,27 @@ def non_default_host_interface_fixture(monkeypatch):
657658
# First set the default host interface to a non-default value
658659
# Then set MWI_TEST to false and then create an instance of the test_server
659660
# This order will set the test_server with appropriate values.
660-
def test_get_access_url_non_dev(non_default_host_interface, non_test_env, test_server):
661-
"""Test to check access url to not be 127.0.0.1 in non-dev mode"""
662-
assert "127.0.0.1" not in util.get_access_url(test_server.app)
661+
662+
663+
@pytest.mark.skipif(
664+
platform.system() == "Linux" or platform.system() == "Darwin",
665+
reason="Testing the windows access URL",
666+
)
667+
def test_get_access_url_non_dev_windows(
668+
non_default_host_interface, non_test_env, test_server
669+
):
670+
"""Test to check access url to be 127.0.0.1 in non-dev mode on Windows"""
671+
assert "127.0.0.1" in util.get_access_url(test_server.app)
672+
673+
674+
@pytest.mark.skipif(
675+
platform.system() == "Windows", reason="Testing the non-Windows access URL"
676+
)
677+
def test_get_access_url_non_dev_posix(
678+
non_default_host_interface, non_test_env, test_server
679+
):
680+
"""Test to check access url to be 0.0.0.0 in non-dev mode on Linux/Darwin"""
681+
assert "0.0.0.0" in util.get_access_url(test_server.app)
663682

664683

665684
@pytest.fixture(name="set_licensing_info_mock_fetch_single_entitlement")

0 commit comments

Comments
 (0)