Define proper exception instead of ValidationError

In nova_dpm.virt.dpm.utils.py need to write proper
exceptions instead of ValidationError or Exceptions.

for example
https://github.com/openstack/nova-dpm/blob/master/nova_dpm/virt/dpm/utils.py#L42

Closes-Bug: #1669359

Change-Id: If41458cf46db5dcd93cbcd69e28a8bad19bcb9ac
Signed-off-by: Prabhat Ranjan <pranjank@in.ibm.com>
This commit is contained in:
Prabhat Ranjan 2017-04-24 19:08:11 +05:30
parent c1d3edfb43
commit 3bb1595d1f
4 changed files with 126 additions and 30 deletions

View File

@ -89,16 +89,17 @@ class DPMdriverInitHostTestCase(TestCase):
def test_invalid_mem_config(self):
self.flags(group="dpm", max_memory=3000)
self.assertRaises(exception.ValidationError,
self.assertRaises(exceptions.MaxMemoryExceededError,
self.dpmdriver.init_host,
None)
def test_invalid_proc_config(self):
self.flags(group="dpm", max_processors=50)
self.assertRaises(exception.ValidationError,
self.dpmdriver.init_host,
None)
self.assertRaises(
exceptions.MaxProcessorExceededError,
self.dpmdriver.init_host,
None)
@mock.patch.object(vm.PartitionInstance, 'get_partition')
@mock.patch.object(vm.PartitionInstance, 'get_partition_wwpns')

View File

@ -0,0 +1,88 @@
# Copyright 2016 IBM Corp. All Rights Reserved.
#
# 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 requests.packages.urllib3
import zhmcclient
import zhmcclient_mock
from nova.test import TestCase
from nova_dpm.virt.dpm import exceptions
from nova_dpm.virt.dpm import utils
class HostTestCase(TestCase):
def setUp(self):
super(HostTestCase, self).setUp()
requests.packages.urllib3.disable_warnings()
session = zhmcclient_mock.FakedSession(
'fake-host', 'fake-hmc', '2.13.1', '1.8')
session.hmc.cpcs.add({
'name': 'cpc_1',
'description': 'CPC #1',
'dpm-enabled': True,
'processor-count-ifl': 10,
'storage-customer': 2048,
})
client = zhmcclient.Client(session)
self.cpc = client.cpcs.find(**{"name": "cpc_1"})
self.flags(host='foo')
self.flags(group="dpm", max_processors=3)
self.flags(group="dpm", max_memory=1024)
def test_max_processor_correct(self):
utils.validate_host_conf(self.cpc)
def test_max_processor_exceded(self):
self.flags(group="dpm", max_processors=11)
self.assertRaises(
exceptions.MaxProcessorExceededError,
utils.validate_host_conf, self.cpc)
def test_max_memory_correct(self):
utils.validate_host_conf(self.cpc)
def test_max_memory_exceded(self):
self.flags(group="dpm", max_memory=4096)
self.assertRaises(
exceptions.MaxMemoryExceededError,
utils.validate_host_conf, self.cpc)
def test_dpm_enabled(self):
utils.validate_host_conf(self.cpc)
def test_dpm_enabled_false(self):
requests.packages.urllib3.disable_warnings()
session = zhmcclient_mock.FakedSession(
'fake-host', 'fake-hmc', '2.13.1', '1.8')
session.hmc.cpcs.add({
'name': 'cpc_1',
'description': 'CPC #1',
'dpm-enabled': False,
'processor-count-ifl': 10,
'storage-customer': 2048,
})
client = zhmcclient.Client(session)
cpc = client.cpcs.find(**{"name": "cpc_1"})
self.flags(host='foo')
self.flags(group="dpm", max_processors=3)
self.flags(group="dpm", max_memory=1024)
self.assertRaises(
exceptions.CpcDpmModeNotEnabledException,
utils.validate_host_conf, cpc)

View File

@ -35,3 +35,21 @@ class BootOsSpecificParametersPropertyExceededError(NovaException):
class UnsupportedVolumeTypeException(NovaException):
msg_fmt = _("Driver volume type"
" %(vol_type)s is not supported by nova-dpm.")
class MaxProcessorExceededError(NovaException):
msg_fmt = _("max_processors %(config_proc)s configured for "
"CpcSubset %(cpcsubset_name)s is greater than the "
"available amount of shared IFL processors %(max_proc)s on "
"CPC object-id %(cpcid)s and CPC name %(cpcname)s.")
class MaxMemoryExceededError(NovaException):
msg_fmt = _("max_memory_mb %(config_mem)s configured for "
"CpcSubset %(cpcsubset_name)s is greater than the "
"available amount of memory %(max_mem)s on CPC "
"object-id %(cpcid)s and CPC name %(cpcname)s.")
class CpcDpmModeNotEnabledException(NovaException):
msg_fmt = _("DPM mode on CPC %(cpc_name)s not enabled.")

View File

@ -14,8 +14,7 @@
import nova_dpm.conf
from nova import exception
from nova.i18n import _
from nova_dpm.virt.dpm import exceptions
from oslo_log import log as logging
LOG = logging.getLogger(__name__)
@ -25,34 +24,24 @@ CONF = nova_dpm.conf.CONF
def validate_host_conf(cpc):
LOG.debug('validate_host_conf')
if not cpc.dpm_enabled:
# TODO(preethipy): Exception infrastructure to be finalized
raise Exception("Host not in DPM mode")
raise exceptions.CpcDpmModeNotEnabledException(
cpc_name=cpc.get_property('name'))
if (CONF.dpm.max_processors > cpc.get_property('processor-count-ifl')):
# TODO(preethipy): Exception infrastructure to be finalized
errormsg = (_("max_processors %(config_proc)s configured for "
"CpcSubset %(cpcsubset_name)s is greater than the "
"available amount of processors %(max_proc)s on "
"CPC object-id %(cpcid)s and CPC name %(cpcname)s")
% {'config_proc': CONF.dpm.max_processors,
'cpcsubset_name': CONF.host,
'max_proc': cpc.get_property('processor-count-ifl'),
'cpcid': CONF.dpm.cpc_object_id,
'cpcname': cpc.get_property('name')})
raise exception.ValidationError(errormsg)
raise exceptions.MaxProcessorExceededError(
config_proc=CONF.dpm.max_processors,
cpcsubset_name=CONF.host,
max_proc=cpc.get_property('processor-count-ifl'),
cpcid=CONF.dpm.cpc_object_id,
cpcname=cpc.get_property('name'))
if (CONF.dpm.max_memory > cpc.get_property('storage-customer')):
# TODO(preethipy): Exception infrastructure to be finalized
errormsg = (_("max_memory_mb %(config_mem)s configured for "
"CpcSubset %(cpcsubset_name)s is greater than the "
"available amount of memory %(max_mem)s on CPC "
"object-id %(cpcid)s and CPC name %(cpcname)s")
% {'config_mem': CONF.dpm.max_processors,
'cpcsubset_name': CONF.host,
'max_mem': cpc.get_property('storage-customer'),
'cpcid': CONF.dpm.cpc_object_id,
'cpcname': cpc.get_property('name')})
raise exception.ValidationError(errormsg)
raise exceptions.MaxMemoryExceededError(
config_mem=CONF.dpm.max_processors,
cpcsubset_name=CONF.host,
max_mem=cpc.get_property('storage-customer'),
cpcid=CONF.dpm.cpc_object_id,
cpcname=cpc.get_property('name'))
class PartitionState(object):