Add "volume backup set" command in volume v2
Add "volume backup set" command in volume v2 (v2 only) to set backup name, description and state Change-Id: If17e8457db9a4704fb5bb9c75921ed82fd0069cf Closes-Bug: #1613261
This commit is contained in:
parent
69c4f605ec
commit
ddf84429f2
@ -115,6 +115,37 @@ Restore volume backup
|
||||
|
||||
Volume to restore to (name or ID)
|
||||
|
||||
volume backup set
|
||||
-----------------
|
||||
|
||||
Set volume backup properties
|
||||
|
||||
.. program:: volume backup set
|
||||
.. code:: bash
|
||||
|
||||
os volume backup set
|
||||
[--name <name>]
|
||||
[--description <description>]
|
||||
[--state <state>]
|
||||
<backup>
|
||||
|
||||
.. option:: --name <name>
|
||||
|
||||
New backup name
|
||||
|
||||
.. option:: --description <description>
|
||||
|
||||
New backup description
|
||||
|
||||
.. option:: --state <state>
|
||||
|
||||
New backup state ("available" or "error") (admin only)
|
||||
|
||||
.. _backup_set-volume-backup:
|
||||
.. describe:: <backup>
|
||||
|
||||
Backup to modify (name or ID)
|
||||
|
||||
volume backup show
|
||||
------------------
|
||||
|
||||
|
@ -336,6 +336,75 @@ class TestBackupRestore(TestBackup):
|
||||
self.assertIsNone(result)
|
||||
|
||||
|
||||
class TestBackupSet(TestBackup):
|
||||
|
||||
backup = volume_fakes.FakeBackup.create_one_backup()
|
||||
|
||||
def setUp(self):
|
||||
super(TestBackupSet, self).setUp()
|
||||
|
||||
self.backups_mock.get.return_value = self.backup
|
||||
|
||||
# Get the command object to test
|
||||
self.cmd = backup.SetVolumeBackup(self.app, None)
|
||||
|
||||
def test_backup_set_name(self):
|
||||
arglist = [
|
||||
'--name', 'new_name',
|
||||
self.backup.id,
|
||||
]
|
||||
verifylist = [
|
||||
('name', 'new_name'),
|
||||
('backup', self.backup.id),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
# In base command class ShowOne in cliff, abstract method take_action()
|
||||
# returns nothing
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
self.backups_mock.update.assert_called_once_with(
|
||||
self.backup.id, **{'name': 'new_name'})
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_backup_set_state(self):
|
||||
arglist = [
|
||||
'--state', 'error',
|
||||
self.backup.id
|
||||
]
|
||||
verifylist = [
|
||||
('state', 'error'),
|
||||
('backup', self.backup.id)
|
||||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
self.backups_mock.reset_state.assert_called_once_with(
|
||||
self.backup.id, 'error')
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_backup_set_state_failed(self):
|
||||
self.backups_mock.reset_state.side_effect = exceptions.CommandError()
|
||||
arglist = [
|
||||
'--state', 'error',
|
||||
self.backup.id
|
||||
]
|
||||
verifylist = [
|
||||
('state', 'error'),
|
||||
('backup', self.backup.id)
|
||||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
try:
|
||||
self.cmd.take_action(parsed_args)
|
||||
self.fail('CommandError should be raised.')
|
||||
except exceptions.CommandError as e:
|
||||
self.assertEqual('One or more of the set operations failed',
|
||||
str(e))
|
||||
self.backups_mock.reset_state.assert_called_with(
|
||||
self.backup.id, 'error')
|
||||
|
||||
|
||||
class TestBackupShow(TestBackup):
|
||||
|
||||
backup = volume_fakes.FakeBackup.create_one_backup()
|
||||
|
@ -281,6 +281,65 @@ class RestoreBackup(RestoreVolumeBackup):
|
||||
return super(RestoreBackup, self).take_action(parsed_args)
|
||||
|
||||
|
||||
class SetVolumeBackup(command.Command):
|
||||
"""Set volume backup properties"""
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(SetVolumeBackup, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
"backup",
|
||||
metavar="<backup>",
|
||||
help=_("Backup to modify (name or ID)")
|
||||
)
|
||||
parser.add_argument(
|
||||
'--name',
|
||||
metavar='<name>',
|
||||
help=_('New backup name')
|
||||
)
|
||||
parser.add_argument(
|
||||
'--description',
|
||||
metavar='<description>',
|
||||
help=_('New backup description')
|
||||
)
|
||||
parser.add_argument(
|
||||
'--state',
|
||||
metavar='<state>',
|
||||
choices=['available', 'error'],
|
||||
help=_('New backup state ("available" or "error") (admin only)'),
|
||||
)
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
volume_client = self.app.client_manager.volume
|
||||
backup = utils.find_resource(volume_client.backups,
|
||||
parsed_args.backup)
|
||||
result = 0
|
||||
if parsed_args.state:
|
||||
try:
|
||||
volume_client.backups.reset_state(
|
||||
backup.id, parsed_args.state)
|
||||
except Exception as e:
|
||||
LOG.error(_("Failed to set backup state: %s"), e)
|
||||
result += 1
|
||||
|
||||
kwargs = {}
|
||||
if parsed_args.name:
|
||||
kwargs['name'] = parsed_args.name
|
||||
if parsed_args.description:
|
||||
kwargs['description'] = parsed_args.description
|
||||
if kwargs:
|
||||
try:
|
||||
volume_client.backups.update(backup.id, **kwargs)
|
||||
except Exception as e:
|
||||
LOG.error(_("Failed to update backup name "
|
||||
"or description: %s"), e)
|
||||
result += 1
|
||||
|
||||
if result > 0:
|
||||
raise exceptions.CommandError(_("One or more of the "
|
||||
"set operations failed"))
|
||||
|
||||
|
||||
class ShowVolumeBackup(command.ShowOne):
|
||||
"""Display volume backup details"""
|
||||
|
||||
|
4
releasenotes/notes/bug-1613261-290a64080fead6c0.yaml
Normal file
4
releasenotes/notes/bug-1613261-290a64080fead6c0.yaml
Normal file
@ -0,0 +1,4 @@
|
||||
---
|
||||
features:
|
||||
- Add ``volume backup set`` commands in volume v2.
|
||||
[Bug `1613261 <https://bugs.launchpad.net/python-openstackclient/+bug/1613261>`_]
|
@ -512,6 +512,7 @@ openstack.volume.v2 =
|
||||
volume_backup_delete = openstackclient.volume.v2.backup:DeleteVolumeBackup
|
||||
volume_backup_list = openstackclient.volume.v2.backup:ListVolumeBackup
|
||||
volume_backup_restore = openstackclient.volume.v2.backup:RestoreVolumeBackup
|
||||
volume_backup_set = openstackclient.volume.v2.backup:SetVolumeBackup
|
||||
volume_backup_show = openstackclient.volume.v2.backup:ShowVolumeBackup
|
||||
|
||||
volume_type_create = openstackclient.volume.v2.volume_type:CreateVolumeType
|
||||
|
Loading…
Reference in New Issue
Block a user