Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ART-10882: Get RHCOS to build on new host #1110

Merged
merged 2 commits into from
Nov 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions pyartcd/pyartcd/pipelines/build_rhcos.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
from typing import List, Dict, Tuple


JENKINS_BASE_URL = "https://jenkins-rhcos.apps.ocp-virt.prod.psi.redhat.com"

# lifted verbatim from
# https://findwork.dev/blog/advanced-usage-python-requests-timeouts-retries-hooks/
DEFAULT_TIMEOUT = 5 # seconds
Expand Down Expand Up @@ -47,6 +45,9 @@ def __init__(self, runtime: Runtime, new_build: bool, ignore_running: bool, vers
self.api_token = None
self._stream = None # rhcos stream the version maps to
self.dry_run = self.runtime.dry_run
self.jenkins_base_url = "https://jenkins-rhcos--prod-pipeline.apps.int.prod-stable-spoke1-dc-iad2.itup.redhat.com"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggest putting this URL in the constants

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It used to be a module constant, which is appropriate, as this is the only place that consumes it.
I intend to restore that next week once we get the go ahead to produce all builds on the new instance.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

if self.version in ["4.15", "4.16", "4.17", "4.18", "4.19"]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggest using version compare

self.jenkins_base_url = 'https://jenkins-rhcos.apps.ocp-virt.prod.psi.redhat.com'

self.request_session = requests.Session()
retries = Retry(
Expand Down Expand Up @@ -92,7 +93,7 @@ def retrieve_auth_token(self) -> str:
if s.model.type == "kubernetes.io/service-account-token" and s.model.metadata.annotations["kubernetes.io/service-account.name"] == "jenkins" and s.model.metadata.annotations["kubernetes.io/service-account.uid"] == jenkins_uid:
secret_maybe = base64.b64decode(s.model.data.token).decode('utf-8')
r = self.request_session.get(
f"{JENKINS_BASE_URL}/me/api/json",
f"{self.jenkins_base_url}/me/api/json",
headers={"Authorization": f"Bearer {secret_maybe}"},
)
if r.status_code == 200:
Expand All @@ -114,9 +115,8 @@ def build_parameters(build: Dict[str, List[Dict]]) -> Dict:
), [])
return {p["name"]: p["value"] for p in parameters}

@staticmethod
def build_url(job: str, number: int) -> str:
return f"{JENKINS_BASE_URL}/job/{job}/{number}/"
def build_url(self, job: str, number: int) -> str:
return f"{self.jenkins_base_url}/job/{job}/{number}/"

def query_existing_builds(self) -> List[Dict]:
"""Check if there are any existing builds for the given version. Returns builds in progress."""
Expand All @@ -125,7 +125,7 @@ def query_existing_builds(self) -> List[Dict]:
builds.extend(
dict(**b, job=job, parameters=self.build_parameters(b), url=self.build_url(job, b["number"]))
for b in self.request_session.get(
f"{JENKINS_BASE_URL}/job/{job}/api/json?tree=builds[number,description,result,actions[parameters[name,value]]]",
f"{self.jenkins_base_url}/job/{job}/api/json?tree=builds[number,description,result,actions[parameters[name,value]]]",
).json()["builds"]
if b["result"] is None # build is still running when it has no status
)
Expand Down Expand Up @@ -164,7 +164,7 @@ def start_build(self):
params = dict(STREAM=self.stream, EARLY_ARCH_JOBS="false")
if self.new_build:
params["FORCE"] = "true"
job_url = f"{JENKINS_BASE_URL}/job/build/buildWithParameters"
job_url = f"{self.jenkins_base_url}/job/build/buildWithParameters"
if self.dry_run:
print(f"Would've started build at url={job_url} with params={params}", file=sys.stderr)
return {}
Expand Down Expand Up @@ -195,7 +195,7 @@ def build_result(self, job, number):
description=b["description"] or "[no description yet]",
result=b["result"],
) for b in self.request_session.get(
f"{JENKINS_BASE_URL}/job/{job}/api/json?tree=builds[number,description,result]"
f"{self.jenkins_base_url}/job/{job}/api/json?tree=builds[number,description,result]"
).json()["builds"]
if b["number"] == number
), None)
Expand Down