Skip to content

Commit ca7c49e

Browse files
authored
Implement a fallback IP mechanism in topology JSON (#196)
This way if for some reason the IP auto detection doesn't work locally a quick way to resolve it is present. This should NOT be used for a permanent solution on Jenkins infrastructure, though.
1 parent 23c7b6d commit ca7c49e

8 files changed

Lines changed: 55 additions & 11 deletions

File tree

environment/aws/topology_setup/setup_topology.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,19 +336,26 @@ def platform(self) -> str:
336336
def download(self) -> bool:
337337
return self.__download
338338

339+
@property
340+
def ip_hint(self) -> str | None:
341+
return self.__ip_hint
342+
339343
def __init__(
340344
self,
341345
location: str,
342346
cbl_version: str,
343347
dataset_version: str,
344348
platform: str,
345349
download: bool,
350+
*,
351+
ip_hint: str | None = None,
346352
):
347353
self.__location = location
348354
self.__cbl_version = cbl_version
349355
self.__dataset_version = dataset_version
350356
self.__platform = platform
351357
self.__download = download
358+
self.__ip_hint = ip_hint
352359

353360

354361
class TestServerConfig:
@@ -476,6 +483,7 @@ def __init__(
476483
raw_server["dataset_version"],
477484
raw_server["platform"],
478485
cast(bool, raw_server.get("download", False)),
486+
ip_hint=raw_server.get("ip_hint"),
479487
)
480488
)
481489

@@ -648,7 +656,9 @@ def resolve_test_servers(self):
648656
bridge.validate(test_server_input.location)
649657
self.__test_servers.append(
650658
TestServerConfig(
651-
bridge.get_ip(test_server_input.location),
659+
bridge.get_ip(
660+
test_server_input.location, fallback=test_server_input.ip_hint
661+
),
652662
test_server_input.cbl_version,
653663
test_server_input.dataset_version,
654664
test_server_input.platform,
@@ -674,7 +684,9 @@ def run_test_servers(self):
674684
bridge.install(test_server_input.location)
675685
bridge.run(test_server_input.location)
676686
port = 5555 if test_server_input.platform.startswith("dotnet") else 8080
677-
ip = bridge.get_ip(test_server_input.location)
687+
ip = bridge.get_ip(
688+
test_server_input.location, fallback=test_server_input.ip_hint
689+
)
678690

679691
success = False
680692
for _ in range(0, 30):

environment/aws/topology_setup/test_server_platforms/android_bridge.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def uninstall(self, location: str) -> None:
176176
capture_output=False,
177177
)
178178

179-
def get_ip(self, location: str) -> str:
179+
def _get_ip(self, location: str) -> str | None:
180180
"""
181181
Retrieve the IP address of the specified device.
182182
@@ -211,4 +211,4 @@ def get_ip(self, location: str) -> str:
211211
if "inet" in line:
212212
return line.lstrip().split(" ")[1].split("/")[0]
213213

214-
raise RuntimeError(f"Could not determine IP address of '{location}'")
214+
return None

environment/aws/topology_setup/test_server_platforms/exe_bridge.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def uninstall(self, location: str) -> None:
136136
"""
137137
click.echo("No action needed for uninstalling executable")
138138

139-
def get_ip(self, location: str) -> str:
139+
def _get_ip(self, location: str) -> str | None:
140140
"""
141141
Retrieve the IP address of the specified location.
142142

environment/aws/topology_setup/test_server_platforms/ios_bridge.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ def __broadcast_ping_request(self) -> None:
374374
fg="yellow",
375375
)
376376

377-
def get_ip(self, location: str) -> str:
377+
def _get_ip(self, location: str) -> str | None:
378378
"""
379379
Retrieve the IP address of the specified device.
380380
@@ -414,4 +414,4 @@ def get_ip(self, location: str) -> str:
414414
if mac_address in line:
415415
return line.split(" ")[1].strip("()")
416416

417-
raise RuntimeError(f"Could not determine IP address of '{location}'")
417+
return None

environment/aws/topology_setup/test_server_platforms/java_register.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def install(self, location: str) -> None:
119119
def uninstall(self, location: str) -> None:
120120
pass
121121

122-
def get_ip(self, location):
122+
def _get_ip(self, location) -> str | None:
123123
if location != "localhost":
124124
raise ValueError("JarBridge only supports running on localhost")
125125

@@ -179,7 +179,7 @@ def install(self, location: str) -> None:
179179
def uninstall(self, location: str) -> None:
180180
pass
181181

182-
def get_ip(self, location):
182+
def _get_ip(self, location) -> str | None:
183183
if location != "localhost":
184184
raise ValueError("JettyBridge only supports running on localhost")
185185

environment/aws/topology_setup/test_server_platforms/macos_bridge.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def uninstall(self, location: str) -> None:
107107
self.validate(location)
108108
click.echo("No action needed for uninstalling macOS app")
109109

110-
def get_ip(self, location: str) -> str:
110+
def _get_ip(self, location: str) -> str | None:
111111
"""
112112
Retrieve the IP address of the specified location.
113113

environment/aws/topology_setup/test_server_platforms/platform_bridge.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727

2828
from abc import ABC, abstractmethod
2929

30+
import click
31+
3032

3133
class PlatformBridge(ABC):
3234
"""
@@ -102,8 +104,34 @@ def uninstall(self, location: str) -> None:
102104
"""
103105
pass
104106

107+
def get_ip(self, location: str, *, fallback: str | None = None) -> str:
108+
"""
109+
Retrieve the IP address of the specified location.
110+
111+
Args:
112+
location (str): The location of the application (e.g., device serial number).
113+
fallback (str | None): An optional fallback IP address if the retrieval fails.
114+
115+
Returns:
116+
str: The IP address of the location, or the fallback if specified.
117+
"""
118+
attempt = self._get_ip(location)
119+
if attempt is not None:
120+
return attempt
121+
122+
if fallback is not None:
123+
click.secho(
124+
f"Failed to retrieve IP address for {location}, using fallback: {fallback}.",
125+
fg="yellow",
126+
)
127+
return fallback
128+
129+
raise RuntimeError(
130+
f"Failed to retrieve IP address for {location} and no fallback provided."
131+
)
132+
105133
@abstractmethod
106-
def get_ip(self, location: str) -> str:
134+
def _get_ip(self, location: str) -> str | None:
107135
"""
108136
Retrieve the IP address of the specified location.
109137

environment/aws/topology_setup/topology_schema.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@
115115
"download": {
116116
"type": "boolean",
117117
"default": false
118+
},
119+
"ip_hint": {
120+
"type": "string",
121+
"default": ""
118122
}
119123
},
120124
"required": ["location", "cbl_version", "platform", "dataset_version"],

0 commit comments

Comments
 (0)