Merge "Add "volume service set" command"

This commit is contained in:
Jenkins 2016-09-06 03:40:31 +00:00 committed by Gerrit Code Review
commit 20ad61b9d4
7 changed files with 442 additions and 0 deletions

View File

@ -29,3 +29,37 @@ List volume service
.. option:: --long
List additional fields in output
volume service set
------------------
Set volume service properties
.. program:: volume service set
.. code:: bash
os volume service set
[--enable | --disable]
[--disable-reason <reason>]
<host> <service>
.. option:: --enable
Enable volume service
.. option:: --disable
Disable volume service
.. option:: --disable-reason <reason>
Reason for disabling the service (should be used with --disable option)
.. _volume-service-set:
.. describe:: <host>
Name of host
.. describe:: <service>
Name of service (Binary name)

View File

@ -12,6 +12,7 @@
# under the License.
#
from osc_lib import exceptions
from openstackclient.tests.volume.v1 import fakes as service_fakes
from openstackclient.volume.v1 import service
@ -139,3 +140,147 @@ class TestServiceList(TestService):
self.services.host,
self.services.binary,
)
class TestServiceSet(TestService):
service = service_fakes.FakeService.create_one_service()
def setUp(self):
super(TestServiceSet, self).setUp()
self.service_mock.enable.return_value = self.service
self.service_mock.disable.return_value = self.service
self.service_mock.disable_log_reason.return_value = self.service
self.cmd = service.SetService(self.app, None)
def test_service_set_nothing(self):
arglist = [
self.service.host,
self.service.binary,
]
verifylist = [
('host', self.service.host),
('service', self.service.binary),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.take_action(parsed_args)
self.service_mock.enable.assert_not_called()
self.service_mock.disable.assert_not_called()
self.service_mock.disable_log_reason.assert_not_called()
self.assertIsNone(result)
def test_service_set_enable(self):
arglist = [
'--enable',
self.service.host,
self.service.binary,
]
verifylist = [
('enable', True),
('host', self.service.host),
('service', self.service.binary),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.take_action(parsed_args)
self.service_mock.enable.assert_called_with(
self.service.host,
self.service.binary
)
self.service_mock.disable.assert_not_called()
self.service_mock.disable_log_reason.assert_not_called()
self.assertIsNone(result)
def test_service_set_disable(self):
arglist = [
'--disable',
self.service.host,
self.service.binary,
]
verifylist = [
('disable', True),
('host', self.service.host),
('service', self.service.binary),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.take_action(parsed_args)
self.service_mock.disable.assert_called_with(
self.service.host,
self.service.binary
)
self.service_mock.enable.assert_not_called()
self.service_mock.disable_log_reason.assert_not_called()
self.assertIsNone(result)
def test_service_set_disable_with_reason(self):
reason = 'earthquake'
arglist = [
'--disable',
'--disable-reason', reason,
self.service.host,
self.service.binary,
]
verifylist = [
('disable', True),
('disable_reason', reason),
('host', self.service.host),
('service', self.service.binary),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.take_action(parsed_args)
self.service_mock.disable_log_reason.assert_called_with(
self.service.host,
self.service.binary,
reason
)
self.assertIsNone(result)
def test_service_set_only_with_disable_reason(self):
reason = 'earthquake'
arglist = [
'--disable-reason', reason,
self.service.host,
self.service.binary,
]
verifylist = [
('disable_reason', reason),
('host', self.service.host),
('service', self.service.binary),
]
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("Cannot specify option --disable-reason without "
"--disable specified.", str(e))
def test_service_set_enable_with_disable_reason(self):
reason = 'earthquake'
arglist = [
'--enable',
'--disable-reason', reason,
self.service.host,
self.service.binary,
]
verifylist = [
('enable', True),
('disable_reason', reason),
('host', self.service.host),
('service', self.service.binary),
]
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("Cannot specify option --disable-reason without "
"--disable specified.", str(e))

View File

@ -12,6 +12,7 @@
# under the License.
#
from osc_lib import exceptions
from openstackclient.tests.volume.v2 import fakes as service_fakes
from openstackclient.volume.v2 import service
@ -139,3 +140,147 @@ class TestServiceList(TestService):
self.services.host,
self.services.binary,
)
class TestServiceSet(TestService):
service = service_fakes.FakeService.create_one_service()
def setUp(self):
super(TestServiceSet, self).setUp()
self.service_mock.enable.return_value = self.service
self.service_mock.disable.return_value = self.service
self.service_mock.disable_log_reason.return_value = self.service
self.cmd = service.SetService(self.app, None)
def test_service_set_nothing(self):
arglist = [
self.service.host,
self.service.binary,
]
verifylist = [
('host', self.service.host),
('service', self.service.binary),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.take_action(parsed_args)
self.service_mock.enable.assert_not_called()
self.service_mock.disable.assert_not_called()
self.service_mock.disable_log_reason.assert_not_called()
self.assertIsNone(result)
def test_service_set_enable(self):
arglist = [
'--enable',
self.service.host,
self.service.binary,
]
verifylist = [
('enable', True),
('host', self.service.host),
('service', self.service.binary),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.take_action(parsed_args)
self.service_mock.enable.assert_called_with(
self.service.host,
self.service.binary
)
self.service_mock.disable.assert_not_called()
self.service_mock.disable_log_reason.assert_not_called()
self.assertIsNone(result)
def test_service_set_disable(self):
arglist = [
'--disable',
self.service.host,
self.service.binary,
]
verifylist = [
('disable', True),
('host', self.service.host),
('service', self.service.binary),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.take_action(parsed_args)
self.service_mock.disable.assert_called_with(
self.service.host,
self.service.binary
)
self.service_mock.enable.assert_not_called()
self.service_mock.disable_log_reason.assert_not_called()
self.assertIsNone(result)
def test_service_set_disable_with_reason(self):
reason = 'earthquake'
arglist = [
'--disable',
'--disable-reason', reason,
self.service.host,
self.service.binary,
]
verifylist = [
('disable', True),
('disable_reason', reason),
('host', self.service.host),
('service', self.service.binary),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.take_action(parsed_args)
self.service_mock.disable_log_reason.assert_called_with(
self.service.host,
self.service.binary,
reason
)
self.assertIsNone(result)
def test_service_set_only_with_disable_reason(self):
reason = 'earthquake'
arglist = [
'--disable-reason', reason,
self.service.host,
self.service.binary,
]
verifylist = [
('disable_reason', reason),
('host', self.service.host),
('service', self.service.binary),
]
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("Cannot specify option --disable-reason without "
"--disable specified.", str(e))
def test_service_set_enable_with_disable_reason(self):
reason = 'earthquake'
arglist = [
'--enable',
'--disable-reason', reason,
self.service.host,
self.service.binary,
]
verifylist = [
('enable', True),
('disable_reason', reason),
('host', self.service.host),
('service', self.service.binary),
]
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("Cannot specify option --disable-reason without "
"--disable specified.", str(e))

View File

@ -15,6 +15,7 @@
"""Service action implementations"""
from osc_lib.command import command
from osc_lib import exceptions
from osc_lib import utils
from openstackclient.i18n import _
@ -72,3 +73,58 @@ class ListService(command.Lister):
(utils.get_item_properties(
s, columns,
) for s in data))
class SetService(command.Command):
"""Set volume service properties"""
def get_parser(self, prog_name):
parser = super(SetService, self).get_parser(prog_name)
parser.add_argument(
"host",
metavar="<host>",
help=_("Name of host")
)
parser.add_argument(
"service",
metavar="<service>",
help=_("Name of service (Binary name)")
)
enabled_group = parser.add_mutually_exclusive_group()
enabled_group.add_argument(
"--enable",
action="store_true",
help=_("Enable volume service")
)
enabled_group.add_argument(
"--disable",
action="store_true",
help=_("Disable volume service")
)
parser.add_argument(
"--disable-reason",
metavar="<reason>",
help=_("Reason for disabling the service "
"(should be used with --disable option)")
)
return parser
def take_action(self, parsed_args):
if parsed_args.disable_reason and not parsed_args.disable:
msg = _("Cannot specify option --disable-reason without "
"--disable specified.")
raise exceptions.CommandError(msg)
service_client = self.app.client_manager.volume
if parsed_args.enable:
service_client.services.enable(
parsed_args.host, parsed_args.service)
if parsed_args.disable:
if parsed_args.disable_reason:
service_client.services.disable_log_reason(
parsed_args.host,
parsed_args.service,
parsed_args.disable_reason)
else:
service_client.services.disable(
parsed_args.host, parsed_args.service)

View File

@ -15,6 +15,7 @@
"""Service action implementations"""
from osc_lib.command import command
from osc_lib import exceptions
from osc_lib import utils
from openstackclient.i18n import _
@ -72,3 +73,58 @@ class ListService(command.Lister):
(utils.get_item_properties(
s, columns,
) for s in data))
class SetService(command.Command):
"""Set volume service properties"""
def get_parser(self, prog_name):
parser = super(SetService, self).get_parser(prog_name)
parser.add_argument(
"host",
metavar="<host>",
help=_("Name of host")
)
parser.add_argument(
"service",
metavar="<service>",
help=_("Name of service (Binary name)")
)
enabled_group = parser.add_mutually_exclusive_group()
enabled_group.add_argument(
"--enable",
action="store_true",
help=_("Enable volume service")
)
enabled_group.add_argument(
"--disable",
action="store_true",
help=_("Disable volume service")
)
parser.add_argument(
"--disable-reason",
metavar="<reason>",
help=_("Reason for disabling the service "
"(should be used with --disable option)")
)
return parser
def take_action(self, parsed_args):
if parsed_args.disable_reason and not parsed_args.disable:
msg = _("Cannot specify option --disable-reason without "
"--disable specified.")
raise exceptions.CommandError(msg)
service_client = self.app.client_manager.volume
if parsed_args.enable:
service_client.services.enable(
parsed_args.host, parsed_args.service)
if parsed_args.disable:
if parsed_args.disable_reason:
service_client.services.disable_log_reason(
parsed_args.host,
parsed_args.service,
parsed_args.disable_reason)
else:
service_client.services.disable(
parsed_args.host, parsed_args.service)

View File

@ -0,0 +1,4 @@
---
features:
- Add ``volume service set`` commands in volume v1 and v2.
[Bug `1613597 <https://bugs.launchpad.net/python-openstackclient/+bug/1613597>`_]

View File

@ -481,6 +481,7 @@ openstack.volume.v1 =
volume_qos_unset = openstackclient.volume.v1.qos_specs:UnsetQos
volume_service_list = openstackclient.volume.v1.service:ListService
volume_service_set = openstackclient.volume.v1.service:SetService
volume_transfer_request_list = openstackclient.volume.v1.volume_transfer_request:ListTransferRequests
@ -528,6 +529,7 @@ openstack.volume.v2 =
volume_qos_unset = openstackclient.volume.v2.qos_specs:UnsetQos
volume_service_list = openstackclient.volume.v2.service:ListService
volume_service_set = openstackclient.volume.v2.service:SetService
volume_transfer_request_list = openstackclient.volume.v2.volume_transfer_request:ListTransferRequests