volume: Allow setting volume statuses individually
Some of these are admin-only. We don't want to force setting them all at once. Change-Id: I3b1694ee5e4dfd96315cc48b44b3d28c01aa3bfa Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
@@ -385,7 +385,7 @@ class Proxy(_base_proxy.BaseBlockStorageProxy):
|
|||||||
volume.set_bootable_status(self, bootable)
|
volume.set_bootable_status(self, bootable)
|
||||||
|
|
||||||
def reset_volume_status(
|
def reset_volume_status(
|
||||||
self, volume, status, attach_status, migration_status
|
self, volume, status=None, attach_status=None, migration_status=None
|
||||||
):
|
):
|
||||||
"""Reset volume statuses.
|
"""Reset volume statuses.
|
||||||
|
|
||||||
|
@@ -9,6 +9,9 @@
|
|||||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
import typing as ty
|
||||||
|
|
||||||
from openstack.common import metadata
|
from openstack.common import metadata
|
||||||
from openstack import format
|
from openstack import format
|
||||||
from openstack import resource
|
from openstack import resource
|
||||||
@@ -114,15 +117,17 @@ class Volume(resource.Resource, metadata.MetadataMixin):
|
|||||||
body = {'os-set_bootable': {'bootable': bootable}}
|
body = {'os-set_bootable': {'bootable': bootable}}
|
||||||
self._action(session, body)
|
self._action(session, body)
|
||||||
|
|
||||||
def reset_status(self, session, status, attach_status, migration_status):
|
def reset_status(
|
||||||
|
self, session, status=None, attach_status=None, migration_status=None
|
||||||
|
):
|
||||||
"""Reset volume statuses (admin operation)"""
|
"""Reset volume statuses (admin operation)"""
|
||||||
body = {
|
body: ty.Dict[str, ty.Dict[str, str]] = {'os-reset_status': {}}
|
||||||
'os-reset_status': {
|
if status:
|
||||||
'status': status,
|
body['os-reset_status']['status'] = status
|
||||||
'attach_status': attach_status,
|
if attach_status:
|
||||||
'migration_status': migration_status,
|
body['os-reset_status']['attach_status'] = attach_status
|
||||||
}
|
if migration_status:
|
||||||
}
|
body['os-reset_status']['migration_status'] = migration_status
|
||||||
self._action(session, body)
|
self._action(session, body)
|
||||||
|
|
||||||
def attach(self, session, mountpoint, instance):
|
def attach(self, session, mountpoint, instance):
|
||||||
|
@@ -771,7 +771,7 @@ class Proxy(_base_proxy.BaseBlockStorageProxy):
|
|||||||
volume.set_bootable_status(self, bootable)
|
volume.set_bootable_status(self, bootable)
|
||||||
|
|
||||||
def reset_volume_status(
|
def reset_volume_status(
|
||||||
self, volume, status, attach_status, migration_status
|
self, volume, status=None, attach_status=None, migration_status=None
|
||||||
):
|
):
|
||||||
"""Reset volume statuses.
|
"""Reset volume statuses.
|
||||||
|
|
||||||
|
@@ -10,6 +10,8 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
import typing as ty
|
||||||
|
|
||||||
from openstack.common import metadata
|
from openstack.common import metadata
|
||||||
from openstack import exceptions
|
from openstack import exceptions
|
||||||
from openstack import format
|
from openstack import format
|
||||||
@@ -138,15 +140,17 @@ class Volume(resource.Resource, metadata.MetadataMixin):
|
|||||||
body = {'os-update_readonly_flag': {'readonly': readonly}}
|
body = {'os-update_readonly_flag': {'readonly': readonly}}
|
||||||
self._action(session, body)
|
self._action(session, body)
|
||||||
|
|
||||||
def reset_status(self, session, status, attach_status, migration_status):
|
def reset_status(
|
||||||
|
self, session, status=None, attach_status=None, migration_status=None
|
||||||
|
):
|
||||||
"""Reset volume statuses (admin operation)"""
|
"""Reset volume statuses (admin operation)"""
|
||||||
body = {
|
body: ty.Dict[str, ty.Dict[str, str]] = {'os-reset_status': {}}
|
||||||
'os-reset_status': {
|
if status:
|
||||||
'status': status,
|
body['os-reset_status']['status'] = status
|
||||||
'attach_status': attach_status,
|
if attach_status:
|
||||||
'migration_status': migration_status,
|
body['os-reset_status']['attach_status'] = attach_status
|
||||||
}
|
if migration_status:
|
||||||
}
|
body['os-reset_status']['migration_status'] = migration_status
|
||||||
self._action(session, body)
|
self._action(session, body)
|
||||||
|
|
||||||
def revert_to_snapshot(self, session, snapshot_id):
|
def revert_to_snapshot(self, session, snapshot_id):
|
||||||
|
@@ -198,6 +198,21 @@ class TestVolumeActions(TestVolume):
|
|||||||
url, json=body, microversion=sot._max_microversion
|
url, json=body, microversion=sot._max_microversion
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_reset_status__single_option(self):
|
||||||
|
sot = volume.Volume(**VOLUME)
|
||||||
|
|
||||||
|
self.assertIsNone(sot.reset_status(self.sess, status='1'))
|
||||||
|
|
||||||
|
url = 'volumes/%s/action' % FAKE_ID
|
||||||
|
body = {
|
||||||
|
'os-reset_status': {
|
||||||
|
'status': '1',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.sess.post.assert_called_with(
|
||||||
|
url, json=body, microversion=sot._max_microversion
|
||||||
|
)
|
||||||
|
|
||||||
def test_attach_instance(self):
|
def test_attach_instance(self):
|
||||||
sot = volume.Volume(**VOLUME)
|
sot = volume.Volume(**VOLUME)
|
||||||
|
|
||||||
|
@@ -227,6 +227,21 @@ class TestVolumeActions(TestVolume):
|
|||||||
url, json=body, microversion=sot._max_microversion
|
url, json=body, microversion=sot._max_microversion
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_reset_status__single_option(self):
|
||||||
|
sot = volume.Volume(**VOLUME)
|
||||||
|
|
||||||
|
self.assertIsNone(sot.reset_status(self.sess, status='1'))
|
||||||
|
|
||||||
|
url = 'volumes/%s/action' % FAKE_ID
|
||||||
|
body = {
|
||||||
|
'os-reset_status': {
|
||||||
|
'status': '1',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.sess.post.assert_called_with(
|
||||||
|
url, json=body, microversion=sot._max_microversion
|
||||||
|
)
|
||||||
|
|
||||||
@mock.patch(
|
@mock.patch(
|
||||||
'openstack.utils.require_microversion',
|
'openstack.utils.require_microversion',
|
||||||
autospec=True,
|
autospec=True,
|
||||||
|
Reference in New Issue
Block a user