@@ -145,6 +145,32 @@ def parse(cls, string: str) -> dict[str, "TestingFarmRequest"]:
145
145
logging .info (f"Recovered testing-farm-requests: { res } " )
146
146
return res
147
147
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
+
148
174
@classmethod
149
175
def make (
150
176
cls ,
@@ -177,22 +203,8 @@ def make(
177
203
"""
178
204
logging .info (f"Kicking off new tests for chroot { chroot } ." )
179
205
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 )
186
207
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
- )
196
208
cmd = f"""testing-farm \
197
209
request \
198
210
--compose { cls .get_compose (chroot = chroot )} \
@@ -220,6 +232,8 @@ def make(
220
232
)
221
233
222
234
def watch (self ) -> tuple ["TestingFarmWatchResult" , str ]:
235
+ self .adjust_env (self .chroot )
236
+
223
237
request_id = sanitize_request_id (request_id = self .request_id )
224
238
cmd = f"testing-farm watch --no-wait --id { self .request_id } "
225
239
# We ignore the exit code because in case of a test error, 1 is the exit code
0 commit comments