matlab-proxy 0.26.0__py3-none-any.whl → 0.27.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of matlab-proxy might be problematic. Click here for more details.
- matlab_proxy/app.py +50 -39
- matlab_proxy/app_state.py +9 -3
- matlab_proxy/default_configuration.py +2 -2
- matlab_proxy/gui/index.html +2 -2
- matlab_proxy/gui/static/css/{index.BSVLACuY.css → index.BLxKpbak.css} +2 -2
- matlab_proxy/gui/static/js/{index.CZgGkMCD.js → index.CKi3IRxe.js} +16 -16
- matlab_proxy/settings.py +5 -5
- matlab_proxy/util/__init__.py +2 -2
- matlab_proxy/util/list_servers.py +2 -2
- matlab_proxy/util/mwi/environment_variables.py +5 -0
- matlab_proxy/util/mwi/logger.py +1 -2
- matlab_proxy/util/mwi/session_name.py +28 -0
- matlab_proxy/util/mwi/token_auth.py +2 -2
- matlab_proxy/util/mwi/validators.py +3 -5
- {matlab_proxy-0.26.0.dist-info → matlab_proxy-0.27.1.dist-info}/METADATA +37 -25
- {matlab_proxy-0.26.0.dist-info → matlab_proxy-0.27.1.dist-info}/RECORD +23 -53
- {matlab_proxy-0.26.0.dist-info → matlab_proxy-0.27.1.dist-info}/WHEEL +1 -2
- matlab_proxy_manager/README.md +85 -0
- matlab_proxy_manager/lib/README.md +53 -0
- matlab_proxy_manager/storage/README.md +54 -0
- matlab_proxy_manager/web/README.md +37 -0
- matlab_proxy-0.26.0.dist-info/top_level.txt +0 -3
- tests/integration/__init__.py +0 -1
- tests/integration/integration_tests_with_license/__init__.py +0 -1
- tests/integration/integration_tests_with_license/conftest.py +0 -47
- tests/integration/integration_tests_with_license/test_http_end_points.py +0 -397
- tests/integration/integration_tests_without_license/__init__.py +0 -1
- tests/integration/integration_tests_without_license/conftest.py +0 -116
- tests/integration/integration_tests_without_license/test_matlab_is_down_if_unlicensed.py +0 -49
- tests/integration/utils/__init__.py +0 -1
- tests/integration/utils/integration_tests_utils.py +0 -352
- tests/integration/utils/licensing.py +0 -152
- tests/unit/__init__.py +0 -1
- tests/unit/conftest.py +0 -66
- tests/unit/test_app.py +0 -1299
- tests/unit/test_app_state.py +0 -1094
- tests/unit/test_constants.py +0 -7
- tests/unit/test_ddux.py +0 -22
- tests/unit/test_devel.py +0 -246
- tests/unit/test_non_dev_mode.py +0 -169
- tests/unit/test_settings.py +0 -679
- tests/unit/util/__init__.py +0 -3
- tests/unit/util/mwi/__init__.py +0 -1
- tests/unit/util/mwi/embedded_connector/__init__.py +0 -1
- tests/unit/util/mwi/embedded_connector/test_helpers.py +0 -29
- tests/unit/util/mwi/embedded_connector/test_request.py +0 -64
- tests/unit/util/mwi/test_custom_http_headers.py +0 -281
- tests/unit/util/mwi/test_download.py +0 -152
- tests/unit/util/mwi/test_logger.py +0 -82
- tests/unit/util/mwi/test_token_auth.py +0 -303
- tests/unit/util/mwi/test_validators.py +0 -364
- tests/unit/util/test_cookie_jar.py +0 -252
- tests/unit/util/test_mw.py +0 -550
- tests/unit/util/test_util.py +0 -221
- tests/utils/__init__.py +0 -1
- tests/utils/logging_util.py +0 -81
- {matlab_proxy-0.26.0.dist-info → matlab_proxy-0.27.1.dist-info}/entry_points.txt +0 -0
- {matlab_proxy-0.26.0.dist-info → matlab_proxy-0.27.1.dist-info/licenses}/LICENSE.md +0 -0
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
# Copyright 2023-2024 The MathWorks, Inc.
|
|
2
|
-
|
|
3
|
-
import os
|
|
4
|
-
from tests.integration.utils import integration_tests_utils as utils
|
|
5
|
-
import pytest
|
|
6
|
-
from matlab_proxy.util.mwi import environment_variables as mwi_env
|
|
7
|
-
from tests.utils.logging_util import create_integ_test_logger
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
_logger = create_integ_test_logger(
|
|
11
|
-
__name__, log_file_path=os.getenv("MWI_INTEG_TESTS_LOG_FILE_PATH")
|
|
12
|
-
)
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
@pytest.fixture(scope="module", name="module_monkeypatch")
|
|
16
|
-
def monkeypatch_module_scope_fixture():
|
|
17
|
-
"""
|
|
18
|
-
To ensure that modifications made with the monkeypatch fixture
|
|
19
|
-
persist across all tests in the module, this fixture
|
|
20
|
-
has been created in 'module' scope. This is done because a 'module'
|
|
21
|
-
scope object is needed with matlab-proxy 'module' scope fixture.
|
|
22
|
-
This allows us to patch certain aspects, like environment variables,
|
|
23
|
-
for all tests within the module.
|
|
24
|
-
|
|
25
|
-
Yields:
|
|
26
|
-
class object: Object of class MonkeyPatch
|
|
27
|
-
"""
|
|
28
|
-
with pytest.MonkeyPatch.context() as mp:
|
|
29
|
-
yield mp
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
@pytest.fixture(autouse=True, scope="module")
|
|
33
|
-
def matlab_proxy_fixture(module_monkeypatch, request):
|
|
34
|
-
"""
|
|
35
|
-
Pytest fixture for managing a standalone matlab-proxy process
|
|
36
|
-
for testing purposes. This fixture sets up a matlab-proxy process in
|
|
37
|
-
the module scope, and tears it down after all the tests are executed.
|
|
38
|
-
"""
|
|
39
|
-
|
|
40
|
-
utils.perform_basic_checks()
|
|
41
|
-
|
|
42
|
-
module_monkeypatch.setenv(mwi_env.get_env_name_testing(), "false")
|
|
43
|
-
module_monkeypatch.setenv(mwi_env.get_env_name_development(), "false")
|
|
44
|
-
_logger.info("Started MATLAB Proxy process")
|
|
45
|
-
|
|
46
|
-
# Run the matlab proxy tests
|
|
47
|
-
yield
|
|
@@ -1,397 +0,0 @@
|
|
|
1
|
-
# Copyright 2023-2025 The MathWorks, Inc.
|
|
2
|
-
|
|
3
|
-
"""
|
|
4
|
-
Contains integration tests which exercise HTTP endpoints of interest exposed by matlab-proxy-app
|
|
5
|
-
"""
|
|
6
|
-
|
|
7
|
-
# Imports
|
|
8
|
-
from enum import Enum
|
|
9
|
-
import json
|
|
10
|
-
import os
|
|
11
|
-
import pytest
|
|
12
|
-
import re
|
|
13
|
-
import requests
|
|
14
|
-
import time
|
|
15
|
-
from requests.adapters import HTTPAdapter, Retry
|
|
16
|
-
from urllib.parse import urlparse, parse_qs
|
|
17
|
-
|
|
18
|
-
# Local module imports
|
|
19
|
-
import matlab_proxy.settings as settings
|
|
20
|
-
from matlab_proxy.constants import MWI_AUTH_TOKEN_NAME_FOR_HTTP
|
|
21
|
-
from matlab_proxy.util import system
|
|
22
|
-
from tests.integration.utils import integration_tests_utils as utils
|
|
23
|
-
from tests.utils.logging_util import create_integ_test_logger
|
|
24
|
-
|
|
25
|
-
# Logger Setup
|
|
26
|
-
_logger = create_integ_test_logger(__name__)
|
|
27
|
-
|
|
28
|
-
# Constants
|
|
29
|
-
|
|
30
|
-
# Timeout for polling the matlab-proxy http endpoints
|
|
31
|
-
# matlab proxy in Mac machines takes more time to be 'up'
|
|
32
|
-
MAX_TIMEOUT = settings.get_process_startup_timeout()
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
class Format(Enum):
|
|
36
|
-
"""
|
|
37
|
-
An enumeration to specify different format types.
|
|
38
|
-
|
|
39
|
-
Attributes:
|
|
40
|
-
JSON (int): Represents the JSON format type.
|
|
41
|
-
TEXT (int): Represents the plain text format type.
|
|
42
|
-
"""
|
|
43
|
-
|
|
44
|
-
JSON = 1
|
|
45
|
-
TEXT = 2
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
# Utility Functions
|
|
49
|
-
def _http_get_request(
|
|
50
|
-
uri, connection_scheme, headers, http_endpoint="", outputFormat=Format.TEXT
|
|
51
|
-
):
|
|
52
|
-
"""
|
|
53
|
-
Sends an HTTP GET request to a specified URI, optionally appending an endpoint to the URI.
|
|
54
|
-
|
|
55
|
-
This function uses a session with retries configured for transient network errors. It can return
|
|
56
|
-
the response in either text or JSON format, based on the outputFormat parameter.
|
|
57
|
-
|
|
58
|
-
Parameters:
|
|
59
|
-
- uri (str): The base URI for the HTTP request.
|
|
60
|
-
- connection_scheme (str): The scheme to use for the connection (e.g., 'http' or 'https').
|
|
61
|
-
- headers (dict): A dictionary of HTTP headers to include in the request.
|
|
62
|
-
- http_endpoint (str, optional): An additional endpoint to append to the base URI. Defaults to an empty string.
|
|
63
|
-
- outputFormat (format, optional): The desired format for the response content. This should be an attribute
|
|
64
|
-
of a format enumeration, supporting at least 'TEXT' and 'JSON' options. Defaults to Format.TEXT.
|
|
65
|
-
|
|
66
|
-
Returns:
|
|
67
|
-
- str or dict: The response content as a string if outputFormat is Format.TEXT, or as a dictionary
|
|
68
|
-
if outputFormat is Format.JSON.
|
|
69
|
-
|
|
70
|
-
Raises:
|
|
71
|
-
- Exception: If an invalid output format is specified.
|
|
72
|
-
|
|
73
|
-
Note:
|
|
74
|
-
- The function disables SSL certificate verification (`verify=False`). This may introduce security risks,
|
|
75
|
-
such as vulnerability to man-in-the-middle attacks. Use with caution in a production environment.
|
|
76
|
-
"""
|
|
77
|
-
request_uri = uri + http_endpoint
|
|
78
|
-
with requests.Session() as s:
|
|
79
|
-
retries = Retry(total=10, backoff_factor=0.1)
|
|
80
|
-
s.mount(f"{connection_scheme}://", HTTPAdapter(max_retries=retries))
|
|
81
|
-
response = s.get(request_uri, headers=headers, verify=False)
|
|
82
|
-
|
|
83
|
-
if outputFormat == Format.TEXT:
|
|
84
|
-
return response.text
|
|
85
|
-
elif outputFormat == Format.JSON:
|
|
86
|
-
return json.loads(response.text)
|
|
87
|
-
|
|
88
|
-
raise Exception("Invalid output format specified.")
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
def _check_matlab_status(matlab_proxy_app_fixture, status):
|
|
92
|
-
"""
|
|
93
|
-
Check the status of a MATLAB session until a specified status is reached or a timeout occurs.
|
|
94
|
-
|
|
95
|
-
This function repeatedly sends HTTP GET requests to a MATLAB proxy application to check the current
|
|
96
|
-
status of MATLAB. It continues checking until MATLAB's status matches the specified target status or
|
|
97
|
-
until a maximum timeout is reached.
|
|
98
|
-
|
|
99
|
-
Parameters:
|
|
100
|
-
- matlab_proxy_app_fixture: An object containing configuration for connecting to the MATLAB proxy application.
|
|
101
|
-
This object must have the following attributes:
|
|
102
|
-
- url (str): The base URL of the MATLAB proxy application.
|
|
103
|
-
- connection_scheme (str): The scheme used for the connection (e.g., 'http' or 'https').
|
|
104
|
-
- headers (dict): A dictionary of HTTP headers to be sent with each request.
|
|
105
|
-
- status (str): The target status to wait for MATLAB to reach.
|
|
106
|
-
|
|
107
|
-
Returns:
|
|
108
|
-
- str: The status of MATLAB at the end of the function execution. This could be the target status if
|
|
109
|
-
it was reached within the timeout period, or the last known status of MATLAB if the timeout was reached
|
|
110
|
-
first.
|
|
111
|
-
|
|
112
|
-
Notes:
|
|
113
|
-
- The function waits for a maximum of MAX_TIMEOUT seconds, defined elsewhere, before exiting.
|
|
114
|
-
- It checks the MATLAB status every 1 second.
|
|
115
|
-
- The MATLAB status is obtained by sending a GET request to the '/get_status' endpoint of the proxy application.
|
|
116
|
-
- The response from the proxy application is expected to be in JSON format, with MATLAB's status accessible
|
|
117
|
-
via `res["matlab"]["status"]`.
|
|
118
|
-
|
|
119
|
-
Exceptions:
|
|
120
|
-
- This function may raise exceptions related to network issues or JSON parsing errors, which are not
|
|
121
|
-
explicitly handled within the function.
|
|
122
|
-
"""
|
|
123
|
-
uri = matlab_proxy_app_fixture.url
|
|
124
|
-
connection_scheme = matlab_proxy_app_fixture.connection_scheme
|
|
125
|
-
headers = matlab_proxy_app_fixture.headers
|
|
126
|
-
|
|
127
|
-
matlab_status = None
|
|
128
|
-
|
|
129
|
-
start_time = time.time()
|
|
130
|
-
while matlab_status != status and (time.time() - start_time < MAX_TIMEOUT):
|
|
131
|
-
time.sleep(1)
|
|
132
|
-
res = _http_get_request(
|
|
133
|
-
uri,
|
|
134
|
-
connection_scheme,
|
|
135
|
-
headers,
|
|
136
|
-
http_endpoint="/get_status",
|
|
137
|
-
outputFormat=Format.JSON,
|
|
138
|
-
)
|
|
139
|
-
matlab_status = res["matlab"]["status"]
|
|
140
|
-
|
|
141
|
-
return matlab_status
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
def _download_test_file(matlab_proxy_app_fixture, test_file):
|
|
145
|
-
"""Returns result of hitting the /download endpoint for test_file.
|
|
146
|
-
|
|
147
|
-
Returns:
|
|
148
|
-
str: The contents of the test_file being downloaded through matlab-proxy.
|
|
149
|
-
"""
|
|
150
|
-
uri = matlab_proxy_app_fixture.url
|
|
151
|
-
connection_scheme = matlab_proxy_app_fixture.connection_scheme
|
|
152
|
-
headers = matlab_proxy_app_fixture.headers
|
|
153
|
-
|
|
154
|
-
res = _http_get_request(
|
|
155
|
-
uri,
|
|
156
|
-
connection_scheme,
|
|
157
|
-
headers,
|
|
158
|
-
http_endpoint="/download/" + test_file,
|
|
159
|
-
outputFormat=Format.TEXT,
|
|
160
|
-
)
|
|
161
|
-
return res
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
# Main Classes
|
|
165
|
-
class RealMATLABServer:
|
|
166
|
-
"""
|
|
167
|
-
Context Manager class which returns matlab proxy web server serving real MATLAB
|
|
168
|
-
for testing.
|
|
169
|
-
|
|
170
|
-
Setting up the server in the context of Pytest.
|
|
171
|
-
"""
|
|
172
|
-
|
|
173
|
-
def __init__(self, event_loop):
|
|
174
|
-
self.event_loop = event_loop
|
|
175
|
-
|
|
176
|
-
def __enter__(self):
|
|
177
|
-
# Store the matlab proxy logs in os.pipe for testing
|
|
178
|
-
# os.pipe2 is only supported in Linux systems
|
|
179
|
-
_logger.info("Setting up MATLAB Server for integration test")
|
|
180
|
-
|
|
181
|
-
_logger.debug("Entering RealMATLABServer enter section.")
|
|
182
|
-
self.dpipe = os.pipe2(os.O_NONBLOCK) if system.is_linux() else os.pipe()
|
|
183
|
-
self.mwi_app_port = utils.get_random_free_port()
|
|
184
|
-
self.matlab_config_file_path = str(utils.get_matlab_config_file())
|
|
185
|
-
|
|
186
|
-
self.temp_dir_path = os.path.dirname(
|
|
187
|
-
os.path.dirname(self.matlab_config_file_path)
|
|
188
|
-
)
|
|
189
|
-
|
|
190
|
-
self.temp_dir_name = "temp_dir"
|
|
191
|
-
self.mwi_base_url = "/matlab-test"
|
|
192
|
-
|
|
193
|
-
# Environment variables to launch matlab proxy
|
|
194
|
-
input_env = {
|
|
195
|
-
"MWI_APP_PORT": self.mwi_app_port,
|
|
196
|
-
"MWI_BASE_URL": self.mwi_base_url,
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
self.proc = self.event_loop.run_until_complete(
|
|
200
|
-
utils.start_matlab_proxy_app(out=self.dpipe[1], input_env=input_env)
|
|
201
|
-
)
|
|
202
|
-
|
|
203
|
-
utils.wait_server_info_ready(self.mwi_app_port)
|
|
204
|
-
parsed_url = urlparse(utils.get_connection_string(self.mwi_app_port))
|
|
205
|
-
|
|
206
|
-
self.headers = {
|
|
207
|
-
MWI_AUTH_TOKEN_NAME_FOR_HTTP: (
|
|
208
|
-
parse_qs(parsed_url.query)[MWI_AUTH_TOKEN_NAME_FOR_HTTP][0]
|
|
209
|
-
if MWI_AUTH_TOKEN_NAME_FOR_HTTP in parse_qs(parsed_url.query)
|
|
210
|
-
else ""
|
|
211
|
-
)
|
|
212
|
-
}
|
|
213
|
-
self.connection_scheme = parsed_url.scheme
|
|
214
|
-
self.url = parsed_url.scheme + "://" + parsed_url.netloc + parsed_url.path
|
|
215
|
-
return self
|
|
216
|
-
|
|
217
|
-
async def _terminate_process(self, timeout=0):
|
|
218
|
-
"""
|
|
219
|
-
Asynchronous helper method to terminate the process with a timeout.
|
|
220
|
-
|
|
221
|
-
Args:
|
|
222
|
-
timeout: Maximum number of seconds to wait
|
|
223
|
-
for the process to terminate
|
|
224
|
-
|
|
225
|
-
"""
|
|
226
|
-
import asyncio
|
|
227
|
-
|
|
228
|
-
process = self.proc
|
|
229
|
-
try:
|
|
230
|
-
process.terminate()
|
|
231
|
-
await asyncio.wait_for(process.wait(), timeout=timeout)
|
|
232
|
-
except asyncio.TimeoutError:
|
|
233
|
-
_logger.warning(
|
|
234
|
-
"Termination of the MATLAB Server process timed out. Attempting to kill."
|
|
235
|
-
)
|
|
236
|
-
process.kill()
|
|
237
|
-
await process.wait()
|
|
238
|
-
_logger.debug("Killed the MATLAB process after timeout.")
|
|
239
|
-
|
|
240
|
-
def __exit__(self, exc_type, exc_value, exc_traceback):
|
|
241
|
-
_logger.info("Tearing down the MATLAB Server.")
|
|
242
|
-
self.event_loop.run_until_complete(self._terminate_process(timeout=10))
|
|
243
|
-
_logger.debug("Terminated the MATLAB process.")
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
# Fixtures
|
|
247
|
-
@pytest.fixture
|
|
248
|
-
def matlab_proxy_app_fixture(
|
|
249
|
-
event_loop,
|
|
250
|
-
):
|
|
251
|
-
"""A pytest fixture which yields a real matlab server to be used by tests.
|
|
252
|
-
|
|
253
|
-
Args:
|
|
254
|
-
event_loop (Event loop): The built-in event loop provided by pytest.
|
|
255
|
-
|
|
256
|
-
Yields:
|
|
257
|
-
real_matlab_server : A real matlab web server used by tests.
|
|
258
|
-
"""
|
|
259
|
-
|
|
260
|
-
try:
|
|
261
|
-
with RealMATLABServer(event_loop) as matlab_proxy_app:
|
|
262
|
-
yield matlab_proxy_app
|
|
263
|
-
except ProcessLookupError as e:
|
|
264
|
-
_logger.debug("ProcessLookupError found in matlab proxy app fixture")
|
|
265
|
-
_logger.debug(e)
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
@pytest.fixture
|
|
269
|
-
def test_file_contents():
|
|
270
|
-
"""
|
|
271
|
-
A pytest fixture that provides a string for testing purposes.
|
|
272
|
-
|
|
273
|
-
This fixture returns a predefined string that can be used in tests to simulate
|
|
274
|
-
the contents of a file or any scenario where a constant string value is needed.
|
|
275
|
-
|
|
276
|
-
Returns:
|
|
277
|
-
str: A string containing the text "I LOVE MATLAB."
|
|
278
|
-
"""
|
|
279
|
-
return "I LOVE MATLAB."
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
@pytest.fixture
|
|
283
|
-
def test_file(tmp_path, test_file_contents):
|
|
284
|
-
"""
|
|
285
|
-
A pytest fixture that creates a temporary test file with given contents.
|
|
286
|
-
|
|
287
|
-
This fixture utilizes pytest's `tmp_path` fixture to generate a temporary directory,
|
|
288
|
-
then creates a file named "temporary_test_file.txt" within this directory,
|
|
289
|
-
and writes the provided contents to this file. It is useful for tests that require
|
|
290
|
-
reading from or writing to files without affecting the actual file system.
|
|
291
|
-
|
|
292
|
-
Parameters:
|
|
293
|
-
- tmp_path (Path): A pytest fixture that provides a temporary directory unique to the test function.
|
|
294
|
-
- test_file_contents (str): The content to be written into the temporary test file.
|
|
295
|
-
|
|
296
|
-
Returns:
|
|
297
|
-
- str: The path to the created temporary test file as a string.
|
|
298
|
-
"""
|
|
299
|
-
test_file = os.path.join(tmp_path, "temporary_test_file.txt")
|
|
300
|
-
with open(test_file, "w+") as f:
|
|
301
|
-
f.write(test_file_contents)
|
|
302
|
-
return test_file
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
# Test Functions
|
|
306
|
-
def test_matlab_is_up(matlab_proxy_app_fixture):
|
|
307
|
-
"""Test that the status switches from 'starting' to 'up' within a timeout.
|
|
308
|
-
|
|
309
|
-
Args:
|
|
310
|
-
matlab_proxy_app_fixture: A pytest fixture which yields a real matlab server to be used by tests.
|
|
311
|
-
"""
|
|
312
|
-
|
|
313
|
-
status = _check_matlab_status(matlab_proxy_app_fixture, "up")
|
|
314
|
-
assert status == "up"
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
def test_stop_matlab(matlab_proxy_app_fixture):
|
|
318
|
-
"""Test to check that matlab is in 'down' state when
|
|
319
|
-
we send the delete request to 'stop_matlab' endpoint
|
|
320
|
-
|
|
321
|
-
Args:
|
|
322
|
-
matlab_proxy_app_fixture: A pytest fixture which yields a real matlab server to be used by tests.
|
|
323
|
-
"""
|
|
324
|
-
status = _check_matlab_status(matlab_proxy_app_fixture, "up")
|
|
325
|
-
assert status == "up"
|
|
326
|
-
|
|
327
|
-
http_endpoint_to_test = "/stop_matlab"
|
|
328
|
-
stop_url = matlab_proxy_app_fixture.url + http_endpoint_to_test
|
|
329
|
-
|
|
330
|
-
with requests.Session() as s:
|
|
331
|
-
retries = Retry(total=10, backoff_factor=0.1)
|
|
332
|
-
s.mount(
|
|
333
|
-
f"{matlab_proxy_app_fixture.connection_scheme}://",
|
|
334
|
-
HTTPAdapter(max_retries=retries),
|
|
335
|
-
)
|
|
336
|
-
s.delete(stop_url, headers=matlab_proxy_app_fixture.headers, verify=False)
|
|
337
|
-
|
|
338
|
-
status = _check_matlab_status(matlab_proxy_app_fixture, "down")
|
|
339
|
-
assert status == "down"
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
async def test_print_message(matlab_proxy_app_fixture):
|
|
343
|
-
"""Test if the right logs are printed
|
|
344
|
-
|
|
345
|
-
Args:
|
|
346
|
-
matlab_proxy_app_fixture: A pytest fixture which yields a real matlab server to be used by tests.
|
|
347
|
-
|
|
348
|
-
FIXME: If output has logging or extra debug info, 600 bytes might not be enough.
|
|
349
|
-
"""
|
|
350
|
-
# Checks if matlab proxy is in "up" state or not
|
|
351
|
-
status = _check_matlab_status(matlab_proxy_app_fixture, "up")
|
|
352
|
-
assert status == "up"
|
|
353
|
-
|
|
354
|
-
uri_regex = f"{matlab_proxy_app_fixture.connection_scheme}://[a-zA-Z0-9\-_.]+:{matlab_proxy_app_fixture.mwi_app_port}{matlab_proxy_app_fixture.mwi_base_url}"
|
|
355
|
-
|
|
356
|
-
read_descriptor, write_descriptor = matlab_proxy_app_fixture.dpipe
|
|
357
|
-
number_of_bytes = 600
|
|
358
|
-
|
|
359
|
-
if read_descriptor:
|
|
360
|
-
line = os.read(read_descriptor, number_of_bytes).decode("utf-8")
|
|
361
|
-
process_logs = line.strip()
|
|
362
|
-
|
|
363
|
-
assert bool(re.search(uri_regex, process_logs)) == True
|
|
364
|
-
|
|
365
|
-
# Close the read and write descriptors.
|
|
366
|
-
os.close(read_descriptor)
|
|
367
|
-
os.close(write_descriptor)
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
def test_download_file_from_matlab(
|
|
371
|
-
matlab_proxy_app_fixture, test_file, test_file_contents
|
|
372
|
-
):
|
|
373
|
-
"""
|
|
374
|
-
Test the downloading of a file from a MATLAB proxy application.
|
|
375
|
-
|
|
376
|
-
This test function checks if the MATLAB proxy application is up and running, and then attempts to download
|
|
377
|
-
a specific test file from it. It validates both the status of the MATLAB proxy and the contents of the downloaded file.
|
|
378
|
-
|
|
379
|
-
Parameters:
|
|
380
|
-
- matlab_proxy_app_fixture (fixture): A test fixture representing the MATLAB proxy application environment.
|
|
381
|
-
- test_file (str): The name or path of the test file to be downloaded from the MATLAB proxy application.
|
|
382
|
-
- test_file_contents (str): The expected contents of the test file to validate the download operation.
|
|
383
|
-
|
|
384
|
-
Assertions:
|
|
385
|
-
- Asserts that the MATLAB proxy application is "up".
|
|
386
|
-
- Asserts that the content of the downloaded file matches the expected `test_file_contents`.
|
|
387
|
-
|
|
388
|
-
Raises:
|
|
389
|
-
- AssertionError: If any of the assertions fail, indicating either the MATLAB proxy application is not running
|
|
390
|
-
as expected or there is a mismatch in the file content.
|
|
391
|
-
"""
|
|
392
|
-
status = _check_matlab_status(matlab_proxy_app_fixture, "up")
|
|
393
|
-
assert status == "up"
|
|
394
|
-
|
|
395
|
-
# Once MATLAB is up, we can then attempt to download
|
|
396
|
-
result = _download_test_file(matlab_proxy_app_fixture, test_file)
|
|
397
|
-
assert result == test_file_contents
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
# Copyright 2023 The MathWorks, Inc.
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
# Copyright 2023-2024 The MathWorks, Inc.
|
|
2
|
-
|
|
3
|
-
import pytest
|
|
4
|
-
from tests.integration.utils import integration_tests_utils as utils
|
|
5
|
-
import requests
|
|
6
|
-
from tests.utils.logging_util import create_integ_test_logger
|
|
7
|
-
import os
|
|
8
|
-
from urllib.parse import urlparse, parse_qs
|
|
9
|
-
from matlab_proxy.constants import MWI_AUTH_TOKEN_NAME_FOR_HTTP
|
|
10
|
-
|
|
11
|
-
_logger = create_integ_test_logger(__name__)
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
@pytest.fixture(scope="module", name="module_monkeypatch")
|
|
15
|
-
def monkeypatch_module_scope_fixture():
|
|
16
|
-
"""
|
|
17
|
-
Pytest fixture for creating a monkeypatch object in 'module' scope.
|
|
18
|
-
The default monkeypatch fixture returns monkeypatch object in
|
|
19
|
-
'function' scope but a 'module' scope object is needed with matlab-proxy
|
|
20
|
-
'module' scope fixture.
|
|
21
|
-
|
|
22
|
-
Yields:
|
|
23
|
-
class object: Object of class MonkeyPatch
|
|
24
|
-
"""
|
|
25
|
-
with pytest.MonkeyPatch.context() as mp:
|
|
26
|
-
yield mp
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
@pytest.fixture
|
|
30
|
-
def parse_matlab_proxy_url():
|
|
31
|
-
# Get the base URL from a utility function or environment variable
|
|
32
|
-
mwi_app_port = os.environ["MWI_APP_PORT"]
|
|
33
|
-
|
|
34
|
-
# Construct the parameters dictionary
|
|
35
|
-
parsed_url = urlparse(utils.get_connection_string(mwi_app_port))
|
|
36
|
-
|
|
37
|
-
headers = {
|
|
38
|
-
MWI_AUTH_TOKEN_NAME_FOR_HTTP: (
|
|
39
|
-
parse_qs(parsed_url.query)[MWI_AUTH_TOKEN_NAME_FOR_HTTP][0]
|
|
40
|
-
if MWI_AUTH_TOKEN_NAME_FOR_HTTP in parse_qs(parsed_url.query)
|
|
41
|
-
else ""
|
|
42
|
-
)
|
|
43
|
-
}
|
|
44
|
-
connection_scheme = parsed_url.scheme
|
|
45
|
-
|
|
46
|
-
# Return the base URL and parameters as a tuple
|
|
47
|
-
return parsed_url, headers, connection_scheme
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
@pytest.fixture(scope="module", autouse=True)
|
|
51
|
-
def start_matlab_proxy_fixture(module_monkeypatch):
|
|
52
|
-
"""Starts the matlab proxy process"""
|
|
53
|
-
utils.perform_basic_checks()
|
|
54
|
-
|
|
55
|
-
# Start matlab-proxy-app for testing
|
|
56
|
-
|
|
57
|
-
mwi_app_port = utils.get_random_free_port()
|
|
58
|
-
mwi_base_url = "/matlab-test"
|
|
59
|
-
|
|
60
|
-
input_env = {
|
|
61
|
-
"MWI_APP_PORT": mwi_app_port,
|
|
62
|
-
"MWI_BASE_URL": mwi_base_url,
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
import shutil
|
|
66
|
-
import matlab_proxy
|
|
67
|
-
|
|
68
|
-
matlab_config_file = str(
|
|
69
|
-
utils.get_matlab_config_file()
|
|
70
|
-
) # ~/.matlab/MWI/hosts/hostname/proxy_app_config.json
|
|
71
|
-
|
|
72
|
-
_logger.info(f"matlab_config_file {matlab_config_file}")
|
|
73
|
-
|
|
74
|
-
dotmatlab_dir_path = os.path.dirname(os.path.dirname(matlab_config_file))
|
|
75
|
-
|
|
76
|
-
# Create a temporary location in .matlab directory
|
|
77
|
-
temp_dir_path = os.path.join(dotmatlab_dir_path, "temp_dir")
|
|
78
|
-
os.mkdir(temp_dir_path) # delete this folder after the test execution
|
|
79
|
-
shutil.move(matlab_config_file, temp_dir_path)
|
|
80
|
-
|
|
81
|
-
loop = matlab_proxy.util.get_event_loop()
|
|
82
|
-
|
|
83
|
-
# Run matlab-proxy in the background in an event loop
|
|
84
|
-
proc = loop.run_until_complete(utils.start_matlab_proxy_app(input_env=input_env))
|
|
85
|
-
_logger.info("Started MATLAB Proxy process")
|
|
86
|
-
|
|
87
|
-
# Wait for mwi_server.info file to be ready
|
|
88
|
-
utils.wait_server_info_ready(mwi_app_port)
|
|
89
|
-
|
|
90
|
-
# Get the scheme on which MATLAB Proxy connection string
|
|
91
|
-
matlab_proxy_url = utils.get_connection_string(mwi_app_port)
|
|
92
|
-
|
|
93
|
-
utils.poll_web_service(
|
|
94
|
-
matlab_proxy_url,
|
|
95
|
-
step=5,
|
|
96
|
-
timeout=120,
|
|
97
|
-
ignore_exceptions=(
|
|
98
|
-
requests.exceptions.ConnectionError,
|
|
99
|
-
requests.exceptions.SSLError,
|
|
100
|
-
),
|
|
101
|
-
)
|
|
102
|
-
|
|
103
|
-
for key, value in input_env.items():
|
|
104
|
-
module_monkeypatch.setenv(key, value)
|
|
105
|
-
|
|
106
|
-
yield
|
|
107
|
-
from pathlib import Path
|
|
108
|
-
|
|
109
|
-
shutil.move(
|
|
110
|
-
str(temp_dir_path / Path("proxy_app_config.json")),
|
|
111
|
-
str(os.path.dirname(matlab_config_file)),
|
|
112
|
-
)
|
|
113
|
-
shutil.rmtree(temp_dir_path)
|
|
114
|
-
|
|
115
|
-
proc.terminate()
|
|
116
|
-
loop.run_until_complete(proc.wait())
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
# Copyright 2023-2024 The MathWorks, Inc.
|
|
2
|
-
|
|
3
|
-
import os
|
|
4
|
-
import json
|
|
5
|
-
import requests
|
|
6
|
-
from requests.adapters import HTTPAdapter, Retry
|
|
7
|
-
from tests.integration.utils import integration_tests_utils as utils
|
|
8
|
-
from urllib.parse import urlparse
|
|
9
|
-
from tests.utils.logging_util import create_integ_test_logger
|
|
10
|
-
|
|
11
|
-
_logger = create_integ_test_logger(log_name=__name__)
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
def test_matlab_down(parse_matlab_proxy_url):
|
|
15
|
-
"""Test that matlab is down and no license is picked up"""
|
|
16
|
-
|
|
17
|
-
parsed_url, headers, connection_scheme = parse_matlab_proxy_url
|
|
18
|
-
http_endpoint = "/get_status"
|
|
19
|
-
uri = (
|
|
20
|
-
connection_scheme + "://" + parsed_url.netloc + parsed_url.path + http_endpoint
|
|
21
|
-
)
|
|
22
|
-
|
|
23
|
-
json_response = None
|
|
24
|
-
|
|
25
|
-
with requests.Session() as s:
|
|
26
|
-
retries = Retry(total=10, backoff_factor=0.1)
|
|
27
|
-
s.mount(f"{connection_scheme}://", HTTPAdapter(max_retries=retries))
|
|
28
|
-
response = s.get(uri, headers=headers, verify=False)
|
|
29
|
-
json_response = json.loads(response.text)
|
|
30
|
-
|
|
31
|
-
matlab_status = json_response["matlab"]["status"]
|
|
32
|
-
assert matlab_status == "down"
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
def test_matlab_proxy_app_installed():
|
|
36
|
-
import shutil
|
|
37
|
-
|
|
38
|
-
"""Test that the executable matlab_proxy_app is located on PATH and executable"""
|
|
39
|
-
|
|
40
|
-
which_matlabproxyapp = shutil.which("matlab-proxy-app")
|
|
41
|
-
assert (
|
|
42
|
-
which_matlabproxyapp is not None
|
|
43
|
-
), "matlab-proxy-app does not exist in system path"
|
|
44
|
-
assert (
|
|
45
|
-
os.access(which_matlabproxyapp, os.R_OK) == True
|
|
46
|
-
), """matlab-proxy-app does not have the read permissions"""
|
|
47
|
-
assert (
|
|
48
|
-
os.access(which_matlabproxyapp, os.X_OK) == True
|
|
49
|
-
), """matlab-proxy-app does not have the execute permissions"""
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
# Copyright 2023-2024 The MathWorks, Inc.
|