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

Kolla-Ansible/Kayobe version enforcement #1551

Open
wants to merge 20 commits into
base: stackhpc/2024.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 17 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
2 changes: 2 additions & 0 deletions .ansible-lint-ignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ etc/kayobe/ansible/vault-generate-internal-tls.yml fqcn[action-core]
etc/kayobe/ansible/vault-generate-test-external-tls.yml fqcn[action-core]
etc/kayobe/ansible/rabbitmq-reset.yml command-instead-of-module
etc/kayobe/ansible/ubuntu-upgrade.yml syntax-check[missing-file]
etc/kayobe/ansible/check-kayobe-version.yml command-instead-of-module
etc/kayobe/ansible/check-kolla-version.yml command-instead-of-module
57 changes: 57 additions & 0 deletions etc/kayobe/ansible/check-kayobe-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
- name: Check Kayobe version
tags: kayobe-version-check
hosts: localhost
gather_facts: false
vars:
requirements_path: "{{ kayobe_config_path }}/../../requirements.txt"
tasks:
- name: Get package info
community.general.pip_package_info:
register: packages

- name: Check if pip is version 24.0 or newer
ansible.builtin.assert:
that: "{{ packages.packages.pip.pip[0].version is version('24.0', '>=') }}"
fail_msg: |
Pip must be 24.0 or newer to run this check. Upgrade pip by running
pip install -U pip and reinstall Kayobe by running:
pip install --force-reinstall -r {{ requirements_path }}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note the order here must be observed as Kayobe installed on an older verison of pip will still show the incorrect version output in pip freeze, breaking the check.

- name: Get installed Kayobe commit
ansible.builtin.shell:
cmd: set -o pipefail && pip freeze | grep kayobe | cut -d @ -f 3
executable: /usr/bin/bash
register: kayobe_git_commit

- name: Clone Kayobe
Copy link
Contributor

@jovial jovial Mar 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if instead of doing all this manually, could you use:

pip install . --dry-run --report /tmp/test.json

Which i think will tell you the new commit of kayobe it would install.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this approach will work here, as we're cloning Kayobe to get the commit that matches up with the currently installed tag from the git SHA outputted in the venv, rather than the newest commit from Kayobe.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So just to clarify, I was suggesting doing a dry run pip install of kayobe-config. That would work with any repo specified in requirements.txt, whereas this solution has some custom parsing of that and is hardcoded to:

       - name: Clone Kayobe
          ansible.builtin.git:
            repo: https://github.com/stackhpc/kayobe.git
            dest: /tmp/kayobe-git
            version: stackhpc/{{ openstack_release }}

But was just a thought and can accept it might not do what you want.

ansible.builtin.git:
repo: https://github.com/stackhpc/kayobe.git
dest: /tmp/kayobe-git
version: stackhpc/{{ openstack_release }}

- name: Get tag from Kayobe commit

Check warning on line 33 in etc/kayobe/ansible/check-kayobe-version.yml

View workflow job for this annotation

GitHub Actions / Ansible 2.16 lint with Python 3.12

command-instead-of-module

git used in place of git module

Check warning on line 33 in etc/kayobe/ansible/check-kayobe-version.yml

View workflow job for this annotation

GitHub Actions / Ansible 2.15 lint with Python 3.10

command-instead-of-module

git used in place of git module
ansible.builtin.command:
cmd: git describe --tags {{ kayobe_git_commit.stdout }}
chdir: /tmp/kayobe-git
register: kayobe_current_version

- name: Get latest Kayobe version
ansible.builtin.shell:
cmd: set -o pipefail && grep -o kayobe@stackhpc\/.*$ {{ requirements_path }} | cut -d @ -f 2
executable: /usr/bin/bash
register: kayobe_latest_version

- name: Check installed Kayobe version is the latest
ansible.builtin.assert:
that: "kayobe_latest_version.stdout in kayobe_current_version.stdout"
fail_msg: |
Kayobe must use the expected version before continuing.
Current Kayobe version: {{ kayobe_current_version.stdout }}
Expected Kayobe version: {{ kayobe_latest_version.stdout }}
Recreate the Kayobe environment, or install the expected version
by running: pip install --force-reinstall -r {{ requirements_path }}
success_msg: |
Kayobe running at version: {{ kayobe_current_version.stdout }}
24 changes: 24 additions & 0 deletions etc/kayobe/ansible/check-kolla-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
- name: Check Kolla-Ansible version
tags: kolla-version-check
hosts: localhost
gather_facts: false
tasks:
- name: Get current Kolla-Ansible tag

Check warning on line 7 in etc/kayobe/ansible/check-kolla-version.yml

View workflow job for this annotation

GitHub Actions / Ansible 2.16 lint with Python 3.12

command-instead-of-module

git used in place of git module

Check warning on line 7 in etc/kayobe/ansible/check-kolla-version.yml

View workflow job for this annotation

GitHub Actions / Ansible 2.15 lint with Python 3.10

command-instead-of-module

git used in place of git module
ansible.builtin.command:
cmd: git describe --tags
chdir: "{{ lookup('ansible.builtin.env', 'KOLLA_SOURCE_PATH') }}"
register: kolla_ansible_current_version

- name: Check installed Kolla-Ansible version is the expected version
ansible.builtin.assert:
that: "stackhpc_kolla_ansible_source_version in kolla_ansible_current_version.stdout"
fail_msg: |
Kolla-Ansible must use the expected version before continuing.

Current Kolla-Ansible version: {{ kolla_ansible_current_version.stdout }}
Expected Kolla-Ansible version: {{ stackhpc_kolla_ansible_source_version }}

Upgrade Kolla-Ansible by running: kayobe control host upgrade
success_msg: |
Kolla-Ansible running at version: {{ kolla_ansible_current_version.stdout }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
features:
- |
Ansible playbooks to check the installed Kayobe/Kolla-Ansible versions
with the expected versions in Kayobe configuration. These checks
will run on Kayobe bootstrap, host and service operations.
Loading