Add "volume host failover" command

Add "volume host failover" command in volume v2 (v2 only).

Change-Id: Ia39e6d20bf5c9d3096e46f3432804a240827548d
Implements: bp cinder-command-support
This commit is contained in:
zhiyong.dai 2016-12-14 21:14:17 +08:00
parent 3816b4b90a
commit 55195cec46
6 changed files with 89 additions and 4 deletions

View File

@ -4,6 +4,28 @@ volume host
Volume v2
volume host failover
--------------------
Failover volume host to different backend
.. program:: volume host failover
.. code:: bash
openstack volume host failover
--volume-backend <backend-id>
<host-name>
.. option:: --volume-backend <backend-id>
The ID of the volume backend replication
target where the host will failover to (required)
.. _volume_host_failover-host-name:
.. describe:: <host-name>
Name of volume host
volume host set
---------------
@ -18,13 +40,13 @@ Set volume host properties
.. option:: --enable
Thaw and enable the specified volume host
Thaw and enable the specified volume host.
.. option:: --disable
Freeze and disable the specified volume host
.. _volume-host-set:
.. _volume_host_set-host-name:
.. describe:: <host-name>
Name of volume host

View File

@ -234,6 +234,7 @@ Those actions with an opposite action are noted in parens if applicable.
* ``create`` (``delete``) - create a new occurrence of the specified object
* ``delete`` (``create``) - delete specific occurrences of the specified objects
* ``expand`` (``shrink``) - increase the capacity of a cluster
* ``failover`` - failover volume host to different backend
* ``issue`` (``revoke``) - issue a token
* ``list`` - display summary information about multiple objects
* ``lock`` (``unlock``) - lock one or more servers so that non-admin user won't be able to execute actions

View File

@ -35,6 +35,7 @@ class TestVolumeHostSet(TestVolumeHost):
self.host_mock.freeze_host.return_value = None
self.host_mock.thaw_host.return_value = None
# Get the command object to mock
self.cmd = volume_host.SetVolumeHost(self.app, None)
def test_volume_host_set_nothing(self):
@ -84,3 +85,33 @@ class TestVolumeHostSet(TestVolumeHost):
self.host_mock.freeze_host.assert_called_with(self.service.host)
self.host_mock.thaw_host.assert_not_called()
self.assertIsNone(result)
class TestVolumeHostFailover(TestVolumeHost):
service = host_fakes.FakeService.create_one_service()
def setUp(self):
super(TestVolumeHostFailover, self).setUp()
self.host_mock.failover_host.return_value = None
# Get the command object to mock
self.cmd = volume_host.FailoverVolumeHost(self.app, None)
def test_volume_host_failover(self):
arglist = [
'--volume-backend', 'backend_test',
self.service.host,
]
verifylist = [
('volume_backend', 'backend_test'),
('host', self.service.host),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.take_action(parsed_args)
self.host_mock.failover_host.assert_called_with(
self.service.host, 'backend_test')
self.assertIsNone(result)

View File

@ -19,6 +19,31 @@ from osc_lib.command import command
from openstackclient.i18n import _
class FailoverVolumeHost(command.Command):
_description = _("Failover volume host to different backend")
def get_parser(self, prog_name):
parser = super(FailoverVolumeHost, self).get_parser(prog_name)
parser.add_argument(
"host",
metavar="<host-name>",
help=_("Name of volume host")
)
parser.add_argument(
"--volume-backend",
metavar="<backend-id>",
required=True,
help=_("The ID of the volume backend replication "
"target where the host will failover to (required)")
)
return parser
def take_action(self, parsed_args):
service_client = self.app.client_manager.volume
service_client.services.failover_host(parsed_args.host,
parsed_args.volume_backend)
class SetVolumeHost(command.Command):
_description = _("Set volume host properties")
@ -33,12 +58,12 @@ class SetVolumeHost(command.Command):
enabled_group.add_argument(
"--disable",
action="store_true",
help=_("Freeze and disable the specified volume host.")
help=_("Freeze and disable the specified volume host")
)
enabled_group.add_argument(
"--enable",
action="store_true",
help=_("Thaw and enable the specified volume host.")
help=_("Thaw and enable the specified volume host")
)
return parser

View File

@ -0,0 +1,5 @@
---
features:
- |
Add ``volume host failover`` command.
[Blueprint `cinder-command-support <https://blueprints.launchpad.net/python-openstackclient/+spec/cinder-command-support>`_]

View File

@ -548,6 +548,7 @@ openstack.volume.v2 =
volume_backup_set = openstackclient.volume.v2.backup:SetVolumeBackup
volume_backup_show = openstackclient.volume.v2.backup:ShowVolumeBackup
volume_host_failover = openstackclient.volume.v2.volume_host:FailoverVolumeHost
volume_host_set = openstackclient.volume.v2.volume_host:SetVolumeHost
volume_snapshot_create = openstackclient.volume.v2.volume_snapshot:CreateVolumeSnapshot