Created
September 20, 2021 21:09
-
-
Save jcpowermac/bfd4ddc876c6105b4492b1dcec677bea to your computer and use it in GitHub Desktop.
random-vsphere-release-ci
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import ruamel.yaml | |
from crontab import CronTab | |
supported_versions = ["4.6", "4.7", "4.8", "4.9", "4.10"] | |
job_variants = ["e2e-vsphere-upi", "e2e-vsphere-upi-serial", "e2e-vsphere", "e2e-vsphere-serial", "e2e-vsphere-techpreview", "e2e-vsphere-techpreview-serial"] | |
min_apart = 10 | |
def main(): | |
slots_available = int((24*60)/min_apart) | |
#available_runs_per_day = int(slots_available / (len(supported_versions) * len(job_variants) )) | |
hour = 0 | |
hour_slot = int(24 / len(supported_versions)) | |
# we currently don't need to run during this period of time | |
first_random_hours = list(range(0,10)) | |
second_random_hours = list(range(14,24)) | |
random.shuffle(first_random_hours) | |
random.shuffle(second_random_hours) | |
random_hours = first_random_hours + second_random_hours | |
# do not random the concat list | |
#random.shuffle(random_hours) | |
version_variant_dict = {} | |
for noval in range(hour_slot): | |
for version in supported_versions: | |
configured_hour = random_hours[hour] | |
variant_minute = 0 | |
random.shuffle(job_variants) | |
for variant in job_variants: | |
key = "%s-%s" % (version, variant) | |
if key not in version_variant_dict: | |
version_variant_dict[key] = {} | |
version_variant_dict[key]["hour"] = [] | |
version_variant_dict[key]["minute"] = variant_minute | |
version_variant_dict[key]["hour"].append(configured_hour) | |
version_variant_dict[key]["hour"].sort() | |
variant_minute+=10 | |
hour+=1 | |
cron = CronTab() | |
release_configs = "/var/home/jcallen/Development/release/ci-operator/config/openshift/release" | |
yaml = ruamel.yaml.YAML() | |
yaml.preserve_quotes = True | |
for version in supported_versions: | |
filename = "%s/openshift-release-master__nightly-%s.yaml" % (release_configs, version) | |
with open(filename, 'r') as fp: | |
dictionary= yaml.load(fp) | |
for test in dictionary["tests"]: | |
for jv in job_variants: | |
if test['as'] == jv: | |
version_variant_key = "%s-%s" % (version, jv) | |
minute = version_variant_dict[version_variant_key]["minute"] | |
job = cron.new(command="echo") | |
job.hour.on(*version_variant_dict[version_variant_key]["hour"]) | |
job.minute.on(minute) | |
cronstring = job.render().removesuffix(" echo") | |
test["cron"] = cronstring | |
with open(filename, 'w') as fp: | |
yaml.dump(dictionary, fp) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment