Implement OSC share instance export location commands

In this patch we add openstack commands for:
- share instance export location show
- share instance export location list

Co-authored-by: Eduardo Santos <eduardo.experimental@gmail.com>
Partially-implements: bp openstack-client-support
Change-Id: Ic1b5616a363059a941caa3cce6bd2b24bd379068
This commit is contained in:
Nahim Alves de Souza 2021-08-19 17:48:54 -03:00 committed by Goutham Pacha Ravi
parent d40205a2f2
commit 92ca00cd64
5 changed files with 300 additions and 3 deletions

View File

@ -52,7 +52,7 @@ share instances
===============
.. autoprogram-cliff:: openstack.share.v2
:command: share instance *
:command: share instance [!e]*
==================
share access rules
@ -137,3 +137,10 @@ share limits
.. autoprogram-cliff:: openstack.share.v2
:command: share limits *
==============================
share instance export location
==============================
.. autoprogram-cliff:: openstack.share.v2
:command: share instance export location *

View File

@ -0,0 +1,102 @@
# Copyright 2021 NetApp, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import logging
from osc_lib.command import command
from osc_lib import utils as osc_utils
from manilaclient.common._i18n import _
LOG = logging.getLogger(__name__)
class ShareInstanceListExportLocation(command.Lister):
"""List share instance export locations."""
_description = _("List share instance export locations")
def get_parser(self, prog_name):
parser = super(
ShareInstanceListExportLocation, self).get_parser(prog_name)
parser.add_argument(
"instance",
metavar="<instance>",
help=_("ID of the share instance.")
)
return parser
def take_action(self, parsed_args):
share_client = self.app.client_manager.share
instance = osc_utils.find_resource(
share_client.share_instances,
parsed_args.instance)
export_locations = share_client.share_instance_export_locations.list(
instance,
search_opts=None)
columns = [
'ID',
'Path',
'Is Admin Only',
'Preferred',
]
data = (
osc_utils.get_dict_properties(export_location._info, columns)
for export_location in export_locations
)
return (columns, data)
class ShareInstanceShowExportLocation(command.ShowOne):
"""Display the export location for a share instance."""
_description = _(
"Show export location for a share instance.")
def get_parser(self, prog_name):
parser = super(
ShareInstanceShowExportLocation, self).get_parser(prog_name)
parser.add_argument(
"instance",
metavar="<instance>",
help=_("Name or ID of the share instance")
)
parser.add_argument(
"export_location",
metavar="<export_location>",
help=_("ID of the share instance export location.")
)
return parser
def take_action(self, parsed_args):
share_client = self.app.client_manager.share
share_instance = osc_utils.find_resource(
share_client.share_instances,
parsed_args.instance)
share_instance_export_locations = (
share_client.share_instance_export_locations.get(
share_instance.id,
parsed_args.export_location)
)
data = share_instance_export_locations._info
data.pop('links', None)
return self.dict2columns(data)

View File

@ -327,6 +327,27 @@ class FakeShareExportLocation(object):
loaded=True)
return share_export_location
@staticmethod
def create_share_export_locations(attrs=None, count=2):
"""Create multiple fake export locations.
:param Dictionary attrs:
A dictionary with all attributes
:param Integer count:
The number of share export locations to be faked
:return:
A list of FakeResource objects
"""
share_export_locations = []
for n in range(0, count):
share_export_locations.append(
FakeShareExportLocation.
create_one_export_location(attrs))
return share_export_locations
class FakeShareAccessRule(object):
"""Fake one or more share access rules"""
@ -796,6 +817,7 @@ class FakeShareAvailabilityZones(object):
@staticmethod
def create_share_availability_zones(attrs=None, count=2):
"""Create multiple availability zones.
:param Dictionary attrs:
@ -923,7 +945,6 @@ class FakeShareInstance(object):
:return:
A FakeResource object, with project_id, resource and so on
"""
attrs = attrs or {}
methods = methods or {}
@ -960,7 +981,6 @@ class FakeShareInstance(object):
:return:
A list of FakeResource objects
"""
share_instances = []
for n in range(count):
share_instances.append(

View File

@ -0,0 +1,166 @@
# Copyright 2021 NetApp, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from osc_lib import utils as osc_lib_utils
from manilaclient.osc.v2 \
import share_instance_export_locations \
as osc_share_instance_export_locations
from manilaclient.tests.unit.osc import osc_utils
from manilaclient.tests.unit.osc.v2 import fakes as manila_fakes
class TestShareInstanceExportLocation(manila_fakes.TestShare):
def setUp(self):
super(TestShareInstanceExportLocation, self).setUp()
self.instances_mock = self.app.client_manager.share.share_instances
self.instances_mock.reset_mock()
self.instance_export_locations_mock = (
self.app.client_manager.share.share_instance_export_locations
)
self.instance_export_locations_mock.reset_mock()
class TestShareInstanceExportLocationList(TestShareInstanceExportLocation):
column_headers = [
'ID',
'Path',
'Is Admin Only',
'Preferred',
]
def setUp(self):
super(TestShareInstanceExportLocationList, self).setUp()
self.instance = (
manila_fakes.FakeShareInstance.create_one_share_instance()
)
self.instances_mock.get.return_value = self.instance
self.instance_export_locations = (
manila_fakes.FakeShareExportLocation.
create_share_export_locations()
)
self.instance_export_locations_mock.list.return_value = \
self.instance_export_locations
self.data = (osc_lib_utils.get_dict_properties(
i._info, self.column_headers)
for i in self.instance_export_locations)
self.cmd = (
osc_share_instance_export_locations.
ShareInstanceListExportLocation(self.app, None)
)
def test_share_instance_export_locations_list_missing_args(self):
arglist = []
verifylist = []
self.assertRaises(
osc_utils.ParserException,
self.check_parser, self.cmd, arglist, verifylist)
def test_share_instance_export_locations_list(self):
arglist = [
self.instance.id
]
verifylist = [
('instance', self.instance.id)
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
self.instances_mock.get.assert_called_with(
self.instance.id
)
self.instance_export_locations_mock.list.assert_called_with(
self.instance,
search_opts=None
)
self.assertCountEqual(self.column_headers, columns)
self.assertCountEqual(self.data, data)
class TestShareInstanceExportLocationShow(TestShareInstanceExportLocation):
def setUp(self):
super(TestShareInstanceExportLocationShow, self).setUp()
self.share_instance_export_locations = (
manila_fakes.FakeShareExportLocation.
create_one_export_location()
)
self.instance_export_locations_mock.get.return_value = \
self.share_instance_export_locations
self.instance = (
manila_fakes.FakeShareInstance.create_one_share_instance()
)
self.instances_mock.get.return_value = self.instance
self.cmd = (
osc_share_instance_export_locations.
ShareInstanceShowExportLocation(self.app, None)
)
self.data = tuple(self.share_instance_export_locations._info.values())
self.columns = tuple(self.share_instance_export_locations._info.keys())
def test_share_instance_export_locations_show_missing_args(self):
arglist = []
verifylist = []
self.assertRaises(
osc_utils.ParserException,
self.check_parser, self.cmd, arglist, verifylist)
def test_share_instance_export_locations_show(self):
arglist = [
self.instance.id,
self.share_instance_export_locations.id,
]
verifylist = [
('instance', self.instance.id),
('export_location', self.share_instance_export_locations.id)
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
self.instances_mock.get.assert_called_with(
self.instance.id
)
self.instance_export_locations_mock.get.assert_called_with(
self.instance.id,
self.share_instance_export_locations.id
)
self.assertCountEqual(self.columns, columns)
self.assertCountEqual(self.data, data)

View File

@ -104,6 +104,8 @@ openstack.share.v2 =
share_instance_list = manilaclient.osc.v2.share_instances:ShareInstanceList
share_instance_set = manilaclient.osc.v2.share_instances:ShareInstanceSet
share_instance_show = manilaclient.osc.v2.share_instances:ShareInstanceShow
share_instance_export_location_show = manilaclient.osc.v2.share_instance_export_locations:ShareInstanceShowExportLocation
share_instance_export_location_list = manilaclient.osc.v2.share_instance_export_locations:ShareInstanceListExportLocation
share_limits_show = manilaclient.osc.v2.share_limits:ShareLimitsShow
share_network_list = manilaclient.osc.v2.share_networks:ListShareNetwork
share_network_show = manilaclient.osc.v2.share_networks:ShowShareNetwork