|
20 | 20 | JobType,
|
21 | 21 | PackageConfig,
|
22 | 22 | )
|
| 23 | +from packit.config.requirements import RequirementsConfig, LabelRequirementsConfig |
23 | 24 | from packit.copr_helper import CoprHelper
|
24 | 25 | from packit.local_project import LocalProject
|
25 | 26 | from packit_service.config import PackageConfigGetter, ServiceConfig
|
@@ -1151,6 +1152,282 @@ def test_copr_build_end_testing_farm_manual_trigger(copr_build_end, copr_build_p
|
1151 | 1152 | )
|
1152 | 1153 |
|
1153 | 1154 |
|
| 1155 | +def test_copr_build_end_testing_farm_labels_matching(copr_build_end, copr_build_pr): |
| 1156 | + ServiceConfig.get_service_config().testing_farm_api_url = ( |
| 1157 | + "https://api.dev.testing-farm.io/v0.1/" |
| 1158 | + ) |
| 1159 | + ServiceConfig.get_service_config().testing_farm_secret = "secret token" |
| 1160 | + |
| 1161 | + flexmock(GithubProject).should_receive("is_private").and_return(False) |
| 1162 | + flexmock(GithubProject).should_receive("get_pr").and_return( |
| 1163 | + flexmock( |
| 1164 | + source_project=flexmock( |
| 1165 | + get_web_url=lambda: "https://github.com/source/bar" |
| 1166 | + ), |
| 1167 | + target_project=flexmock( |
| 1168 | + get_web_url=lambda: "https://github.com/target/bar" |
| 1169 | + ), |
| 1170 | + head_commit="0011223344", |
| 1171 | + target_branch_head_commit="deadbeef", |
| 1172 | + source_branch="the-source-branch", |
| 1173 | + target_branch="the-target-branch", |
| 1174 | + id=123, |
| 1175 | + labels=[flexmock(name="a-label")], |
| 1176 | + ) |
| 1177 | + .should_receive("comment") |
| 1178 | + .mock() |
| 1179 | + ) |
| 1180 | + urls.DASHBOARD_URL = "https://dashboard.localhost" |
| 1181 | + |
| 1182 | + config = PackageConfig( |
| 1183 | + packages={ |
| 1184 | + "package": CommonPackageConfig( |
| 1185 | + specfile_path="test.spec", |
| 1186 | + ) |
| 1187 | + }, |
| 1188 | + jobs=[ |
| 1189 | + JobConfig( |
| 1190 | + type=JobType.copr_build, |
| 1191 | + trigger=JobConfigTriggerType.pull_request, |
| 1192 | + packages={ |
| 1193 | + "package": CommonPackageConfig( |
| 1194 | + _targets=["fedora-rawhide"], |
| 1195 | + specfile_path="test.spec", |
| 1196 | + ) |
| 1197 | + }, |
| 1198 | + ), |
| 1199 | + JobConfig( |
| 1200 | + type=JobType.tests, |
| 1201 | + trigger=JobConfigTriggerType.pull_request, |
| 1202 | + packages={ |
| 1203 | + "package": CommonPackageConfig( |
| 1204 | + _targets=["fedora-rawhide"], |
| 1205 | + specfile_path="test.spec", |
| 1206 | + require=RequirementsConfig( |
| 1207 | + label=LabelRequirementsConfig(present=["a-label"]) |
| 1208 | + ), |
| 1209 | + ) |
| 1210 | + }, |
| 1211 | + ), |
| 1212 | + ], |
| 1213 | + ) |
| 1214 | + |
| 1215 | + flexmock(AbstractCoprBuildEvent).should_receive("get_packages_config").and_return( |
| 1216 | + config |
| 1217 | + ) |
| 1218 | + flexmock(CoprHelper).should_receive("get_copr_client").and_return( |
| 1219 | + Client(config={"username": "packit", "copr_url": "https://dummy.url"}) |
| 1220 | + ) |
| 1221 | + flexmock(PackageConfigGetter).should_receive( |
| 1222 | + "get_package_config_from_repo" |
| 1223 | + ).and_return(config) |
| 1224 | + |
| 1225 | + flexmock(LocalProject).should_receive("refresh_the_arguments").and_return(None) |
| 1226 | + |
| 1227 | + flexmock(CoprBuildTargetModel).should_receive("get_by_build_id").and_return( |
| 1228 | + copr_build_pr |
| 1229 | + ) |
| 1230 | + flexmock(CoprBuildTargetModel).should_receive("get_by_id").and_return(copr_build_pr) |
| 1231 | + copr_build_pr.should_call("set_status").with_args(BuildStatus.success).once() |
| 1232 | + copr_build_pr.should_receive("set_end_time").once() |
| 1233 | + copr_build_pr.should_receive("get_package_name").and_return(None) |
| 1234 | + flexmock(requests).should_receive("get").and_return(requests.Response()) |
| 1235 | + flexmock(requests.Response).should_receive("raise_for_status").and_return(None) |
| 1236 | + # check if packit-service set correct PR status |
| 1237 | + url = get_copr_build_info_url(1) |
| 1238 | + flexmock(StatusReporter).should_receive("report").with_args( |
| 1239 | + state=BaseCommitStatus.success, |
| 1240 | + description="RPMs were built successfully.", |
| 1241 | + url=url, |
| 1242 | + check_names=EXPECTED_BUILD_CHECK_NAME, |
| 1243 | + markdown_content=None, |
| 1244 | + links_to_external_services=None, |
| 1245 | + update_feedback_time=object, |
| 1246 | + ).once() |
| 1247 | + |
| 1248 | + flexmock(StatusReporter).should_receive("report").with_args( |
| 1249 | + state=BaseCommitStatus.pending, |
| 1250 | + description="RPMs were built successfully.", |
| 1251 | + url=url, |
| 1252 | + check_names=EXPECTED_TESTING_FARM_CHECK_NAME, |
| 1253 | + markdown_content=None, |
| 1254 | + links_to_external_services=None, |
| 1255 | + update_feedback_time=object, |
| 1256 | + ).once() |
| 1257 | + |
| 1258 | + flexmock(GithubProject).should_receive("get_web_url").and_return( |
| 1259 | + "https://github.com/foo/bar" |
| 1260 | + ) |
| 1261 | + |
| 1262 | + flexmock(Signature).should_receive("apply_async").twice() |
| 1263 | + |
| 1264 | + # skip SRPM url since it touches multiple classes |
| 1265 | + flexmock(CoprBuildEndHandler).should_receive("set_srpm_url").and_return(None) |
| 1266 | + |
| 1267 | + ( |
| 1268 | + flexmock(CoprBuildJobHelper) |
| 1269 | + .should_receive("get_build_chroot") |
| 1270 | + .with_args(1, "some-target") |
| 1271 | + .and_return(flexmock(ended_on=1666889710)) |
| 1272 | + .at_least() |
| 1273 | + .once() |
| 1274 | + ) |
| 1275 | + |
| 1276 | + flexmock(Pushgateway).should_receive("push").times(2).and_return() |
| 1277 | + |
| 1278 | + processing_results = SteveJobs().process_message(copr_build_end) |
| 1279 | + event_dict, job, job_config, package_config = get_parameters_from_results( |
| 1280 | + processing_results |
| 1281 | + ) |
| 1282 | + assert json.dumps(event_dict) |
| 1283 | + |
| 1284 | + flexmock(CoprBuildJobHelper).should_receive("get_built_packages").and_return([]) |
| 1285 | + |
| 1286 | + run_copr_build_end_handler( |
| 1287 | + package_config=package_config, |
| 1288 | + event=event_dict, |
| 1289 | + job_config=job_config, |
| 1290 | + ) |
| 1291 | + |
| 1292 | + |
| 1293 | +def test_copr_build_end_testing_farm_labels_not_matching(copr_build_end, copr_build_pr): |
| 1294 | + ServiceConfig.get_service_config().testing_farm_api_url = ( |
| 1295 | + "https://api.dev.testing-farm.io/v0.1/" |
| 1296 | + ) |
| 1297 | + ServiceConfig.get_service_config().testing_farm_secret = "secret token" |
| 1298 | + |
| 1299 | + flexmock(GithubProject).should_receive("is_private").and_return(False) |
| 1300 | + flexmock(GithubProject).should_receive("get_pr").and_return( |
| 1301 | + flexmock( |
| 1302 | + source_project=flexmock( |
| 1303 | + get_web_url=lambda: "https://github.com/source/bar" |
| 1304 | + ), |
| 1305 | + target_project=flexmock( |
| 1306 | + get_web_url=lambda: "https://github.com/target/bar" |
| 1307 | + ), |
| 1308 | + head_commit="0011223344", |
| 1309 | + target_branch_head_commit="deadbeef", |
| 1310 | + source_branch="the-source-branch", |
| 1311 | + target_branch="the-target-branch", |
| 1312 | + id=123, |
| 1313 | + labels=[flexmock(name="another-label")], |
| 1314 | + ) |
| 1315 | + .should_receive("comment") |
| 1316 | + .mock() |
| 1317 | + ) |
| 1318 | + urls.DASHBOARD_URL = "https://dashboard.localhost" |
| 1319 | + |
| 1320 | + config = PackageConfig( |
| 1321 | + packages={ |
| 1322 | + "package": CommonPackageConfig( |
| 1323 | + specfile_path="test.spec", |
| 1324 | + ) |
| 1325 | + }, |
| 1326 | + jobs=[ |
| 1327 | + JobConfig( |
| 1328 | + type=JobType.copr_build, |
| 1329 | + trigger=JobConfigTriggerType.pull_request, |
| 1330 | + packages={ |
| 1331 | + "package": CommonPackageConfig( |
| 1332 | + _targets=["fedora-rawhide"], |
| 1333 | + specfile_path="test.spec", |
| 1334 | + ) |
| 1335 | + }, |
| 1336 | + ), |
| 1337 | + JobConfig( |
| 1338 | + type=JobType.tests, |
| 1339 | + trigger=JobConfigTriggerType.pull_request, |
| 1340 | + packages={ |
| 1341 | + "package": CommonPackageConfig( |
| 1342 | + _targets=["fedora-rawhide"], |
| 1343 | + specfile_path="test.spec", |
| 1344 | + require=RequirementsConfig( |
| 1345 | + label=LabelRequirementsConfig(present=["a-label"]) |
| 1346 | + ), |
| 1347 | + ) |
| 1348 | + }, |
| 1349 | + ), |
| 1350 | + ], |
| 1351 | + ) |
| 1352 | + |
| 1353 | + flexmock(AbstractCoprBuildEvent).should_receive("get_packages_config").and_return( |
| 1354 | + config |
| 1355 | + ) |
| 1356 | + flexmock(CoprHelper).should_receive("get_copr_client").and_return( |
| 1357 | + Client(config={"username": "packit", "copr_url": "https://dummy.url"}) |
| 1358 | + ) |
| 1359 | + flexmock(PackageConfigGetter).should_receive( |
| 1360 | + "get_package_config_from_repo" |
| 1361 | + ).and_return(config) |
| 1362 | + |
| 1363 | + flexmock(LocalProject).should_receive("refresh_the_arguments").and_return(None) |
| 1364 | + |
| 1365 | + flexmock(CoprBuildTargetModel).should_receive("get_by_build_id").and_return( |
| 1366 | + copr_build_pr |
| 1367 | + ) |
| 1368 | + flexmock(CoprBuildTargetModel).should_receive("get_by_id").and_return(copr_build_pr) |
| 1369 | + copr_build_pr.should_call("set_status").with_args(BuildStatus.success).once() |
| 1370 | + copr_build_pr.should_receive("set_end_time").once() |
| 1371 | + copr_build_pr.should_receive("get_package_name").and_return(None) |
| 1372 | + flexmock(requests).should_receive("get").and_return(requests.Response()) |
| 1373 | + flexmock(requests.Response).should_receive("raise_for_status").and_return(None) |
| 1374 | + # check if packit-service set correct PR status |
| 1375 | + url = get_copr_build_info_url(1) |
| 1376 | + flexmock(StatusReporter).should_receive("report").with_args( |
| 1377 | + state=BaseCommitStatus.success, |
| 1378 | + description="RPMs were built successfully.", |
| 1379 | + url=url, |
| 1380 | + check_names=EXPECTED_BUILD_CHECK_NAME, |
| 1381 | + markdown_content=None, |
| 1382 | + links_to_external_services=None, |
| 1383 | + update_feedback_time=object, |
| 1384 | + ).once() |
| 1385 | + |
| 1386 | + flexmock(StatusReporter).should_receive("report").with_args( |
| 1387 | + state=BaseCommitStatus.pending, |
| 1388 | + description="RPMs were built successfully.", |
| 1389 | + url=url, |
| 1390 | + check_names=EXPECTED_TESTING_FARM_CHECK_NAME, |
| 1391 | + markdown_content=None, |
| 1392 | + links_to_external_services=None, |
| 1393 | + update_feedback_time=object, |
| 1394 | + ).once() |
| 1395 | + |
| 1396 | + flexmock(GithubProject).should_receive("get_web_url").and_return( |
| 1397 | + "https://github.com/foo/bar" |
| 1398 | + ) |
| 1399 | + |
| 1400 | + flexmock(Signature).should_receive("apply_async").once() |
| 1401 | + |
| 1402 | + # skip SRPM url since it touches multiple classes |
| 1403 | + flexmock(CoprBuildEndHandler).should_receive("set_srpm_url").and_return(None) |
| 1404 | + |
| 1405 | + ( |
| 1406 | + flexmock(CoprBuildJobHelper) |
| 1407 | + .should_receive("get_build_chroot") |
| 1408 | + .with_args(1, "some-target") |
| 1409 | + .and_return(flexmock(ended_on=1666889710)) |
| 1410 | + .at_least() |
| 1411 | + .once() |
| 1412 | + ) |
| 1413 | + |
| 1414 | + flexmock(Pushgateway).should_receive("push").times(2).and_return() |
| 1415 | + |
| 1416 | + processing_results = SteveJobs().process_message(copr_build_end) |
| 1417 | + event_dict, job, job_config, package_config = get_parameters_from_results( |
| 1418 | + processing_results |
| 1419 | + ) |
| 1420 | + assert json.dumps(event_dict) |
| 1421 | + |
| 1422 | + flexmock(CoprBuildJobHelper).should_receive("get_built_packages").and_return([]) |
| 1423 | + |
| 1424 | + run_copr_build_end_handler( |
| 1425 | + package_config=package_config, |
| 1426 | + event=event_dict, |
| 1427 | + job_config=job_config, |
| 1428 | + ) |
| 1429 | + |
| 1430 | + |
1154 | 1431 | def test_copr_build_end_push_testing_farm(copr_build_end_push, copr_build_branch_push):
|
1155 | 1432 | config = PackageConfig(
|
1156 | 1433 | packages={
|
|
0 commit comments