Add ensure shares command
Added a new command to trigger the ensure shares API. Change-Id: If40328c83ec4c87d727aceac89a1a14b9fd8a25d Signed-off-by: Carlos Eduardo <ces.eduardo98@gmail.com>
This commit is contained in:
parent
e34c55c5ac
commit
baa0091d53
@ -151,8 +151,40 @@ class ListShareService(command.Lister):
|
|||||||
]
|
]
|
||||||
if share_client.api_version >= api_versions.APIVersion("2.83"):
|
if share_client.api_version >= api_versions.APIVersion("2.83"):
|
||||||
columns.append('Disabled Reason')
|
columns.append('Disabled Reason')
|
||||||
|
if share_client.api_version >= api_versions.APIVersion("2.86"):
|
||||||
|
columns.append('Ensuring')
|
||||||
|
|
||||||
data = (osc_utils.get_dict_properties(
|
data = (osc_utils.get_dict_properties(
|
||||||
service._info, columns) for service in services)
|
service._info, columns) for service in services)
|
||||||
|
|
||||||
return (columns, data)
|
return (columns, data)
|
||||||
|
|
||||||
|
|
||||||
|
class EnsureShareService(command.Command):
|
||||||
|
"""Run ensure shares in a back end (Admin only)."""
|
||||||
|
_description = _("Run ensure shares in a back end (Admin only).")
|
||||||
|
|
||||||
|
def get_parser(self, prog_name):
|
||||||
|
parser = super(EnsureShareService, self).get_parser(prog_name)
|
||||||
|
parser.add_argument(
|
||||||
|
'host',
|
||||||
|
metavar='<host>',
|
||||||
|
help=_("Host to run ensure shares. "
|
||||||
|
"'example_host@example_backend'.")
|
||||||
|
)
|
||||||
|
return parser
|
||||||
|
|
||||||
|
def take_action(self, parsed_args):
|
||||||
|
share_client = self.app.client_manager.share
|
||||||
|
|
||||||
|
if share_client.api_version < api_versions.APIVersion("2.86"):
|
||||||
|
raise exceptions.CommandError(
|
||||||
|
"Ensure shares API is only available in "
|
||||||
|
"manila API version >= 2.86")
|
||||||
|
|
||||||
|
try:
|
||||||
|
share_client.services.ensure_shares(parsed_args.host)
|
||||||
|
except Exception as e:
|
||||||
|
raise exceptions.CommandError(
|
||||||
|
_("Failed to run ensure shares: %s" % e)
|
||||||
|
)
|
||||||
|
@ -266,3 +266,61 @@ class TestShareServiceList(TestShareService):
|
|||||||
else:
|
else:
|
||||||
self.assertEqual(self.column_headers, columns)
|
self.assertEqual(self.column_headers, columns)
|
||||||
self.assertEqual(list(self.values), list(data))
|
self.assertEqual(list(self.values), list(data))
|
||||||
|
|
||||||
|
|
||||||
|
@ddt.ddt
|
||||||
|
class TestShareServiceEnsureShares(TestShareService):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(TestShareServiceEnsureShares, self).setUp()
|
||||||
|
|
||||||
|
self.cmd = osc_services.EnsureShareService(self.app, None)
|
||||||
|
|
||||||
|
def test_ensure_shares(self):
|
||||||
|
self.app.client_manager.share.api_version = api_versions.APIVersion(
|
||||||
|
'2.86')
|
||||||
|
fake_host = 'fake_host@fakebackend'
|
||||||
|
arglist = [
|
||||||
|
fake_host,
|
||||||
|
]
|
||||||
|
verifylist = [
|
||||||
|
('host', fake_host),
|
||||||
|
]
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
|
self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
|
self.services_mock.ensure_shares.assert_called_with(fake_host)
|
||||||
|
|
||||||
|
def test_ensure_shares_invalid_version(self):
|
||||||
|
self.app.client_manager.share.api_version = api_versions.APIVersion(
|
||||||
|
'2.85')
|
||||||
|
fake_host = 'fake_host@fakebackend'
|
||||||
|
arglist = [
|
||||||
|
fake_host,
|
||||||
|
]
|
||||||
|
verifylist = [
|
||||||
|
('host', fake_host),
|
||||||
|
]
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
|
self.assertRaises(exceptions.CommandError,
|
||||||
|
self.cmd.take_action,
|
||||||
|
parsed_args)
|
||||||
|
|
||||||
|
def test_ensure_shares_command_error(self):
|
||||||
|
self.app.client_manager.share.api_version = api_versions.APIVersion(
|
||||||
|
'2.86')
|
||||||
|
self.services_mock.ensure_shares.side_effect = Exception()
|
||||||
|
fake_host = 'fake_host@fakebackend'
|
||||||
|
arglist = [
|
||||||
|
fake_host,
|
||||||
|
]
|
||||||
|
verifylist = [
|
||||||
|
('host', fake_host),
|
||||||
|
]
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
|
self.assertRaises(exceptions.CommandError,
|
||||||
|
self.cmd.take_action,
|
||||||
|
parsed_args)
|
||||||
|
@ -98,3 +98,13 @@ class ServicesTest(utils.TestCase):
|
|||||||
self._get_resource_path(microversion) + '/disable',
|
self._get_resource_path(microversion) + '/disable',
|
||||||
{"host": host, "binary": binary},
|
{"host": host, "binary": binary},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_ensure_shares(self):
|
||||||
|
microversion = '2.86'
|
||||||
|
manager = self._get_manager(microversion)
|
||||||
|
manager.api.client.post = mock.Mock(return_value='fake')
|
||||||
|
host = 'fake_host'
|
||||||
|
|
||||||
|
result = manager.ensure_shares(host)
|
||||||
|
|
||||||
|
self.assertEqual(result, 'fake')
|
||||||
|
@ -87,6 +87,12 @@ class ServiceManager(base.Manager):
|
|||||||
return self._do_disable(host, binary, RESOURCE_PATH,
|
return self._do_disable(host, binary, RESOURCE_PATH,
|
||||||
disable_reason=disable_reason)
|
disable_reason=disable_reason)
|
||||||
|
|
||||||
|
@api_versions.wraps("2.86")
|
||||||
|
def ensure_shares(self, host): # noqa
|
||||||
|
resource_path = f'{RESOURCE_PATH}/ensure_shares'
|
||||||
|
body = {"host": host}
|
||||||
|
return self.api.client.post(resource_path, body=body)
|
||||||
|
|
||||||
def server_api_version(self, url_append=""):
|
def server_api_version(self, url_append=""):
|
||||||
"""Returns the API Version supported by the server.
|
"""Returns the API Version supported by the server.
|
||||||
|
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
features:
|
||||||
|
- |
|
||||||
|
Starting from API version 2.86, it is possible to run ensure shares
|
||||||
|
on a given manila-share host, in order to update the shares
|
||||||
|
information.
|
@ -115,6 +115,7 @@ openstack.share.v2 =
|
|||||||
share_availability_zone_list = manilaclient.osc.v2.availability_zones:ShareAvailabilityZoneList
|
share_availability_zone_list = manilaclient.osc.v2.availability_zones:ShareAvailabilityZoneList
|
||||||
share_service_set = manilaclient.osc.v2.services:SetShareService
|
share_service_set = manilaclient.osc.v2.services:SetShareService
|
||||||
share_service_list = manilaclient.osc.v2.services:ListShareService
|
share_service_list = manilaclient.osc.v2.services:ListShareService
|
||||||
|
share_service_ensure_shares = manilaclient.osc.v2.services:EnsureShareService
|
||||||
share_security_service_create = manilaclient.osc.v2.security_services:CreateShareSecurityService
|
share_security_service_create = manilaclient.osc.v2.security_services:CreateShareSecurityService
|
||||||
share_security_service_delete = manilaclient.osc.v2.security_services:DeleteShareSecurityService
|
share_security_service_delete = manilaclient.osc.v2.security_services:DeleteShareSecurityService
|
||||||
share_security_service_show = manilaclient.osc.v2.security_services:ShowShareSecurityService
|
share_security_service_show = manilaclient.osc.v2.security_services:ShowShareSecurityService
|
||||||
|
Loading…
Reference in New Issue
Block a user