Skip to content

Commit 32bd3ef

Browse files
committed
add updated logic to resolve assets.json and pass along to record|playback/start
1 parent 8358af6 commit 32bd3ef

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ build/
3434
# Test results
3535
TestResults/
3636
ENV_DIR/
37+
.assets/
3738

3839
# Perf test profiling
3940
cProfile-*.pstats

tools/azure-sdk-tools/devtools_testutils/proxy_startup.py

+8
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
PROXY_CHECK_URL = PROXY_URL.rstrip("/") + "/Info/Available"
3232
TOOL_ENV_VAR = "PROXY_PID"
3333

34+
discovered_roots = []
3435

3536
def get_image_tag(repo_root: str) -> str:
3637
"""Gets the test proxy Docker image tag from the target_version.txt file in /eng/common/testproxy"""
@@ -59,6 +60,8 @@ def ascend_to_root(start_dir_or_file: str) -> str:
5960

6061
# we need the git check to prevent ascending out of the repo
6162
if os.path.exists(possible_root):
63+
if current_dir not in discovered_roots:
64+
discovered_roots.append(current_dir)
6265
return current_dir
6366
else:
6467
current_dir = os.path.dirname(current_dir)
@@ -137,13 +140,18 @@ def start_test_proxy(request) -> None:
137140
else:
138141
envname = os.getenv("TOX_ENV_NAME", "default")
139142
root = os.getenv("BUILD_SOURCESDIRECTORY", repo_root)
143+
144+
145+
140146
log = open(os.path.join(root, "_proxy_log_{}.log".format(envname)), "a")
147+
env = {}
141148

142149
_LOGGER.info("{} is calculated repo root".format(root))
143150
proc = subprocess.Popen(
144151
shlex.split('test-proxy start --storage-location="{}" -- --urls "{}"'.format(root, PROXY_URL)),
145152
stdout=log,
146153
stderr=log,
154+
env = {}
147155
)
148156
os.environ[TOOL_ENV_VAR] = str(proc.pid)
149157
else:

tools/azure-sdk-tools/devtools_testutils/proxy_testcase.py

+29-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import logging
77
import requests
88
import six
9+
import os
910
from typing import TYPE_CHECKING
1011
import urllib.parse as url_parse
1112

@@ -19,6 +20,7 @@
1920
from azure_devtools.scenario_tests.utilities import trim_kwargs_from_test_function
2021
from .config import PROXY_URL
2122
from .helpers import get_test_id, is_live, is_live_and_not_recording, set_recording_id
23+
from .proxy_startup import discovered_roots
2224

2325
if TYPE_CHECKING:
2426
from typing import Callable, Dict, Tuple
@@ -34,6 +36,26 @@
3436
PLAYBACK_START_URL = "{}/playback/start".format(PROXY_URL)
3537
PLAYBACK_STOP_URL = "{}/playback/stop".format(PROXY_URL)
3638

39+
def get_recording_assets(test_id: str) -> str:
40+
"""
41+
Used to retrieve the assets.json given a PYTEST_CURRENT_TEST test id.
42+
"""
43+
for root in discovered_roots:
44+
current_dir = os.path.dirname(test_id)
45+
while current_dir is not None and not (os.path.dirname(current_dir) == current_dir):
46+
possible_assets = os.path.join(current_dir, "assets.json")
47+
possible_root = os.path.join(current_dir, ".git")
48+
49+
# we need to check for assets.json first!
50+
if os.path.exists(os.path.join(root, possible_assets)):
51+
return os.path.abspath(os.path.join(root, possible_assets))
52+
# we need the git check to prevent ascending out of the repo
53+
elif os.path.exists(os.path.join(root, possible_root)):
54+
return None
55+
else:
56+
current_dir = os.path.dirname(current_dir)
57+
58+
return None
3759

3860
def start_record_or_playback(test_id: str) -> "Tuple[str, Dict[str, str]]":
3961
"""Sends a request to begin recording or playing back the provided test.
@@ -42,11 +64,16 @@ def start_record_or_playback(test_id: str) -> "Tuple[str, Dict[str, str]]":
4264
test variables to values. If no variable dictionary was stored when the test was recorded, b is an empty dictionary.
4365
"""
4466
variables = {} # this stores a dictionary of test variable values that could have been stored with a recording
67+
68+
json_payload = {"x-recording-file": test_id}
69+
assets_json = get_recording_assets(test_id)
70+
if assets_json:
71+
json_payload["x-recording-assets-file"] = assets_json
4572

4673
if is_live():
4774
result = requests.post(
4875
RECORDING_START_URL,
49-
json={"x-recording-file": test_id},
76+
json=json_payload,
5077
)
5178
if result.status_code != 200:
5279
message = six.ensure_str(result._content)
@@ -56,7 +83,7 @@ def start_record_or_playback(test_id: str) -> "Tuple[str, Dict[str, str]]":
5683
else:
5784
result = requests.post(
5885
PLAYBACK_START_URL,
59-
json={"x-recording-file": test_id},
86+
json=json_payload,
6087
)
6188
if result.status_code != 200:
6289
message = six.ensure_str(result._content)

0 commit comments

Comments
 (0)