Merge "Unify QoSSpecs returned data"

This commit is contained in:
Jenkins 2017-04-25 10:37:43 +00:00 committed by Gerrit Code Review
commit 5de572afc3
3 changed files with 31 additions and 6 deletions

View File

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

View File

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

View File

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