From 55195cec46fadd88f6151783b1e17557d5e94940 Mon Sep 17 00:00:00 2001 From: "zhiyong.dai" Date: Wed, 14 Dec 2016 21:14:17 +0800 Subject: [PATCH] Add "volume host failover" command Add "volume host failover" command in volume v2 (v2 only). Change-Id: Ia39e6d20bf5c9d3096e46f3432804a240827548d Implements: bp cinder-command-support --- doc/source/command-objects/volume-host.rst | 26 ++++++++++++++-- doc/source/commands.rst | 1 + .../tests/unit/volume/v2/test_volume_host.py | 31 +++++++++++++++++++ openstackclient/volume/v2/volume_host.py | 29 +++++++++++++++-- ...volume-host-failover-8fc77b24533b7fed.yaml | 5 +++ setup.cfg | 1 + 6 files changed, 89 insertions(+), 4 deletions(-) create mode 100644 releasenotes/notes/add-volume-host-failover-8fc77b24533b7fed.yaml diff --git a/doc/source/command-objects/volume-host.rst b/doc/source/command-objects/volume-host.rst index a225e53e58..1e513cb716 100644 --- a/doc/source/command-objects/volume-host.rst +++ b/doc/source/command-objects/volume-host.rst @@ -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 + + +.. option:: --volume-backend + + The ID of the volume backend replication + target where the host will failover to (required) + +.. _volume_host_failover-host-name: +.. describe:: + + 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:: Name of volume host diff --git a/doc/source/commands.rst b/doc/source/commands.rst index 206b18af3a..815a29bb3a 100644 --- a/doc/source/commands.rst +++ b/doc/source/commands.rst @@ -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 diff --git a/openstackclient/tests/unit/volume/v2/test_volume_host.py b/openstackclient/tests/unit/volume/v2/test_volume_host.py index aad7bb0bf4..b024329a1b 100644 --- a/openstackclient/tests/unit/volume/v2/test_volume_host.py +++ b/openstackclient/tests/unit/volume/v2/test_volume_host.py @@ -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) diff --git a/openstackclient/volume/v2/volume_host.py b/openstackclient/volume/v2/volume_host.py index 376e502491..2fdeb9684b 100644 --- a/openstackclient/volume/v2/volume_host.py +++ b/openstackclient/volume/v2/volume_host.py @@ -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="", + help=_("Name of volume host") + ) + parser.add_argument( + "--volume-backend", + metavar="", + 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 diff --git a/releasenotes/notes/add-volume-host-failover-8fc77b24533b7fed.yaml b/releasenotes/notes/add-volume-host-failover-8fc77b24533b7fed.yaml new file mode 100644 index 0000000000..8630f74251 --- /dev/null +++ b/releasenotes/notes/add-volume-host-failover-8fc77b24533b7fed.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + Add ``volume host failover`` command. + [Blueprint `cinder-command-support `_] diff --git a/setup.cfg b/setup.cfg index 8c5c663055..f184d03870 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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