|
| 1 | +# Generate inputs for the reusable multinode.yml workflow. |
| 2 | +# The test scenario is randomly selected. |
| 3 | +# The inputs are printed to stdout in GitHub step output key=value format. |
| 4 | + |
| 5 | +from dataclasses import dataclass |
| 6 | +import random |
| 7 | +import typing as t |
| 8 | + |
| 9 | + |
| 10 | +@dataclass |
| 11 | +class OSRelease: |
| 12 | + distribution: str |
| 13 | + release: str |
| 14 | + ssh_username: str |
| 15 | + |
| 16 | + |
| 17 | +@dataclass |
| 18 | +class OpenStackRelease: |
| 19 | + version: str |
| 20 | + previous_version: str |
| 21 | + os_releases: t.List[OSRelease] |
| 22 | + |
| 23 | + |
| 24 | +@dataclass |
| 25 | +class Scenario: |
| 26 | + openstack_release: OpenStackRelease |
| 27 | + os_release: OSRelease |
| 28 | + neutron_plugin: str |
| 29 | + upgrade: bool |
| 30 | + |
| 31 | + |
| 32 | +ROCKY_9 = OSRelease("rocky", "9", "cloud-user") |
| 33 | +UBUNTU_JAMMY = OSRelease("ubuntu", "jammy", "ubuntu") |
| 34 | +# NOTE(upgrade): Add supported releases here. |
| 35 | +OPENSTACK_RELEASES = [ |
| 36 | + OpenStackRelease("2023.1", "zed", [ROCKY_9, UBUNTU_JAMMY]) |
| 37 | +] |
| 38 | +NEUTRON_PLUGINS = ["ovs", "ovn"] |
| 39 | + |
| 40 | + |
| 41 | +def main() -> None: |
| 42 | + scenario = random_scenario() |
| 43 | + inputs = generate_inputs(scenario) |
| 44 | + for name, value in inputs.items(): |
| 45 | + write_output(name, value) |
| 46 | + |
| 47 | + |
| 48 | +def random_scenario() -> Scenario: |
| 49 | + openstack_release = random.choice(OPENSTACK_RELEASES) |
| 50 | + os_release = random.choice(openstack_release.os_releases) |
| 51 | + neutron_plugin = random.choice(NEUTRON_PLUGINS) |
| 52 | + upgrade = random.random() > 0.6 |
| 53 | + return Scenario(openstack_release, os_release, neutron_plugin, upgrade) |
| 54 | + |
| 55 | + |
| 56 | +def generate_inputs(scenario: Scenario) -> t.Dict[str, str]: |
| 57 | + branch = get_branch(scenario.openstack_release.version) |
| 58 | + previous_branch = get_branch(scenario.openstack_release.previous_version) |
| 59 | + inputs = { |
| 60 | + "os_distribution": scenario.os_release.distribution, |
| 61 | + "os_release": scenario.os_release.release, |
| 62 | + "ssh_username": scenario.os_release.ssh_username, |
| 63 | + "neutron_plugin": scenario.neutron_plugin, |
| 64 | + "upgrade": str(scenario.upgrade).lower(), |
| 65 | + "stackhpc_kayobe_config_version": branch, |
| 66 | + "stackhpc_kayobe_config_previous_version": previous_branch, |
| 67 | + } |
| 68 | + return inputs |
| 69 | + |
| 70 | + |
| 71 | +def get_branch(version: str) -> str: |
| 72 | + return f"stackhpc/{version}" |
| 73 | + |
| 74 | + |
| 75 | +def write_output(name: str, value: str) -> None: |
| 76 | + print(f"{name}={value}") |
| 77 | + |
| 78 | + |
| 79 | +if __name__ == "__main__": |
| 80 | + main() |
0 commit comments