|
5 | 5 | import pwd |
6 | 6 | import yaml |
7 | 7 | import re |
| 8 | +import requests |
8 | 9 | import time |
9 | 10 |
|
10 | 11 | from pathlib import Path |
@@ -103,6 +104,7 @@ def create_initial_config(self): |
103 | 104 | self.choose_ceph_version(ceph_hash) |
104 | 105 | suite_branch = self.choose_suite_branch() |
105 | 106 | suite_hash = self.choose_suite_hash(suite_branch) |
| 107 | + self.verify_sha_id(ceph_hash, suite_branch) |
106 | 108 | if self.args.suite_dir: |
107 | 109 | self.suite_repo_path = self.args.suite_dir |
108 | 110 | else: |
@@ -251,6 +253,43 @@ def choose_ceph_version(self, ceph_hash): |
251 | 253 | else: |
252 | 254 | log.info('skipping ceph package verification') |
253 | 255 |
|
| 256 | + def verify_sha_id(self, ceph_hash, ceph_branch): |
| 257 | + """ |
| 258 | + Verify if a given Ceph version (SHA1) exists in either Chacra or Shaman |
| 259 | + repositories for the specified branch. |
| 260 | + """ |
| 261 | + def fetch_url(url, expect_json=False): |
| 262 | + """Fetch content from a URL, optionally parse JSON.""" |
| 263 | + try: |
| 264 | + response = requests.get(url, timeout=10) |
| 265 | + response.raise_for_status() |
| 266 | + except requests.exceptions.RequestException as e: |
| 267 | + log.error(f"Failed to fetch {url}: {e}") |
| 268 | + return None |
| 269 | + |
| 270 | + if expect_json: |
| 271 | + try: |
| 272 | + return response.json() |
| 273 | + except ValueError: |
| 274 | + log.error(f"Invalid JSON from {url}") |
| 275 | + return None |
| 276 | + return response.text |
| 277 | + |
| 278 | + chacra_url = f"https://1.chacra.ceph.com/repos/ceph/{ceph_branch}/" |
| 279 | + chacra_data = fetch_url(chacra_url, expect_json=True) |
| 280 | + if chacra_data: |
| 281 | + if ceph_hash not in chacra_data: |
| 282 | + msg = f"Not found in Chacra for branch {ceph_branch}." |
| 283 | + util.schedule_fail(msg, self.name, dry_run=self.args.dry_run) |
| 284 | + |
| 285 | + shaman_url = f"https://shaman.ceph.com/builds/ceph/{ceph_branch}/" |
| 286 | + shaman_html = fetch_url(shaman_url) |
| 287 | + if shaman_html: |
| 288 | + sha1s = set(re.findall(r"[0-9a-f]{40}", shaman_html)) |
| 289 | + if ceph_hash not in sha1s: |
| 290 | + msg = f"Not found in Shaman for branch {ceph_branch}." |
| 291 | + util.schedule_fail(msg, self.name, dry_run=self.args.dry_run) |
| 292 | + |
254 | 293 | def choose_teuthology_branch(self): |
255 | 294 | """Select teuthology branch, check if it is present in repo and return |
256 | 295 | tuple (branch, hash) where hash is commit sha1 corresponding |
|
0 commit comments