Skip to content

Commit

Permalink
update job tool to support specific ENV vars
Browse files Browse the repository at this point in the history
  • Loading branch information
jianzhangbjz committed Dec 25, 2023
1 parent b52869d commit 7d2874d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
9 changes: 9 additions & 0 deletions prow/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ Debug mode is off
Returned job id: 3ebe0a6e-ea5c-4c96-9ca4-295074f9eaa3
periodic-ci-openshift-openshift-tests-private-release-4.11-amd64-nightly-4.11-upgrade-from-stable-4.10-gcp-ipi-disconnected-private-p2-f14 None 3ebe0a6e-ea5c-4c96-9ca4-295074f9eaa3 2023-06-07T06:15:10Z https://qe-private-deck-ci.apps.ci.l2s4.p1.openshiftapps.com/view/gs/qe-private-deck/logs/periodic-ci-openshift-openshift-tests-private-release-4.11-amd64-nightly-4.11-upgrade-from-stable-4.10-gcp-ipi-disconnected-private-p2-f14/1666327924111839232
```
- An example to run a job with specific Envs.
```console
MacBook-Pro:job jianzhang$ job run --envs OMR_IMAGE=openshift-mirror-registry-rhel8:v1.3.8-2 periodic-ci-quay-quay-tests-master-omr-ocp415-unreleased-quay-omr-tests-omr-ocp415-disconnected-unreleased
Debug mode is off
{'job_execution_type': '1', 'pod_spec_options': {'envs': {'OMR_IMAGE': 'openshift-mirror-registry-rhel8:v1.3.8-2'}}}
Returned job id: 02a12b66-9a64-42db-8c28-bf785bbca501
periodic-ci-quay-quay-tests-master-omr-ocp415-unreleased-quay-omr-tests-omr-ocp415-disconnected-unreleased None 02a12b66-9a64-42db-8c28-bf785bbca501 2023-12-25T08:37:30Z https://prow.ci.openshift.org/view/gs/origin-ci-test/logs/periodic-ci-quay-quay-tests-master-omr-ocp415-unreleased-quay-omr-tests-omr-ocp415-disconnected-unreleased/1739203704738811904
Done.
```
### Debug failure job
- `Error code: 500, reason: Internal Server Error`
Expand Down
2 changes: 1 addition & 1 deletion prow/job/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version_info = (2, 1, 0)
version_info = (2, 1, 1)
version = '.'.join(str(c) for c in version_info)
31 changes: 24 additions & 7 deletions prow/job/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ def get_amdBaseImage_for_arm(self, payload):
else:
print("Warning! Fail to get the corresponding amd64 base image, use the default one:%s" % self.base_image)

def get_job_data(self, payload, upgrade_from, upgrade_to):
def get_job_data(self, payload, upgrade_from, upgrade_to, extra_env=None):
data = {"job_execution_type": "1"}
env = None
if payload is not None and upgrade_from is not None and upgrade_to is not None:
print("Error! You cannot run e2e and upgrade test at the same time!")
sys.exit(1)
env = None
# amd_latest env is must no mater what platforms you run
# support platforms: https://github.com/openshift/release-controller/blob/master/cmd/release-controller/sync_verify_prow.go#L203
amd_latest = "RELEASE_IMAGE_LATEST"
Expand Down Expand Up @@ -121,10 +121,26 @@ def get_job_data(self, payload, upgrade_from, upgrade_to):
self.get_amdBaseImage_for_arm(upgrade_from)
env = {"envs": {amd_latest: self.base_image, arm_latest: upgrade_from}}
if env is not None:
if extra_env is not None:
old_env = env["envs"]
extra_env = self.string2Json(extra_env)
old_env.update(extra_env)
env["envs"] = old_env
data = {"job_execution_type": "1", "pod_spec_options": env}
else:
if extra_env is not None:
env_json = self.string2Json(extra_env)
env = {"envs": {""}}
env["envs"] = env_json
data = {"job_execution_type": "1", "pod_spec_options": env}
print(data)
return data


def string2Json(self, strings):
pairs = [pair.split('=') for pair in strings.split(',')]
jsons = {key: value for key, value in pairs}
return jsons

def get_sha(self, url):
res = requests.get(url=url, headers=self.get_github_headers())
if res.status_code == 200:
Expand Down Expand Up @@ -322,7 +338,7 @@ def run_required_jobs(self, channels, file_path, version):
self.run_job(job, None, None, None)

# run_job func runs job by calling the API
def run_job(self, jobName, payload, upgrade_from, upgrade_to):
def run_job(self, jobName, payload, upgrade_from, upgrade_to, extra_env=None):
if jobName is None:
print("Error! Please input the correct prow job name!")
elif jobName.startswith("periodic-ci-"):
Expand All @@ -336,7 +352,7 @@ def run_job(self, jobName, payload, upgrade_from, upgrade_to):

res = requests.post(
url=url,
json=self.get_job_data(payload, upgrade_from, upgrade_to),
json=self.get_job_data(payload, upgrade_from, upgrade_to, extra_env),
headers=self.get_prow_headers(),
)
if res.status_code == 200:
Expand Down Expand Up @@ -505,11 +521,12 @@ def get_cmd(job_id):
)
@click.option("--upgrade_from", help="specify an original payload for upgrade test.")
@click.option("--upgrade_to", help="specify a target payload for upgrade test.")
def run_cmd(job_name, payload, upgrade_from, upgrade_to):
@click.option("--envs", help="specify ENV vars, multi are separated by commas, such as env1=xxx,env2=xxx")
def run_cmd(job_name, payload, upgrade_from, upgrade_to, envs):
"""Run a job and save results to /tmp/prow-jobs.csv. \n
For ARM test, we hard code a x86 image as the base image. Details: https://issues.redhat.com/browse/DPTP-3538
"""
job.run_job(job_name, payload, upgrade_from, upgrade_to)
job.run_job(job_name, payload, upgrade_from, upgrade_to, envs)


@cli.command("list")
Expand Down

0 comments on commit 7d2874d

Please sign in to comment.