# Post Tempest Run Cleanup Utility

Utility for cleaning up environment after Tempest test run

Usage: `tempest cleanup [--help] [OPTIONS]`

If run with no arguments, `tempest cleanup` will query your OpenStack deployment and build a list of resources to delete and destroy them. This list will exclude the resources from `saved_state.json` and will include the configured admin account if the `--delete-tempest-conf-objects` flag is specified. By default the admin project is not deleted and the admin user specified in `tempest.conf` is never deleted.

## Example Run

Warning

We advice not to run tempest cleanup on production environments.

Warning

If step 1 is skipped in the example below, the cleanup procedure may delete resources that existed in the cloud before the test run. This may cause an unwanted destruction of cloud resources, so use caution with this command.

Examples:

    $ tempest cleanup --init-saved-state
    $ # Actual running of Tempest tests
    $ tempest cleanup

## Runtime Arguments

- `--init-saved-state`: Initializes the saved state of the OpenStack deployment and will output a `saved_state.json` file containing resources from your deployment that will be preserved from the cleanup command. This should be done prior to running Tempest tests. Note, that if other users of your cloud could have created resources after running `--init-saved-state`, it would not protect those resources as they wouldn’t be present in the saved_state.json file.

- `--delete-tempest-conf-objects`: If option is present, then the command will delete the admin project in addition to the resources associated with them on clean up. If option is not present, the command will delete the resources associated with the Tempest and alternate Tempest users and projects but will not delete the projects themselves.

- `--dry-run`: Creates a report (`./dry_run.json`) of the projects that will be cleaned up (in the `_projects_to_clean` dictionary [1]) and the global objects that will be removed (domains, flavors, images, roles, projects, and users). Once the cleanup command is executed (e.g. run without parameters), running it again with `--dry-run` should yield an empty report. We STRONGLY ENCOURAGE to run `tempest cleanup` with `--dry-run` first and then verify that the resources listed in the `dry_run.json` file are meant to be deleted.

- `--prefix`: Only resources that match the prefix will be deleted. When this option is used, `saved_state.json` file is not needed (no need to run with `--init-saved-state` first).

  All tempest resources are created with the prefix value from the config option `resource_name_prefix` in tempest.conf. To cleanup only the resources created by tempest, you should use the prefix set in your tempest.conf (the default value of `resource_name_prefix` is `tempest`.

  Note, that some resources are not named thus they will not be deleted when filtering based on the prefix. This option will be ignored when `--init-saved-state` is used so that it can capture the true init state - all resources present at that moment. If there is any `saved_state.json` file present (e.g. if you ran the tempest cleanup with `--init-saved-state` before) and you run the tempest cleanup with `--prefix`, the `saved_state.json` file will be ignored and cleanup will be done based on the passed prefix only.

- `--resource-list`: Allows the use of file `./resource_list.json`, which contains all resources created by Tempest during all Tempest runs, to create another method for removing only resources created by Tempest. List of these resources is created when config option `record_resources` in default section is set to true. After using this option for cleanup, the existing `./resource_list.json` is cleared from deleted resources.

  When this option is used, `saved_state.json` file is not needed (no need to run with `--init-saved-state` first). If there is any `saved_state.json` file present and you run the tempest cleanup with `--resource-list`, the `saved_state.json` file will be ignored and cleanup will be done based on the `resource_list.json` only.

  If you run tempest cleanup with both `--prefix` and `--resource-list`, the `--resource-list` option will be ignored and cleanup will be done based on the `--prefix` option only.

- `--help`: Print the help text for the command and parameters.

[1]

The `_projects_to_clean` dictionary in `dry_run.json` lists the projects that `tempest cleanup` will loop through to delete child objects, but the command will, by default, not delete the projects themselves. This may differ from the `projects` list as you can clean the Tempest and alternate Tempest users and projects but they will not be deleted unless the `--delete-tempest-conf-objects` flag is used to force their deletion.

Note

If during execution of `tempest cleanup` NotImplemented exception occurres, `tempest cleanup` won’t fail on that, it will be logged only. NotImplemented errors are ignored because they are an outcome of some extensions being disabled and `tempest cleanup` is not checking their availability as it tries to clean up as much as possible without any complicated logic.

this page last updated: 2026-06-02 11:22:24

Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.

found an error? report a bug