Skip to content

Commit 3a1c2a3

Browse files
authored
Merge pull request #1266 from stackhpc/2024.1-2023.1-merge
2024.1: 2023.1 merge
2 parents 7462fb3 + a9c131b commit 3a1c2a3

File tree

11 files changed

+221
-10
lines changed

11 files changed

+221
-10
lines changed

.github/workflows/multinode-inputs.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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()

.github/workflows/overcloud-host-image-build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ jobs:
191191
source venvs/kayobe/bin/activate &&
192192
source src/kayobe-config/kayobe-env --environment ci-builder &&
193193
kayobe seed host command run \
194-
--command "sudo dnf config-manager --set-enabled crb && sudo dnf -y install epel-release && sudo dnf -y install zstd debootstrap kpartx cloud-init" --show-output
194+
--command "sudo dnf config-manager --set-enabled crb && sudo dnf -y install epel-release && sudo dnf -y install cloud-init debootstrap git kpartx zstd" --show-output
195195
env:
196196
KAYOBE_VAULT_PASSWORD: ${{ secrets.KAYOBE_VAULT_PASSWORD }}
197197

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
# This workflow provides a periodic deploy of a multi-node test cluster.
3+
# The test scenario is randomly selected.
4+
5+
name: Multinode periodic
6+
'on':
7+
schedule:
8+
# Runs nightly at 2:42 AM.
9+
- cron: "42 2 * * *"
10+
jobs:
11+
generate-inputs:
12+
name: Generate inputs
13+
runs-on: ubuntu-latest
14+
outputs:
15+
os_distribution: ${{ steps.generate-inputs.outputs.os_distribution }}
16+
os_release: ${{ steps.generate-inputs.outputs.os_release }}
17+
ssh_username: ${{ steps.generate-inputs.outputs.ssh_username }}
18+
neutron_plugin: ${{ steps.generate-inputs.outputs.neutron_plugin }}
19+
upgrade: ${{ steps.generate-inputs.outputs.upgrade }}
20+
stackhpc_kayobe_config_version: ${{ steps.generate-inputs.outputs.stackhpc_kayobe_config_version }}
21+
stackhpc_kayobe_config_previous_version: ${{ steps.generate-inputs.outputs.stackhpc_kayobe_config_previous_version }}
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v4
25+
26+
- name: Generate inputs for multinode workflow
27+
id: generate-inputs
28+
run: |
29+
python3 .github/workflows/multinode-inputs.py >> $GITHUB_OUTPUT
30+
31+
- name: Display generated inputs
32+
run: |
33+
echo '${{ toJSON(steps.generate-inputs.outputs) }}'
34+
multinode:
35+
name: Multinode periodic
36+
needs:
37+
- generate-inputs
38+
uses: stackhpc/stackhpc-openstack-gh-workflows/.github/workflows/[email protected]
39+
with:
40+
multinode_name: mn-prdc-${{ github.run_id }}
41+
os_distribution: ${{ needs.generate-inputs.outputs.os_distribution }}
42+
os_release: ${{ needs.generate-inputs.outputs.os_release }}
43+
ssh_username: ${{ needs.generate-inputs.outputs.ssh_username }}
44+
neutron_plugin: ${{ needs.generate-inputs.outputs.neutron_plugin }}
45+
upgrade: ${{ needs.generate-inputs.outputs.upgrade == 'true' }}
46+
stackhpc_kayobe_config_version: ${{ needs.generate-inputs.outputs.stackhpc_kayobe_config_version }}
47+
stackhpc_kayobe_config_previous_version: ${{ needs.generate-inputs.outputs.stackhpc_kayobe_config_previous_version }}
48+
enable_slack_alert: true
49+
secrets: inherit
50+
if: github.repository == 'stackhpc/stackhpc-kayobe-config'

.github/workflows/stackhpc-multinode.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ name: Multinode
5252
jobs:
5353
multinode:
5454
name: Multinode
55-
uses: stackhpc/stackhpc-openstack-gh-workflows/.github/workflows/[email protected].0
55+
uses: stackhpc/stackhpc-openstack-gh-workflows/.github/workflows/[email protected].1
5656
with:
5757
multinode_name: ${{ inputs.multinode_name }}
5858
os_distribution: ${{ inputs.os_distribution }}

.pre-commit-config.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.4.0
4+
hooks:
5+
- id: check-yaml
6+
- id: end-of-file-fixer
7+
- id: trailing-whitespace
8+
- repo: https://github.com/sirwart/ripsecrets
9+
rev: v0.1.7
10+
hooks:
11+
- id: ripsecrets

doc/source/contributor/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ This guide is for contributors of the StackHPC Kayobe configuration project.
1111
release-notes
1212
environments/index
1313
package-updates
14+
pre-commit

doc/source/contributor/pre-commit.rst

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
================
2+
Pre-commit Hooks
3+
================
4+
5+
StackHPC Kayobe configuration carries support for
6+
`pre-commit hooks <https://pre-commit.com/>`_ which simplify the use of git
7+
hooks enabling the identification and repairing of broken or poor code
8+
before committing.
9+
These hooks are designed to make working within SKC easier and less error prone.
10+
11+
Currently the following hooks are provided:
12+
13+
- ``check-yaml``: perform basic yaml syntax linting
14+
- ``end-of-file-fixer``: identify and automatically fix missing newline
15+
- ``trailing-whitespace``: identify and automatically fix excessive white space
16+
- ``ripsecrets``: identify and prevent secrets from being committed to the branch
17+
18+
.. warning::
19+
The hook ``ripsecrets`` is capable of preventing the accidental leaking of secrets
20+
such as those found within `secrets.yml` or `passwords.yml`.
21+
However if the secret is contained within a file on it's own and lacks a certain level
22+
of entropy then the secret will not be identified as such as and maybe leaked as a result.
23+
24+
Installation of `pre-commit` hooks is handled via the `install-pre-commit-hooks` playbook
25+
found within the Ansible directory.
26+
Either run the playbook manually or add the playbook as a hook within Kayobe config such as
27+
within `control-host-bootstrap/post.d`.
28+
Once done you should find `pre-commit` is available within the `kayobe` virtualenv.
29+
30+
To run the playbook using the following command
31+
32+
- ``kayobe playbook run ${KAYOBE_CONFIG_PATH}/ansible/install-pre-commit-hooks.yml``
33+
34+
Whereas to run the playbook when control host bootstrap runs ensure it registered as symlink using the following command
35+
36+
- ``mkdir -p ${KAYOBE_CONFIG_PATH}/hooks/control-host-bootstrap/post.d``
37+
- ``ln -s ${KAYOBE_CONFIG_PATH}/ansible/install-pre-commit-hooks.yml ${KAYOBE_CONFIG_PATH}/hooks/control-host-bootstrap/post.d/install-pre-commit-hooks.yml``
38+
39+
All that remains is the installation of the hooks themselves which can be accomplished either by
40+
running `pre-commit run` or using `git commit` when you have changes that need to be committed.
41+
This will trigger a brief installation process of the hooks which may take a few minutes.
42+
This a one time process and will not be required again unless new hooks are added or existing ones are updated.
43+
44+
.. note::
45+
Currently if you run ``pre-commit run --all-files`` it will make a series of changes to
46+
release notes that lack new lines as well configuration files that ``check-yaml`` does not
47+
approve of.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
- name: Install pre-commit hooks
3+
hosts: localhost
4+
gather_facts: false
5+
vars:
6+
pre_commit_version: 3.5.0
7+
tasks:
8+
- name: Install pre-commit hooks
9+
block:
10+
- name: Install pre-commit hooks into kayobe virtual env
11+
ansible.builtin.pip:
12+
name: pre-commit
13+
version: "{{ pre_commit_version }}"
14+
virtualenv: "{{ lookup('ansible.builtin.env', 'VIRTUAL_ENV') | default(omit, true) }}"
15+
register: pip_install
16+
17+
- name: Register pre-commit hooks with git
18+
ansible.builtin.command:
19+
cmd: "{{ lookup('ansible.builtin.env', 'VIRTUAL_ENV') | default(lookup('ansible.builtin.env', 'HOME') ~ '/.local', true) }}/bin/pre-commit install"
20+
args:
21+
chdir: "{{ playbook_dir | dirname | dirname | dirname }}"

etc/kayobe/environments/ci-multinode/kolla/globals.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# yamllint disable-file
12
---
23
############################################################################
34
# TLS

etc/kayobe/kolla.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,6 @@ kolla_sources:
147147
type: git
148148
location: https://github.com/stackhpc/networking-generic-switch.git
149149
reference: stackhpc/{{ openstack_release }}
150-
octavia-api-plugin-ovn-octavia-provider:
151-
type: git
152-
location: https://github.com/stackhpc/ovn-octavia-provider.git
153-
reference: stackhpc/{{ openstack_release }}
154-
octavia-driver-agent-plugin-ovn-octavia-provider:
155-
type: git
156-
location: https://github.com/stackhpc/ovn-octavia-provider.git
157-
reference: stackhpc/{{ openstack_release }}
158150

159151
###############################################################################
160152
# Kolla image build configuration.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
features:
3+
- |
4+
Add playbook to install pre-commit hooks and register them with git.
5+
The hooks currently configured to be installed will check yaml syntax,
6+
fix new line at end of file and remove excess whitespace. This is
7+
currently opt-in which can be achieved by running `install-pre-commit-hooks`
8+
playbook.

0 commit comments

Comments
 (0)