# OpenStack Volume Deletion Fails

## Problem

Deletion of the volume fails with the following error in `/var/log/pf9/cindervolume-base.log`.

{% tabs %}
{% tab title="cindervolume-base.log" %}

```ruby
Delete for volume [VOLUME-ID] failed: Invalid volume: Volume status must be available or error or error_restoring or error_extending or error_managing and must not be migrating, attached, belong to a group, have snapshots or be disassociated from snapshots after volume transfer. 
(HTTP 400) (Request-ID: [REQUEST-ID]) ERROR: Unable to delete any of the specified volumes.
```

{% endtab %}
{% endtabs %}

## Environment

* Platform9 Managed OpenStack - v3.6.0 and Higher
* Cinder

## Cause

In both these cases mentioned below, Cinder restricts the volume deletion.

* **Case 1**: The volume stuck during volume migration.
* **Case 2**: The volume was not cleanly detached during VM deletion.

## Diagnosis

**Case 1:**

* Volume details

{% tabs %}
{% tab title="Command" %}

```bash
$ openstack volume show --fit <VOLUME_UUID>
+--------------------------------+--------------------------------------------------+
| Field                          | Value                                            |
+--------------------------------+--------------------------------------------------+
| attachments                    | []                                               |
| availability_zone              | [AZ-NAME]                                        |
| bootable                       | false                                            |
| consistencygroup_id            | None                                             |
| created_at                     | [TIME-STAMP]                                     |
| description                    | [DESCRIPTION]                                    |
| encrypted                      | False                                            |
| id                             | [VOLUME-ID]                                      |
| migration_status               | deleting                                         |
| multiattach                    | False                                            |
| name                           | [VOLUME-NAME]                                    |
| os-vol-host-attr:host          | [HOST-ID]                                        |
| os-vol-mig-status-attr:migstat | deleting                                         |
| os-vol-mig-status-attr:name_id | None                                             |
| os-vol-tenant-attr:tenant_id   | [TENANT-ID]                                      |
| properties                     | attached_mode='rw', readonly='False'             |
| replication_status             | None                                             |
| size                           | [SIZE]                                           |
| snapshot_id                    | None                                             |
| source_volid                   | None                                             |
| status                         | deleting                                         |
| type                           | None                                             |
| updated_at                     | [TIME-STAMP]                                     |
| user_id                        | [USER-ID]                                        |
+--------------------------------+--------------------------------------------------+
```

{% endtab %}
{% endtabs %}

* Cinder volume base logs

{% tabs %}
{% tab title="cindervolume-base.log" %}

```ruby
Delete for volume [VOLUME-ID] failed: Invalid volume: Volume status must be available or error or error_restoring or error_extending or error_managing and must not be migrating, attached, belong to a group, have snapshots or be disassociated from snapshots after volume transfer. 
(HTTP 400) (Request-ID: [REQUEST-ID]) ERROR: Unable to delete any of the specified volumes.
```

{% endtab %}
{% endtabs %}

**Case 2:**

* Volume details

{% tabs %}
{% tab title="Command" %}

```bash
$ openstack volume show --fit <VOLUME_UUID>
+--------------------------------+--------------------------------------------------+
| Field                          | Value                                            |
+--------------------------------+--------------------------------------------------+
| attachments                    | []                                               |
| availability_zone              | [AZ-NAME]                                        |
| bootable                       | false                                            |
| consistencygroup_id            | None                                             |
| created_at                     | [TIME-STAMP]                                     |
| description                    | [DESCRIPTION]                                    |
| encrypted                      | False                                            |
| id                             | [VOLUME-ID]                                      |
| migration_status               | None                                             |
| multiattach                    | False                                            |
| name                           | [VOLUME-NAME]                                    |
| os-vol-host-attr:host          | [HOST-ID]                                        |
| os-vol-mig-status-attr:migstat | None                                             |
| os-vol-mig-status-attr:name_id | None                                             |
| os-vol-tenant-attr:tenant_id   | [TENANT-ID]                                      |
| properties                     | readonly='False'                                 |
| replication_status             | None                                             |
| size                           | [SIZE]                                           |
| snapshot_id                    | None                                             |
| source_volid                   | None                                             |
| status                         | deleting                                         |
| type                           | None                                             |
| updated_at                     | [TIME-STAMP]                                     |
| user_id                        | [USER-ID]                                        |
+--------------------------------+--------------------------------------------------+
```

{% endtab %}
{% endtabs %}

* Cinder volume base logs

{% tabs %}
{% tab title="cindervolume-base.log" %}

```ruby
Delete for volume [VOLUME-ID] failed: Invalid volume: Volume status must be available or error or error_restoring or error_extending or error_managing and must not be migrating, attached, belong to a group, have snapshots or be disassociated from snapshots after volume transfer. 
(HTTP 400) (Request-ID: [REQUEST-ID]) ERROR: Unable to delete any of the specified volumes.
```

{% endtab %}
{% endtabs %}

## Resolution

**Case 1:** **For volume stuck with migration** **and attach-related flags:**

{% hint style="info" %}
**Note**

To run `cinder` commands, install `python-cinderclient==9.4.0` Generally cinder binary is available only on the Platform9 Management Plane and Block Storage hosts directly.
{% endhint %}

* Set the state of the volume to "available".

{% tabs %}
{% tab title="Command" %}

```bash
$ cinder reset-state --state available <VOLUME_UUID>
```

{% endtab %}
{% endtabs %}

* Reset the migration status of the volume.

{% tabs %}
{% tab title="Command" %}

```bash
$ cinder reset-state --reset-migration-status  <VOLUME_UUID>
```

{% endtab %}
{% endtabs %}

* Set the attach status to "detached".

{% tabs %}
{% tab title="Command" %}

```bash
$ cinder reset-state --attach-status detached  <VOLUME_UUID>
```

{% endtab %}
{% endtabs %}

* Delete the volume.

{% tabs %}
{% tab title="Command" %}

```bash
$ cinder delete  <VOLUME_UUID>
```

{% endtab %}
{% endtabs %}

**Case 2: For volumes stuck in `deleting` state:**

* Reset the state of the volume to "available"

{% tabs %}
{% tab title="Command" %}

```bash
$ openstack volume set --state available <VOLUME_UUID>
```

{% endtab %}
{% endtabs %}

* Delete the volume

{% tabs %}
{% tab title="Command" %}

```bash
$ openstack volume delete  <VOLUME_UUID>
```

{% endtab %}
{% endtabs %}

## Validation

**Case 1: After applying fix for volume with migration and attach metadata:**

* Volume status changes from **deleting** to **available** after the *reset-state* command.
* **migration\_status** becomes **None**.
* **attached\_mode** or properties like **attached\_mode='rw'** are no longer blocking deletion.
* The volume is successfully deleted from the system and no longer appears in CLI or UI.
* Verify volume state:

{% tabs %}
{% tab title="Command" %}

```bash
$ openstack volume show <VOLUME_UUID> --fit-width
Expected Output:

No volume with a name or ID of '[VOLUME_UUID]' exists.
```

{% endtab %}
{% endtabs %}

**Case 2: After applying fix for volume with migration and attach metadata:**

* Volume status changes from **deleting** to **available** after the *reset-state* command.
* The volume is successfully deleted from the system and no longer appears in CLI or UI.
* Verify volume state:

{% tabs %}
{% tab title="Command" %}

```bash
$ openstack volume show <VOLUME_UUID> --fit-width
Expected Output:

No volume with a name or ID of '[VOLUME_UUID]' exists.
```

{% endtab %}
{% endtabs %}

## Additional Information

* Always confirm that the volume is not in use or attached to a running instance before forcibly resetting its state.
* Resetting states bypasses safety checks and should only be used when metadata inconsistencies block clean-up.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://platform9.com/kb/pmo/solution/openstack-volume-deletion-fails.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
