Add affinity score check attribute to flavor

This change request is to enable adding affinity score check
attribute as part of VM deploy based on the host capability.

Change-Id: I63b80fc80ef6634396a460d74794216b09ed2f2d
This commit is contained in:
arunmani 2018-03-22 09:56:28 -04:00 committed by Arun Mani
parent 6249706488
commit 1dc302b719
2 changed files with 38 additions and 2 deletions

View File

@ -1,4 +1,4 @@
# Copyright 2014, 2017 IBM Corp.
# Copyright 2014, 2018 IBM Corp.
#
# All Rights Reserved.
#
@ -217,6 +217,21 @@ class TestVMBuilder(test.NoDBTestCase):
test_attrs = dict(lpar_attrs, ppt_ratio='1:64')
self.assertEqual(self.lpar_b._format_flavor(instance), test_attrs)
# Test enforce affinity check set to true
flavor.extra_specs = {'powervm:enforce_affinity_check': 'true'}
test_attrs = dict(lpar_attrs, enforce_affinity_check=True)
self.assertEqual(self.lpar_b._format_flavor(instance), test_attrs)
# Test enforce affinity check set to false
flavor.extra_specs = {'powervm:enforce_affinity_check': 'false'}
test_attrs = dict(lpar_attrs, enforce_affinity_check=False)
self.assertEqual(self.lpar_b._format_flavor(instance), test_attrs)
# Test enforce affinity check set to invalid value
flavor.extra_specs = {'powervm:enforce_affinity_check': 'invalid'}
self.assertRaises(exception.ValidationError,
self.lpar_b._format_flavor, instance)
# Test PPT ratio not set when rebuilding to non-supported host
flavor.extra_specs = {'powervm:ppt_ratio': '1:4096'}
instance.task_state = task_states.REBUILD_SPAWNING
@ -226,6 +241,13 @@ class TestVMBuilder(test.NoDBTestCase):
self.lpar_b.host_w.get_capability.assert_called_once_with(
'physical_page_table_ratio_capable')
# Test affinity check not set when rebuilding to non-supported host
self.lpar_b.host_w.get_capability.reset_mock()
flavor.extra_specs = {'powervm:enforce_affinity_check': 'true'}
self.assertEqual(self.lpar_b._format_flavor(instance), test_attrs)
self.lpar_b.host_w.get_capability.assert_called_once_with(
'affinity_check_capable')
@mock.patch('pypowervm.wrappers.shared_proc_pool.SharedProcPool.search')
def test_spp_pool_id(self, mock_search):
# The default pool is always zero. Validate the path.

View File

@ -1,4 +1,4 @@
# Copyright 2014, 2017 IBM Corp.
# Copyright 2014, 2018 IBM Corp.
#
# All Rights Reserved.
#
@ -234,6 +234,7 @@ class VMBuilder(object):
_PVM_SHAR_PROC_POOL = 'powervm:shared_proc_pool_name'
_PVM_SRR_CAPABILITY = 'powervm:srr_capability'
_PVM_PPT_RATIO = 'powervm:ppt_ratio'
_PVM_ENFORCE_AFFINITY_CHECK = 'powervm:enforce_affinity_check'
# Map of PowerVM extra specs to the lpar builder attributes.
# '' is used for attributes that are not implemented yet.
@ -252,6 +253,7 @@ class VMBuilder(object):
'powervm:availability_priority': lpar_bldr.AVAIL_PRIORITY,
'powervm:enable_lpar_metric': lpar_bldr.ENABLE_LPAR_METRIC,
_PVM_PPT_RATIO: lpar_bldr.PPT_RATIO,
_PVM_ENFORCE_AFFINITY_CHECK: lpar_bldr.ENFORCE_AFFINITY_CHECK,
_PVM_UNCAPPED: None,
_PVM_DED_SHAR_MODE: None,
_PVM_PROC_COMPAT: None,
@ -359,6 +361,18 @@ class VMBuilder(object):
"unsupported host.", instance=instance)
else:
attrs[bldr_key] = instance.flavor.extra_specs[key]
elif bldr_key == lpar_bldr.ENFORCE_AFFINITY_CHECK:
if (instance.task_state == task_states.REBUILD_SPAWNING and not
self.host_w.get_capability('affinity_check_capable')):
# We still want to be able to rebuild from hosts that
# support affinity score check to hosts that don't support
# affinity score check.
LOG.info("Skipping affinity check attribute processing "
"on rebuild to host which does not support "
"affinity checks.", instance=instance)
else:
attrs[bldr_key] = self._flavor_bool(
instance.flavor.extra_specs[key], key)
else:
# We found a direct mapping
attrs[bldr_key] = instance.flavor.extra_specs[key]