OpenStack Oslo Upgrade Check

2.7.1 · active · verified Thu Apr 16

oslo-upgradecheck is a Python library providing common code for writing upgrade checks within OpenStack projects. It assists with implementing `$SERVICE-status upgrade check` commands by offering a framework to define and execute various pre-upgrade validation functions. Currently at version 2.7.1, its release cadence is generally aligned with the OpenStack coordinated release cycle, typically every six months, though individual Oslo libraries may have more frequent patch releases.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to define custom upgrade checks using the `oslo_upgradecheck.check_func` decorator and run them using `UpgradeCommands`. Each check function should return a tuple of `(status, details)`, where `status` is a boolean indicating success/failure and `details` is a string message. The `group` argument in `check_func` allows organizing checks into different phases (e.g., pre-upgrade, post-upgrade).

import sys
from oslo_upgradecheck.upgradecheck import UpgradeCommands, check_func


@check_func(group='required_pre_upgrade')
def my_first_check():
    """This is my first upgrade check.

    :returns: a tuple of (status, details).
    """
    # Simulate a successful check
    return (True, "My service is ready for upgrade.")


@check_func(group='required_pre_upgrade')
def my_second_check():
    """This is my second, more complex check.

    :returns: a tuple of (status, details).
    ""
    # Simulate a failed check based on some condition
    is_database_migrated = False # In a real scenario, check DB status
    if not is_database_migrated:
        return (False, "Database migration is incomplete. Please run 'db sync'.")
    return (True, "Database is migrated.")


def main():
    # In a real OpenStack project, oslo_config would be initialized here
    # to handle command-line arguments and configuration.
    # For this quickstart, we'll manually invoke the checks.

    commands = UpgradeCommands()

    # You can specify which group of checks to run
    # e.g., 'required_pre_upgrade', 'pre_upgrade', 'post_upgrade'
    print("\n--- Running required_pre_upgrade checks ---")
    results = commands.run_checks(group='required_pre_upgrade')
    for check, status, details in results:
        print(f"Check: {check.__name__}, Status: {status}, Details: {details}")

    if any(not s for _, s, _ in results):
        print("\nSome required checks failed. Upgrade is not recommended.")
        sys.exit(1)
    else:
        print("\nAll required checks passed. Proceed with upgrade.")
        sys.exit(0)


if __name__ == '__main__':
    main()

view raw JSON →