Skip to content

Commit 020733f

Browse files
committed
Adjust testing-farm token based on chroot when watching a request
1 parent 39e309c commit 020733f

File tree

1 file changed

+29
-15
lines changed

1 file changed

+29
-15
lines changed

snapshot_manager/snapshot_manager/testing_farm_util.py

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,32 @@ def parse(cls, string: str) -> dict[str, "TestingFarmRequest"]:
145145
logging.info(f"Recovered testing-farm-requests: {res}")
146146
return res
147147

148+
@classmethod
149+
def adjust_env(cls, chroot: str) -> None:
150+
"""Adjusts the TESTING_FARM_API_TOKEN env var based on the chroot.
151+
The next testing-farm command is then set up to work with the correct
152+
ranch.
153+
154+
Raises:
155+
ValueError: if the chroot is not supported by the ranch
156+
"""
157+
ranch = cls.select_ranch(chroot)
158+
159+
if not cls.is_chroot_supported(chroot=chroot, ranch=ranch):
160+
raise ValueError(
161+
f"Chroot {chroot} has an unsupported architecture on ranch {ranch}"
162+
)
163+
164+
logging.info(f"Adjusting TESTING_FARM_API_TOKEN for ranch: {ranch}")
165+
if ranch == "public":
166+
os.environ["TESTING_FARM_API_TOKEN"] = os.getenv(
167+
"TESTING_FARM_API_TOKEN_PUBLIC_RANCH", "MISSING_ENV_FOR_PUBLIC_RANCH"
168+
)
169+
if ranch == "redhat":
170+
os.environ["TESTING_FARM_API_TOKEN"] = os.getenv(
171+
"TESTING_FARM_API_TOKEN_REDHAT_RANCH", "MISSING_ENV_FOR_REDHAT_RANCH"
172+
)
173+
148174
@classmethod
149175
def make(
150176
cls,
@@ -177,22 +203,8 @@ def make(
177203
"""
178204
logging.info(f"Kicking off new tests for chroot {chroot}.")
179205

180-
ranch = cls.select_ranch(chroot)
181-
182-
if not cls.is_chroot_supported(chroot=chroot, ranch=ranch):
183-
raise ValueError(
184-
f"Chroot {chroot} has an unsupported architecture on ranch {ranch}"
185-
)
206+
cls.adjust_env(chroot)
186207

187-
logging.info(f"Using testing-farm ranch: {ranch}")
188-
if ranch == "public":
189-
os.environ["TESTING_FARM_API_TOKEN"] = os.getenv(
190-
"TESTING_FARM_API_TOKEN_PUBLIC_RANCH", "MISSING_ENV"
191-
)
192-
if ranch == "redhat":
193-
os.environ["TESTING_FARM_API_TOKEN"] = os.getenv(
194-
"TESTING_FARM_API_TOKEN_REDHAT_RANCH", "MISSING_ENV"
195-
)
196208
cmd = f"""testing-farm \
197209
request \
198210
--compose {cls.get_compose(chroot=chroot)} \
@@ -220,6 +232,8 @@ def make(
220232
)
221233

222234
def watch(self) -> tuple["TestingFarmWatchResult", str]:
235+
self.adjust_env(self.chroot)
236+
223237
request_id = sanitize_request_id(request_id=self.request_id)
224238
cmd = f"testing-farm watch --no-wait --id {self.request_id}"
225239
# We ignore the exit code because in case of a test error, 1 is the exit code

0 commit comments

Comments
 (0)