Unify QoSSpecs returned data

As far as possible, we need to return the unified data, and do not
contain those methods of returned class, ensure that is only interface
which is provided by service class.

Change-Id: I90aa6066c3539603e22e8898996d47bb39d3e917
This commit is contained in:
chenhb-zte 2017-04-24 12:34:13 +08:00
parent 4c340647d7
commit 6c933dd4ad
3 changed files with 31 additions and 6 deletions

View File

@ -34,6 +34,7 @@ VolumeTransfer = collections.namedtuple("VolumeTransfer", ["id", "name",
"auth_key"])
VolumeEncryptionType = collections.namedtuple("VolumeEncryptionType",
["id", "volume_type_id"])
QoSSpecs = collections.namedtuple("QoSSpecs", ["id", "name"])
class BlockStorage(service.UnifiedOpenStackService):

View File

@ -418,6 +418,10 @@ class UnifiedCinderMixin(object):
volume_id=transfer.volume_id,
auth_key=auth_key)
@staticmethod
def _unify_qos(qos):
return block.QoSSpecs(id=qos.id, name=qos.name)
@staticmethod
def _unify_encryption_type(encryption_type):
return block.VolumeEncryptionType(
@ -487,7 +491,7 @@ class UnifiedCinderMixin(object):
:param specs: A dict of key/value pairs to be set
:rtype: :class:'QoSSpecs'
"""
return self._impl.create_qos(specs)
return self._unify_qos(self._impl.create_qos(specs))
def list_qos(self, search_opts=None):
"""Get a list of all qos specs.
@ -495,7 +499,8 @@ class UnifiedCinderMixin(object):
:param search_opts: search options
:rtype: list of :class: 'QoSpecs'
"""
return self._impl.list_qos(search_opts)
return [self._unify_qos(qos)
for qos in self._impl.list_qos(search_opts)]
def get_qos(self, qos_id):
"""Get a specific qos specs.
@ -503,7 +508,7 @@ class UnifiedCinderMixin(object):
:param qos_id: The ID of the :class: 'QoSSpecs' to get
:rtype: :class: 'QoSSpecs'
"""
return self._impl.get_qos(qos_id)
return self._unify_qos(self._impl.get_qos(qos_id))
def delete_snapshot(self, snapshot):
"""Delete the given backup.

View File

@ -439,6 +439,14 @@ class UnifiedCinderMixinTestCase(test.TestCase):
self.assertEqual("volume", transfer.volume_id)
self.assertEqual("st", transfer.status)
def test__unify_qos(self):
class Qos(object):
id = 1
name = "transfer"
qos = self.service._unify_qos(Qos())
self.assertEqual(1, qos.id)
self.assertEqual("transfer", qos.name)
def test__unify_encryption_type(self):
class SomeEncryptionType(object):
encryption_id = 1
@ -487,24 +495,35 @@ class UnifiedCinderMixinTestCase(test.TestCase):
specs = {"consumer": "both",
"write_iops_sec": "10",
"read_iops_sec": "1000"}
self.service._unify_qos = mock.MagicMock()
self.assertEqual(
self.service._impl.create_qos.return_value,
self.service._unify_qos.return_value,
self.service.create_qos(specs)
)
self.service._impl.create_qos.assert_called_once_with(specs)
self.service._unify_qos.assert_called_once_with(
self.service._impl.create_qos.return_value
)
def test_list_qos(self):
self.service._unify_qos = mock.MagicMock()
self.service._impl.list_qos.return_value = ["qos"]
self.assertEqual(
self.service._impl.list_qos.return_value,
[self.service._unify_qos.return_value],
self.service.list_qos(True)
)
self.service._impl.list_qos.assert_called_once_with(True)
self.service._unify_qos.assert_called_once_with("qos")
def test_get_qos(self):
self.service._unify_qos = mock.MagicMock()
self.assertEqual(
self.service._impl.get_qos.return_value,
self.service._unify_qos.return_value,
self.service.get_qos("qos"))
self.service._impl.get_qos.assert_called_once_with("qos")
self.service._unify_qos.assert_called_once_with(
self.service._impl.get_qos.return_value
)
def test_delete_snapshot(self):
self.service.delete_snapshot("snapshot")