Migrate volume backend commands to SDK
This patch migrates following volume backend commands to SDK: volume backend capability show volume backend pool list Change-Id: Idded38a5f87d51574426c4ac10c806af52984b7c
This commit is contained in:
parent
98fb1678bc
commit
39a084f91c
@ -21,6 +21,8 @@ import uuid
|
||||
from cinderclient import api_versions
|
||||
from openstack.block_storage.v2 import _proxy as block_storage_v2_proxy
|
||||
from openstack.block_storage.v3 import backup as _backup
|
||||
from openstack.block_storage.v3 import capabilities as _capabilities
|
||||
from openstack.block_storage.v3 import stats as _stats
|
||||
from openstack.block_storage.v3 import volume as _volume
|
||||
from openstack.image.v2 import _proxy as image_v2_proxy
|
||||
from osc_lib.cli import format_columns
|
||||
@ -301,7 +303,7 @@ def create_one_capability(attrs=None):
|
||||
# Overwrite default attributes if there are some attributes set
|
||||
capability_info.update(attrs or {})
|
||||
|
||||
capability = fakes.FakeResource(None, capability_info, loaded=True)
|
||||
capability = _capabilities.Capabilities(**capability_info)
|
||||
|
||||
return capability
|
||||
|
||||
@ -317,19 +319,21 @@ def create_one_pool(attrs=None):
|
||||
# Set default attribute
|
||||
pool_info = {
|
||||
'name': 'host@lvmdriver-1#lvmdriver-1',
|
||||
'storage_protocol': 'iSCSI',
|
||||
'thick_provisioning_support': False,
|
||||
'thin_provisioning_support': True,
|
||||
'total_volumes': 99,
|
||||
'total_capacity_gb': 1000.00,
|
||||
'allocated_capacity_gb': 100,
|
||||
'max_over_subscription_ratio': 200.0,
|
||||
'capabilities': {
|
||||
'storage_protocol': 'iSCSI',
|
||||
'thick_provisioning_support': False,
|
||||
'thin_provisioning_support': True,
|
||||
'total_volumes': 99,
|
||||
'total_capacity_gb': 1000.00,
|
||||
'allocated_capacity_gb': 100,
|
||||
'max_over_subscription_ratio': 200.0,
|
||||
},
|
||||
}
|
||||
|
||||
# Overwrite default attributes if there are some attributes set
|
||||
pool_info.update(attrs or {})
|
||||
|
||||
pool = fakes.FakeResource(None, pool_info, loaded=True)
|
||||
pool = _stats.Pools(**pool_info)
|
||||
|
||||
return pool
|
||||
|
||||
|
@ -12,6 +12,8 @@
|
||||
# under the License.
|
||||
#
|
||||
|
||||
from osc_lib.cli import format_columns
|
||||
|
||||
from openstackclient.tests.unit.volume.v2 import fakes as volume_fakes
|
||||
from openstackclient.volume.v2 import volume_backend
|
||||
|
||||
@ -25,9 +27,8 @@ class TestShowVolumeCapability(volume_fakes.TestVolume):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
|
||||
# Get a shortcut to the capability Mock
|
||||
self.capability_mock = self.volume_client.capabilities
|
||||
self.capability_mock.get.return_value = self.capability
|
||||
# Assign return value to capabilities mock
|
||||
self.volume_sdk_client.get_capabilities.return_value = self.capability
|
||||
|
||||
# Get the command object to test
|
||||
self.cmd = volume_backend.ShowCapability(self.app, None)
|
||||
@ -68,7 +69,7 @@ class TestShowVolumeCapability(volume_fakes.TestVolume):
|
||||
self.assertIn(cap[0], capabilities)
|
||||
|
||||
# checking if proper call was made to get capabilities
|
||||
self.capability_mock.get.assert_called_with(
|
||||
self.volume_sdk_client.get_capabilities.assert_called_with(
|
||||
'fake',
|
||||
)
|
||||
|
||||
@ -82,8 +83,7 @@ class TestListVolumePool(volume_fakes.TestVolume):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
|
||||
self.pool_mock = self.volume_client.pools
|
||||
self.pool_mock.list.return_value = [self.pools]
|
||||
self.volume_sdk_client.backend_pools.return_value = [self.pools]
|
||||
|
||||
# Get the command object to test
|
||||
self.cmd = volume_backend.ListPool(self.app, None)
|
||||
@ -111,7 +111,7 @@ class TestListVolumePool(volume_fakes.TestVolume):
|
||||
self.assertEqual(datalist, tuple(data))
|
||||
|
||||
# checking if proper call was made to list pools
|
||||
self.pool_mock.list.assert_called_with(
|
||||
self.volume_sdk_client.backend_pools.assert_called_with(
|
||||
detailed=False,
|
||||
)
|
||||
|
||||
@ -131,13 +131,7 @@ class TestListVolumePool(volume_fakes.TestVolume):
|
||||
|
||||
expected_columns = [
|
||||
'Name',
|
||||
'Protocol',
|
||||
'Thick',
|
||||
'Thin',
|
||||
'Volumes',
|
||||
'Capacity',
|
||||
'Allocated',
|
||||
'Max Over Ratio',
|
||||
'Capabilities',
|
||||
]
|
||||
|
||||
# confirming if all expected columns are present in the result.
|
||||
@ -146,19 +140,13 @@ class TestListVolumePool(volume_fakes.TestVolume):
|
||||
datalist = (
|
||||
(
|
||||
self.pools.name,
|
||||
self.pools.storage_protocol,
|
||||
self.pools.thick_provisioning_support,
|
||||
self.pools.thin_provisioning_support,
|
||||
self.pools.total_volumes,
|
||||
self.pools.total_capacity_gb,
|
||||
self.pools.allocated_capacity_gb,
|
||||
self.pools.max_over_subscription_ratio,
|
||||
format_columns.DictColumn(self.pools.capabilities),
|
||||
),
|
||||
)
|
||||
|
||||
# confirming if all expected values are present in the result.
|
||||
self.assertEqual(datalist, tuple(data))
|
||||
|
||||
self.pool_mock.list.assert_called_with(
|
||||
self.volume_sdk_client.backend_pools.assert_called_with(
|
||||
detailed=True,
|
||||
)
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
"""Storage backend action implementations"""
|
||||
|
||||
from osc_lib.cli import format_columns
|
||||
from osc_lib.command import command
|
||||
from osc_lib import utils
|
||||
|
||||
@ -33,7 +34,7 @@ class ShowCapability(command.Lister):
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
volume_client = self.app.client_manager.volume
|
||||
volume_client = self.app.client_manager.sdk_connection.volume
|
||||
|
||||
columns = [
|
||||
'Title',
|
||||
@ -42,7 +43,7 @@ class ShowCapability(command.Lister):
|
||||
'Description',
|
||||
]
|
||||
|
||||
data = volume_client.capabilities.get(parsed_args.host)
|
||||
data = volume_client.get_capabilities(parsed_args.host)
|
||||
|
||||
# The get capabilities API is... interesting. We only want the names of
|
||||
# the capabilities that can set for a backend through extra specs, so
|
||||
@ -83,28 +84,17 @@ class ListPool(command.Lister):
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
volume_client = self.app.client_manager.volume
|
||||
volume_client = self.app.client_manager.sdk_connection.volume
|
||||
|
||||
if parsed_args.long:
|
||||
columns = [
|
||||
'name',
|
||||
'storage_protocol',
|
||||
'thick_provisioning_support',
|
||||
'thin_provisioning_support',
|
||||
'total_volumes',
|
||||
'total_capacity_gb',
|
||||
'allocated_capacity_gb',
|
||||
'max_over_subscription_ratio',
|
||||
'capabilities',
|
||||
]
|
||||
|
||||
headers = [
|
||||
'Name',
|
||||
'Protocol',
|
||||
'Thick',
|
||||
'Thin',
|
||||
'Volumes',
|
||||
'Capacity',
|
||||
'Allocated',
|
||||
'Max Over Ratio',
|
||||
'Capabilities',
|
||||
]
|
||||
else:
|
||||
columns = [
|
||||
@ -112,13 +102,15 @@ class ListPool(command.Lister):
|
||||
]
|
||||
headers = columns
|
||||
|
||||
data = volume_client.pools.list(detailed=parsed_args.long)
|
||||
data = volume_client.backend_pools(detailed=parsed_args.long)
|
||||
formatters = {'capabilities': format_columns.DictColumn}
|
||||
return (
|
||||
headers,
|
||||
(
|
||||
utils.get_item_properties(
|
||||
s,
|
||||
columns,
|
||||
formatters=formatters,
|
||||
)
|
||||
for s in data
|
||||
),
|
||||
|
@ -0,0 +1,7 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
Migrated following volume backends commands to SDK.
|
||||
|
||||
* Capability Show
|
||||
* Pool List
|
Loading…
Reference in New Issue
Block a user