PowerMax Driver - QoS Utils Move

Previoulsy, QoS complimentary static methods were located
in the rest.py file, these are better placed in the file
utils.py.  This change addresses that move to utils.py.

Change-Id: I47cbdbd443e0050a4f4349bf177dd06d807eb56f
This commit is contained in:
michael-mcaleer
2019-07-05 10:51:19 +00:00
committed by Helen Walsh
parent 319760bb0e
commit 27db9d2ed8
4 changed files with 73 additions and 73 deletions

View File

@@ -1292,29 +1292,6 @@ class PowerMaxRestTest(test.TestCase):
array, 'OS-QOS-SG', extra_specs)
self.assertFalse(return_value)
def test_validate_qos_input_exception(self):
qos_extra_spec = {'total_iops_sec': 90, 'DistributionType': 'Wrong',
'total_bytes_sec': 100}
input_key = 'total_iops_sec'
sg_value = 4000
self.assertRaises(exception.VolumeBackendAPIException,
self.rest.validate_qos_input, input_key, sg_value,
qos_extra_spec, {})
input_key = 'total_bytes_sec'
sg_value = 4000
self.assertRaises(exception.VolumeBackendAPIException,
self.rest.validate_qos_input, input_key, sg_value,
qos_extra_spec, {})
def test_validate_qos_distribution_type(self):
qos_extra_spec = {'total_iops_sec': 4000, 'DistributionType': 'Always',
'total_bytes_sec': 4194304000}
input_prop_dict = {'total_iops_sec': 4000}
sg_value = 'Always'
ret_prop_dict = self.rest.validate_qos_distribution_type(
sg_value, qos_extra_spec, input_prop_dict)
self.assertEqual(input_prop_dict, ret_prop_dict)
@mock.patch.object(rest.PowerMaxRest, 'modify_storage_group',
return_value=(202, tpd.PowerMaxData.job_list[0]))
def test_set_storagegroup_srp(self, mock_mod):

View File

@@ -500,3 +500,26 @@ class PowerMaxUtilsTest(test.TestCase):
device_info_fail = self.data.volume_details_no_sg
hostname = self.utils.get_volume_attached_hostname(device_info_fail)
self.assertIsNone(hostname)
def test_validate_qos_input_exception(self):
qos_extra_spec = {'total_iops_sec': 90, 'DistributionType': 'Wrong',
'total_bytes_sec': 100}
input_key = 'total_iops_sec'
sg_value = 4000
self.assertRaises(exception.VolumeBackendAPIException,
self.utils.validate_qos_input, input_key, sg_value,
qos_extra_spec, {})
input_key = 'total_bytes_sec'
sg_value = 4000
self.assertRaises(exception.VolumeBackendAPIException,
self.utils.validate_qos_input, input_key, sg_value,
qos_extra_spec, {})
def test_validate_qos_distribution_type(self):
qos_extra_spec = {'total_iops_sec': 4000, 'DistributionType': 'Always',
'total_bytes_sec': 4194304000}
input_prop_dict = {'total_iops_sec': 4000}
sg_value = 'Always'
ret_prop_dict = self.utils.validate_qos_distribution_type(
sg_value, qos_extra_spec, input_prop_dict)
self.assertEqual(input_prop_dict, ret_prop_dict)

View File

@@ -19,7 +19,6 @@ import time
from oslo_log import log as logging
from oslo_service import loopingcall
from oslo_utils import units
import requests
import requests.auth
import requests.exceptions as r_exc
@@ -1027,15 +1026,15 @@ class PowerMaxRest(object):
except KeyError:
LOG.debug("Unable to get storage group QoS details.")
if 'total_iops_sec' in extra_specs.get('qos'):
property_dict = self.validate_qos_input(
property_dict = self.utils.validate_qos_input(
'total_iops_sec', sg_maxiops, extra_specs.get('qos'),
property_dict)
if 'total_bytes_sec' in extra_specs.get('qos'):
property_dict = self.validate_qos_input(
property_dict = self.utils.validate_qos_input(
'total_bytes_sec', sg_maxmbps, extra_specs.get('qos'),
property_dict)
if 'DistributionType' in extra_specs.get('qos') and property_dict:
property_dict = self.validate_qos_distribution_type(
property_dict = self.utils.validate_qos_distribution_type(
sg_distribution_type, extra_specs.get('qos'), property_dict)
if property_dict:
@@ -1053,52 +1052,6 @@ class PowerMaxRest(object):
return_value = False
return return_value
@staticmethod
def validate_qos_input(input_key, sg_value, qos_extra_spec, property_dict):
max_value = 100000
qos_unit = "IO/Sec"
if input_key == 'total_iops_sec':
min_value = 100
input_value = int(qos_extra_spec['total_iops_sec'])
sg_key = 'host_io_limit_io_sec'
else:
qos_unit = "MB/sec"
min_value = 1
input_value = int(qos_extra_spec['total_bytes_sec']) / units.Mi
sg_key = 'host_io_limit_mb_sec'
if min_value <= input_value <= max_value:
if sg_value is None or input_value != int(sg_value):
property_dict[sg_key] = input_value
else:
exception_message = (
_("Invalid %(ds)s with value %(dt)s entered. Valid values "
"range from %(du)s %(dv)s to 100,000 %(dv)s") % {
'ds': input_key, 'dt': input_value, 'du': min_value,
'dv': qos_unit})
LOG.error(exception_message)
raise exception.VolumeBackendAPIException(
message=exception_message)
return property_dict
@staticmethod
def validate_qos_distribution_type(
sg_value, qos_extra_spec, property_dict):
dynamic_list = ['never', 'onfailure', 'always']
if qos_extra_spec.get('DistributionType').lower() in dynamic_list:
distribution_type = qos_extra_spec['DistributionType']
if distribution_type != sg_value:
property_dict["dynamicDistribution"] = distribution_type
else:
exception_message = (
_("Wrong Distribution type value %(dt)s entered. Please enter "
"one of: %(dl)s") % {
'dt': qos_extra_spec.get('DistributionType'),
'dl': dynamic_list})
LOG.error(exception_message)
raise exception.VolumeBackendAPIException(
message=exception_message)
return property_dict
def set_storagegroup_srp(
self, array, storagegroup_name, srp_name, extra_specs):
"""Modify a storage group's srp value.

View File

@@ -21,6 +21,7 @@ import re
from cinder.objects.group import Group
from oslo_log import log as logging
from oslo_utils import strutils
from oslo_utils import units
import six
from cinder import exception
@@ -903,3 +904,49 @@ class PowerMaxUtils(object):
return sg_id.split('-')[1]
except IndexError:
return None
@staticmethod
def validate_qos_input(input_key, sg_value, qos_extra_spec, property_dict):
max_value = 100000
qos_unit = "IO/Sec"
if input_key == 'total_iops_sec':
min_value = 100
input_value = int(qos_extra_spec['total_iops_sec'])
sg_key = 'host_io_limit_io_sec'
else:
qos_unit = "MB/sec"
min_value = 1
input_value = int(qos_extra_spec['total_bytes_sec']) / units.Mi
sg_key = 'host_io_limit_mb_sec'
if min_value <= input_value <= max_value:
if sg_value is None or input_value != int(sg_value):
property_dict[sg_key] = input_value
else:
exception_message = (
_("Invalid %(ds)s with value %(dt)s entered. Valid values "
"range from %(du)s %(dv)s to 100,000 %(dv)s") % {
'ds': input_key, 'dt': input_value, 'du': min_value,
'dv': qos_unit})
LOG.error(exception_message)
raise exception.VolumeBackendAPIException(
message=exception_message)
return property_dict
@staticmethod
def validate_qos_distribution_type(
sg_value, qos_extra_spec, property_dict):
dynamic_list = ['never', 'onfailure', 'always']
if qos_extra_spec.get('DistributionType').lower() in dynamic_list:
distribution_type = qos_extra_spec['DistributionType']
if distribution_type != sg_value:
property_dict["dynamicDistribution"] = distribution_type
else:
exception_message = (
_("Wrong Distribution type value %(dt)s entered. Please "
"enter one of: %(dl)s") % {
'dt': qos_extra_spec.get('DistributionType'),
'dl': dynamic_list})
LOG.error(exception_message)
raise exception.VolumeBackendAPIException(
message=exception_message)
return property_dict