[OSC] Implement Availability Zones Command
This commit implements the following openstack share command: openstack share availability zone list Change-Id: I75d3c5441b82fb8f16896719544a81dd032cdd15
This commit is contained in:
parent
616f3acf60
commit
53275bec67
@ -88,3 +88,10 @@ share replicas
|
||||
|
||||
.. autoprogram-cliff:: openstack.share.v2
|
||||
:command: share replica *
|
||||
|
||||
========================
|
||||
share availability zones
|
||||
========================
|
||||
|
||||
.. autoprogram-cliff:: openstack.share.v2
|
||||
:command: share availability zone list
|
||||
|
40
manilaclient/osc/v2/availability_zones.py
Normal file
40
manilaclient/osc/v2/availability_zones.py
Normal file
@ -0,0 +1,40 @@
|
||||
# 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 oscutils
|
||||
|
||||
from manilaclient.common._i18n import _
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ShareAvailabilityZoneList(command.Lister):
|
||||
"""List all availability zones."""
|
||||
|
||||
_description = _("List all availability zones")
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(ShareAvailabilityZoneList, self).get_parser(
|
||||
prog_name)
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
share_client = self.app.client_manager.share
|
||||
availability_zones = share_client.availability_zones.list()
|
||||
|
||||
fields = ("Id", "Name", "Created At", "Updated At")
|
||||
|
||||
return (fields, (oscutils.get_item_properties
|
||||
(s, fields) for s in availability_zones))
|
@ -42,6 +42,7 @@ class FakeShareClient(object):
|
||||
self.share_export_locations.resource_class = (
|
||||
osc_fakes.FakeResource(None, {}))
|
||||
self.messages = mock.Mock()
|
||||
self.availability_zones = mock.Mock()
|
||||
|
||||
|
||||
class ManilaParseException(Exception):
|
||||
@ -649,3 +650,50 @@ class FakeShareReplica(object):
|
||||
share_replicas.append(
|
||||
FakeShareReplica.create_one_replica(attrs))
|
||||
return share_replicas
|
||||
|
||||
|
||||
class FakeShareAvailabilityZones(object):
|
||||
"""Fake one or more availability zones"""
|
||||
|
||||
@staticmethod
|
||||
def create_one_availability_zone(attrs=None):
|
||||
"""Create a fake share availability zone
|
||||
|
||||
:param Dictionary attrs:
|
||||
A dictionary with all attributes
|
||||
:return:
|
||||
A FakeResource object, with project_id, resource and so on
|
||||
"""
|
||||
|
||||
attrs = attrs or {}
|
||||
|
||||
availability_zone = {
|
||||
"id": 'id-' + uuid.uuid4().hex,
|
||||
"name": 'name-' + uuid.uuid4().hex,
|
||||
"created_at": 'time-' + uuid.uuid4().hex,
|
||||
"updated_at": 'time-' + uuid.uuid4().hex,
|
||||
}
|
||||
|
||||
availability_zone.update(attrs)
|
||||
availability_zone = osc_fakes.FakeResource(info=copy.deepcopy(
|
||||
availability_zone),
|
||||
loaded=True)
|
||||
return availability_zone
|
||||
|
||||
@staticmethod
|
||||
def create_share_availability_zones(attrs=None, count=2):
|
||||
"""Create multiple availability zones.
|
||||
|
||||
:param Dictionary attrs:
|
||||
A dictionary with all attributes
|
||||
:param Integer count:
|
||||
The number of share types to be faked
|
||||
:return:
|
||||
A list of FakeResource objects
|
||||
"""
|
||||
|
||||
availability_zones = []
|
||||
for n in range(0, count):
|
||||
availability_zones.append(
|
||||
FakeShareAvailabilityZones.create_one_availability_zone(attrs))
|
||||
return availability_zones
|
||||
|
54
manilaclient/tests/unit/osc/v2/test_availability_zones.py
Normal file
54
manilaclient/tests/unit/osc/v2/test_availability_zones.py
Normal file
@ -0,0 +1,54 @@
|
||||
# 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 oscutils
|
||||
|
||||
from manilaclient.osc.v2 import availability_zones as osc_availability_zones
|
||||
from manilaclient.tests.unit.osc.v2 import fakes as manila_fakes
|
||||
|
||||
|
||||
class TestAvailabilityZones(manila_fakes.TestShare):
|
||||
|
||||
def setUp(self):
|
||||
super(TestAvailabilityZones, self).setUp()
|
||||
|
||||
self.zones_mock = self.app.client_manager.share.availability_zones
|
||||
self.zones_mock.reset_mock()
|
||||
|
||||
|
||||
class TestShareAvailabilityZoneList(TestAvailabilityZones):
|
||||
|
||||
availability_zones = manila_fakes.FakeShareAvailabilityZones.\
|
||||
create_share_availability_zones()
|
||||
COLUMNS = ("Id", "Name", "Created At", "Updated At")
|
||||
|
||||
def setUp(self):
|
||||
super(TestShareAvailabilityZoneList, self).setUp()
|
||||
|
||||
self.zones_mock.list.return_value = self.availability_zones
|
||||
|
||||
# Get the command object to test
|
||||
self.cmd = osc_availability_zones.ShareAvailabilityZoneList(
|
||||
self.app, None)
|
||||
|
||||
self.values = (oscutils.get_dict_properties(
|
||||
s._info, self.COLUMNS) for s in self.availability_zones)
|
||||
|
||||
def test_share_list_availability_zone(self):
|
||||
arglist = []
|
||||
verifylist = []
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.assertEqual(self.COLUMNS, columns)
|
||||
self.assertCountEqual(list(self.values), list(data))
|
@ -89,6 +89,7 @@ openstack.share.v2 =
|
||||
share_replica_set = manilaclient.osc.v2.share_replicas:SetShareReplica
|
||||
share_replica_promote = manilaclient.osc.v2.share_replicas:PromoteShareReplica
|
||||
share_replica_resync = manilaclient.osc.v2.share_replicas:ResyncShareReplica
|
||||
share_availability_zone_list = manilaclient.osc.v2.availability_zones:ShareAvailabilityZoneList
|
||||
|
||||
[coverage:run]
|
||||
omit = manilaclient/tests/*
|
||||
|
Loading…
Reference in New Issue
Block a user