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

update job tool to support specific ENV vars #115

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
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