Skip to content

Commit 9ba2cca

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "volume: Add v3-specific volume host module"
2 parents 406b94b + 1e99fa2 commit 9ba2cca

3 files changed

Lines changed: 190 additions & 1 deletion

File tree

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
#
2+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
3+
# not use this file except in compliance with the License. You may obtain
4+
# a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11+
# License for the specific language governing permissions and limitations
12+
# under the License.
13+
14+
from openstackclient.tests.unit.volume.v3 import fakes as volume_fakes
15+
from openstackclient.volume.v3 import volume_host
16+
17+
18+
class TestVolumeHost(volume_fakes.TestVolume):
19+
def setUp(self):
20+
super().setUp()
21+
22+
self.host_mock = self.volume_client.services
23+
self.host_mock.reset_mock()
24+
25+
26+
class TestVolumeHostSet(TestVolumeHost):
27+
service = volume_fakes.create_one_service()
28+
29+
def setUp(self):
30+
super().setUp()
31+
32+
self.host_mock.freeze_host.return_value = None
33+
self.host_mock.thaw_host.return_value = None
34+
35+
# Get the command object to mock
36+
self.cmd = volume_host.SetVolumeHost(self.app, None)
37+
38+
def test_volume_host_set_nothing(self):
39+
arglist = [
40+
self.service.host,
41+
]
42+
verifylist = [
43+
('host', self.service.host),
44+
]
45+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
46+
result = self.cmd.take_action(parsed_args)
47+
48+
self.host_mock.freeze_host.assert_not_called()
49+
self.host_mock.thaw_host.assert_not_called()
50+
self.assertIsNone(result)
51+
52+
def test_volume_host_set_enable(self):
53+
arglist = [
54+
'--enable',
55+
self.service.host,
56+
]
57+
verifylist = [
58+
('enable', True),
59+
('host', self.service.host),
60+
]
61+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
62+
63+
result = self.cmd.take_action(parsed_args)
64+
65+
self.host_mock.thaw_host.assert_called_with(self.service.host)
66+
self.host_mock.freeze_host.assert_not_called()
67+
self.assertIsNone(result)
68+
69+
def test_volume_host_set_disable(self):
70+
arglist = [
71+
'--disable',
72+
self.service.host,
73+
]
74+
verifylist = [
75+
('disable', True),
76+
('host', self.service.host),
77+
]
78+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
79+
80+
result = self.cmd.take_action(parsed_args)
81+
82+
self.host_mock.freeze_host.assert_called_with(self.service.host)
83+
self.host_mock.thaw_host.assert_not_called()
84+
self.assertIsNone(result)
85+
86+
87+
class TestVolumeHostFailover(TestVolumeHost):
88+
service = volume_fakes.create_one_service()
89+
90+
def setUp(self):
91+
super().setUp()
92+
93+
self.host_mock.failover_host.return_value = None
94+
95+
# Get the command object to mock
96+
self.cmd = volume_host.FailoverVolumeHost(self.app, None)
97+
98+
def test_volume_host_failover(self):
99+
arglist = [
100+
'--volume-backend',
101+
'backend_test',
102+
self.service.host,
103+
]
104+
verifylist = [
105+
('volume_backend', 'backend_test'),
106+
('host', self.service.host),
107+
]
108+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
109+
110+
result = self.cmd.take_action(parsed_args)
111+
112+
self.host_mock.failover_host.assert_called_with(
113+
self.service.host, 'backend_test'
114+
)
115+
self.assertIsNone(result)
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#
2+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
3+
# not use this file except in compliance with the License. You may obtain
4+
# a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11+
# License for the specific language governing permissions and limitations
12+
# under the License.
13+
14+
"""Volume v3 host action implementations"""
15+
16+
import argparse
17+
18+
from openstackclient import command
19+
from openstackclient.i18n import _
20+
21+
22+
class FailoverVolumeHost(command.Command):
23+
_description = _("Failover volume host to different backend")
24+
25+
def get_parser(self, prog_name: str) -> argparse.ArgumentParser:
26+
parser = super().get_parser(prog_name)
27+
parser.add_argument(
28+
"host", metavar="<host-name>", help=_("Name of volume host")
29+
)
30+
parser.add_argument(
31+
"--volume-backend",
32+
metavar="<backend-id>",
33+
required=True,
34+
help=_(
35+
"The ID of the volume backend replication "
36+
"target where the host will failover to (required)"
37+
),
38+
)
39+
return parser
40+
41+
def take_action(self, parsed_args: argparse.Namespace) -> None:
42+
service_client = self.app.client_manager.volume
43+
service_client.services.failover_host(
44+
parsed_args.host, parsed_args.volume_backend
45+
)
46+
47+
48+
class SetVolumeHost(command.Command):
49+
_description = _("Set volume host properties")
50+
51+
def get_parser(self, prog_name: str) -> argparse.ArgumentParser:
52+
parser = super().get_parser(prog_name)
53+
parser.add_argument(
54+
"host", metavar="<host-name>", help=_("Name of volume host")
55+
)
56+
enabled_group = parser.add_mutually_exclusive_group()
57+
enabled_group.add_argument(
58+
"--disable",
59+
action="store_true",
60+
help=_("Freeze and disable the specified volume host"),
61+
)
62+
enabled_group.add_argument(
63+
"--enable",
64+
action="store_true",
65+
help=_("Thaw and enable the specified volume host"),
66+
)
67+
return parser
68+
69+
def take_action(self, parsed_args: argparse.Namespace) -> None:
70+
service_client = self.app.client_manager.volume
71+
if parsed_args.enable:
72+
service_client.services.thaw_host(parsed_args.host)
73+
if parsed_args.disable:
74+
service_client.services.freeze_host(parsed_args.host)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ volume_group_type_delete = "openstackclient.volume.v3.volume_group_type:DeleteVo
736736
volume_group_type_list = "openstackclient.volume.v3.volume_group_type:ListVolumeGroupType"
737737
volume_group_type_set = "openstackclient.volume.v3.volume_group_type:SetVolumeGroupType"
738738
volume_group_type_show = "openstackclient.volume.v3.volume_group_type:ShowVolumeGroupType"
739-
volume_host_set = "openstackclient.volume.v2.volume_host:SetVolumeHost"
739+
volume_host_set = "openstackclient.volume.v3.volume_host:SetVolumeHost"
740740
volume_message_delete = "openstackclient.volume.v3.volume_message:DeleteMessage"
741741
volume_message_list = "openstackclient.volume.v3.volume_message:ListMessages"
742742
volume_message_show = "openstackclient.volume.v3.volume_message:ShowMessage"

0 commit comments

Comments
 (0)