Skip to content

Commit 1b4605e

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Add "volume host failover" command"
2 parents c889751 + 55195ce commit 1b4605e

6 files changed

Lines changed: 89 additions & 4 deletions

File tree

doc/source/command-objects/volume-host.rst

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,28 @@ volume host
44

55
Volume v2
66

7+
volume host failover
8+
--------------------
9+
10+
Failover volume host to different backend
11+
12+
.. program:: volume host failover
13+
.. code:: bash
14+
15+
openstack volume host failover
16+
--volume-backend <backend-id>
17+
<host-name>
18+
19+
.. option:: --volume-backend <backend-id>
20+
21+
The ID of the volume backend replication
22+
target where the host will failover to (required)
23+
24+
.. _volume_host_failover-host-name:
25+
.. describe:: <host-name>
26+
27+
Name of volume host
28+
729
volume host set
830
---------------
931

@@ -18,13 +40,13 @@ Set volume host properties
1840
1941
.. option:: --enable
2042

21-
Thaw and enable the specified volume host
43+
Thaw and enable the specified volume host.
2244

2345
.. option:: --disable
2446

2547
Freeze and disable the specified volume host
2648

27-
.. _volume-host-set:
49+
.. _volume_host_set-host-name:
2850
.. describe:: <host-name>
2951

3052
Name of volume host

doc/source/commands.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ Those actions with an opposite action are noted in parens if applicable.
239239
* ``create`` (``delete``) - create a new occurrence of the specified object
240240
* ``delete`` (``create``) - delete specific occurrences of the specified objects
241241
* ``expand`` (``shrink``) - increase the capacity of a cluster
242+
* ``failover`` - failover volume host to different backend
242243
* ``issue`` (``revoke``) - issue a token
243244
* ``list`` - display summary information about multiple objects
244245
* ``lock`` (``unlock``) - lock one or more servers so that non-admin user won't be able to execute actions

openstackclient/tests/unit/volume/v2/test_volume_host.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def setUp(self):
3535
self.host_mock.freeze_host.return_value = None
3636
self.host_mock.thaw_host.return_value = None
3737

38+
# Get the command object to mock
3839
self.cmd = volume_host.SetVolumeHost(self.app, None)
3940

4041
def test_volume_host_set_nothing(self):
@@ -84,3 +85,33 @@ def test_volume_host_set_disable(self):
8485
self.host_mock.freeze_host.assert_called_with(self.service.host)
8586
self.host_mock.thaw_host.assert_not_called()
8687
self.assertIsNone(result)
88+
89+
90+
class TestVolumeHostFailover(TestVolumeHost):
91+
92+
service = host_fakes.FakeService.create_one_service()
93+
94+
def setUp(self):
95+
super(TestVolumeHostFailover, self).setUp()
96+
97+
self.host_mock.failover_host.return_value = None
98+
99+
# Get the command object to mock
100+
self.cmd = volume_host.FailoverVolumeHost(self.app, None)
101+
102+
def test_volume_host_failover(self):
103+
arglist = [
104+
'--volume-backend', 'backend_test',
105+
self.service.host,
106+
]
107+
verifylist = [
108+
('volume_backend', 'backend_test'),
109+
('host', self.service.host),
110+
]
111+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
112+
113+
result = self.cmd.take_action(parsed_args)
114+
115+
self.host_mock.failover_host.assert_called_with(
116+
self.service.host, 'backend_test')
117+
self.assertIsNone(result)

openstackclient/volume/v2/volume_host.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,31 @@
1919
from openstackclient.i18n import _
2020

2121

22+
class FailoverVolumeHost(command.Command):
23+
_description = _("Failover volume host to different backend")
24+
25+
def get_parser(self, prog_name):
26+
parser = super(FailoverVolumeHost, self).get_parser(prog_name)
27+
parser.add_argument(
28+
"host",
29+
metavar="<host-name>",
30+
help=_("Name of volume host")
31+
)
32+
parser.add_argument(
33+
"--volume-backend",
34+
metavar="<backend-id>",
35+
required=True,
36+
help=_("The ID of the volume backend replication "
37+
"target where the host will failover to (required)")
38+
)
39+
return parser
40+
41+
def take_action(self, parsed_args):
42+
service_client = self.app.client_manager.volume
43+
service_client.services.failover_host(parsed_args.host,
44+
parsed_args.volume_backend)
45+
46+
2247
class SetVolumeHost(command.Command):
2348
_description = _("Set volume host properties")
2449

@@ -33,12 +58,12 @@ def get_parser(self, prog_name):
3358
enabled_group.add_argument(
3459
"--disable",
3560
action="store_true",
36-
help=_("Freeze and disable the specified volume host.")
61+
help=_("Freeze and disable the specified volume host")
3762
)
3863
enabled_group.add_argument(
3964
"--enable",
4065
action="store_true",
41-
help=_("Thaw and enable the specified volume host.")
66+
help=_("Thaw and enable the specified volume host")
4267
)
4368
return parser
4469

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
features:
3+
- |
4+
Add ``volume host failover`` command.
5+
[Blueprint `cinder-command-support <https://blueprints.launchpad.net/python-openstackclient/+spec/cinder-command-support>`_]

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,7 @@ openstack.volume.v2 =
568568
volume_backup_set = openstackclient.volume.v2.backup:SetVolumeBackup
569569
volume_backup_show = openstackclient.volume.v2.backup:ShowVolumeBackup
570570

571+
volume_host_failover = openstackclient.volume.v2.volume_host:FailoverVolumeHost
571572
volume_host_set = openstackclient.volume.v2.volume_host:SetVolumeHost
572573

573574
volume_snapshot_create = openstackclient.volume.v2.volume_snapshot:CreateVolumeSnapshot

0 commit comments

Comments
 (0)