Remove local copy of CONF

Local copy of config option is unnecessary
and prevents dynamic config file updates.

Need to remove
self._conf = {'cpcsubset_name': CONF.host,
              'cpc_uuid': CONF.dpm.cpc_uuid,
              'max_processors': CONF.dpm.max_processors,
              'max_memory_mb': CONF.dpm.max_memory,
              'max_partitions': CONF.dpm.max_instances,
              'physical_storage_adapter_mappings':
                  CONF.dpm.physical_storage_adapter_mappings}

And directly use CONF.dpm.xyz

closes-Bug: 1659043

Change-Id: If62008bdf21441ed92eb5fabda440fbb88fcaa64
Signed-off-by: Prabhat Ranjan <pranjank@in.ibm.com>
This commit is contained in:
Prabhat Ranjan
2017-02-27 20:04:29 +05:30
parent b40d6e1654
commit de4742b980
9 changed files with 93 additions and 82 deletions

View File

@@ -15,14 +15,7 @@
def getFakeCPCconf():
conf = {'cpcsubset_name': "S12subset",
'cpc_object_id': "1232132",
'max_processors': 10,
'max_memory_mb': 200,
'max_partitions': 10,
'physical_storage_adapter_mappings':
["439da232-b18d-11e6-9c12-42f2e9ef1641:0"]
}
conf = CONF()
return conf
@@ -49,3 +42,17 @@ class PartitionInstance(object):
@property
def uuid(self):
return self.properties['uuid']
class DPM(object):
cpc_object_id = "1232132"
max_processors = 10
max_memory = 200
max_partitions = 10
physical_storage_adapter_mappings = [
"439da232-b18d-11e6-9c12-42f2e9ef1641:0"]
class CONF(object):
host = "S12subset"
dpm = DPM()

View File

@@ -15,27 +15,35 @@
"""Fake zhmcclient"""
from nova_dpm.tests.unit.virt.dpm import fakeutils
CONF = fakeutils.getFakeCPCconf()
# We have considered 3 fake partition for unit test in one CPC.
# DummyPartition1, DummyPartition2, DummyPartition3
# Data for Fake partition1
INSTANCE_NAME1 = "6511ee0f-0d64-4392-b9e0-cdbea10a17c4"
PARTITION_NAME1 = "OpenStack-foo-6511ee0f-0d64-4392-b9e0-cdbea10a17c4"
PARTITION_NAME1 = ("OpenStack-"
+ CONF.host + "-6511ee0f-0d64-4392-b9e0-cdbea10a17c4")
PARTITION_URI1 = "/api/partitions/00000000-aaba-bbbb-cccc-abcdabcdabcd"
PARTITION_CP_PROCESSOR1 = 1
PARTITION_INITIAL_MEMORY1 = 512
# Data for Fake partition2
INSTANCE_NAME2 = "6511ee0f-0d64-4392-b9e0-cdbea10a17c5"
PARTITION_NAME2 = "OpenStack-foo-6511ee0f-0d64-4392-b9e0-cdbea10a17c5"
PARTITION_NAME2 = ("OpenStack-"
+ CONF.host + "-6511ee0f-0d64-4392-b9e0-cdbea10a17c5")
PARTITION_URI2 = "/api/partitions/00000000-aaba-bcbb-cccc-abcdabcdabcd"
PARTITION_CP_PROCESSOR2 = 2
PARTITION_INITIAL_MEMORY2 = 1024
# Data for Fake partition3
INSTANCE_NAME3 = "6511ee0f-0d64-4392-b9e0-cdbea10a17c6"
PARTITION_NAME3 = "OpenStack-foo-6511ee0f-0d64-4392-b9e0-cdbea10a17c6"
PARTITION_NAME3 = ("OpenStack-"
+ CONF.host + "-6511ee0f-0d64-4392-b9e0-cdbea10a17c6")
PARTITION_URI3 = "/api/partitions/00000000-aaba-bbbb-cdcc-abcdabcdabcd"
PARTITION_CP_PROCESSOR3 = 1
PARTITION_INITIAL_MEMORY3 = 512
@@ -125,7 +133,7 @@ def getFakeCPCwithProp(cpcmanager, cpc_props):
def getFakePartition():
partition_props = dict()
partition_props['name'] = (
"OpenStack-foo-6511ee0f-0d64-4392-b9e0-cdbea10a17c3")
"OpenStack-" + CONF.host + "-6511ee0f-0d64-4392-b9e0-cdbea10a17c3")
partition_props['description'] = "OpenStack CPCSubset=foo"
partition_props['object-uri'] = "/api/partitions/" \
"00000000-aaaa-bbbb-cccc-abcdabcdabcd"

View File

@@ -19,6 +19,7 @@ from nova import exception
from nova.objects import flavor as flavor_object
from nova.test import TestCase
from nova.virt import driver as driv
from nova_dpm.tests.unit.virt.dpm import fakeutils
from nova_dpm.tests.unit.virt.dpm import fakezhmcclient
from nova_dpm.tests.unit.virt.dpm import test_host as testhost
from nova_dpm.virt.dpm import client_proxy
@@ -32,6 +33,7 @@ from nova_dpm.virt.dpm.volume import fibrechannel
cpcsubset unit testcase
"""
nova_dpm.conf.CONF = fakeutils.getFakeCPCconf()
CONF = nova_dpm.conf.CONF
PARTITION_WWPN = 'C05076FFEB8000D6'
@@ -303,9 +305,7 @@ class DPMPartitionSpawnNicTestCase(TestCase):
self.assertEqual(instancelist, dpmdriver.list_instances())
@mock.patch.object(vm, "CONF")
def test_get_info(self, mock_conf):
mock_conf.host = "foo"
def test_get_info(self):
mock_partition_instance_info = mock.Mock(vm.PartitionInstanceInfo)
mock_partition_instance_info.return_value =\
@@ -319,7 +319,8 @@ class DPMPartitionSpawnNicTestCase(TestCase):
self.assertEqual(partitionInfo.num_cpu, 1)
@mock.patch.object(vm.PartitionInstance, 'destroy')
def test_destroy(self, mock_destroy):
@mock.patch.object(vm.PartitionInstance, 'get_partition_wwpns')
def test_destroy(self, mock_destroy, mock_wwpns):
dpmdriver = driver.DPMDriver(None)
dpmdriver._cpc = fakezhmcclient.getFakeCPC()
dpmdriver.destroy(mock.Mock, getMockNovaInstanceForPartion(),

View File

@@ -26,15 +26,17 @@ cpcsubset unit testcase
"""
host.CONF = fakeutils.getFakeCPCconf()
def fakeHost():
session = fakezhmcclient.Session("hostip", "dummyhost", "dummyhost")
client = fakezhmcclient.Client(session)
cpcmanager = fakezhmcclient.getCpcmgrForClient(client)
cpc = fakezhmcclient.getFakeCPC(cpcmanager)
conf = fakezhmcclient.getFakeCPCconf()
host1 = host.Host(conf, cpc, client)
host1 = host.Host(cpc, client)
return host1
@@ -68,12 +70,11 @@ class HostTestCase(TestCase):
self._client = fakezhmcclient.Client(self._session)
self._cpcmanager = fakezhmcclient.getCpcmgrForClient(self._client)
self._cpc = fakezhmcclient.getFakeCPC(self._cpcmanager)
self._conf = fakeutils.getFakeCPCconf()
self.host_obj = host.Host(self._conf, self._cpc, self._client)
self.host_obj = host.Host(self._cpc, self._client)
@mock.patch.object(host.LOG, 'debug')
def test_host(self, mock_warning):
host.Host(self._conf, self._cpc, self._client)
host.Host(self._cpc, self._client)
expected_arg = "Host initializing done"
assertlogs = False
@@ -91,9 +92,7 @@ class HostTestCase(TestCase):
cpcmanager = fakezhmcclient.getCpcmgrForClient(client)
cpc = fakezhmcclient.getFakeCPC(cpcmanager)
conf = fakeutils.getFakeCPCconf()
host1 = host.Host(conf, cpc, client)
host1 = host.Host(cpc, client)
host_properties = host1.properties
self.assertEqual(host_properties['hypervisor_hostname'],
'S12subset')

View File

@@ -28,6 +28,9 @@ vm unit testcase
"""
vm.CONF = fakeutils.getFakeCPCconf()
def getMockInstance():
session = fakezhmcclient.Session("hostip", "dummyhost", "dummyhost")
client = fakezhmcclient.Client(session)
@@ -41,17 +44,16 @@ class VmFunctionTestCase(TestCase):
def setUp(self):
super(VmFunctionTestCase, self).setUp()
self.valid_name = (
'OpenStack-foo-6511ee0f-0d64-4392-b9e0-cdbea10a17c3')
'OpenStack-'
+ vm.CONF.host + '-6511ee0f-0d64-4392-b9e0-cdbea10a17c3')
self.invalid_name = 'OpenStack-Instance-6511ee0f'
self.cpc = fakezhmcclient.getFakeCPC()
def test_is_valid_partition_name(self):
self.flags(host='foo')
self.assertTrue(vm.is_valid_partition_name(self.valid_name))
self.assertFalse(vm.is_valid_partition_name(self.invalid_name))
def test_partition_list(self):
self.flags(host='foo')
partition_list = vm.cpcsubset_partition_list(self.cpc)
list = self.cpc.partitions.list()
length = len(list)
@@ -97,19 +99,19 @@ class InstancePropertiesTestCase(TestCase):
super(InstancePropertiesTestCase, self).setUp()
self.mock_nova_inst = mock.Mock()
self.mock_nova_inst.uuid = 'foo-id'
vm.CONF.set_override("host", "foo")
@mock.patch.object(vm.PartitionInstance, 'get_partition')
def test_partition_name(self, mock_get_part):
inst = vm.PartitionInstance(
self.mock_nova_inst, mock.Mock())
self.assertEqual("OpenStack-foo-foo-id", inst.partition_name)
self.assertEqual("OpenStack-" + vm.CONF.host + "-foo-id",
inst.partition_name)
@mock.patch.object(vm.PartitionInstance, 'get_partition')
def test_partition_description(self, mock_get_part):
inst = vm.PartitionInstance(
self.mock_nova_inst, mock.Mock())
self.assertEqual("OpenStack CPCSubset=foo",
self.assertEqual("OpenStack CPCSubset=" + vm.CONF.host,
inst.partition_description)
@mock.patch.object(vm.PartitionInstance, 'get_partition')
@@ -121,8 +123,10 @@ class InstancePropertiesTestCase(TestCase):
inst = vm.PartitionInstance(
self.mock_nova_inst, mock.Mock(), flavor=mock_flavor)
props = inst.properties()
self.assertEqual('OpenStack-foo-foo-id', props['name'])
self.assertEqual('OpenStack CPCSubset=foo', props['description'])
self.assertEqual('OpenStack-'
+ vm.CONF.host + '-foo-id', props['name'])
self.assertEqual('OpenStack CPCSubset=' + vm.CONF.host,
props['description'])
self.assertEqual(5, props['ifl-processors'])
self.assertEqual(2000, props['initial-memory'])
self.assertEqual(2000, props['maximum-memory'])
@@ -133,7 +137,6 @@ class VmNicTestCase(TestCase):
def setUp(self):
super(VmNicTestCase, self).setUp()
vm.zhmcclient = fakezhmcclient
self.conf = fakeutils.getFakeCPCconf()
self.inst = getMockInstance()
self.inst.partition.nics = fakezhmcclient.getFakeNicManager()
@@ -150,7 +153,7 @@ class VmNicTestCase(TestCase):
ret_val .__getitem__.side_effect = dict.__getitem__
with mock.patch.object(fakezhmcclient.NicManager, 'create',
return_value=ret_val) as mock_create:
nic_interface = self.inst.attach_nic(self.conf, self.vif1)
nic_interface = self.inst.attach_nic(self.vif1)
self.assertEqual(ret_val, nic_interface)
self.assertTrue(mock_create.called)
call_arg_dict = mock_create.mock_calls[0][1][0]
@@ -160,7 +163,7 @@ class VmNicTestCase(TestCase):
# Description
self.assertTrue(call_arg_dict['description'].startswith('OpenStack'))
self.assertIn('mac=12:34:56:78:9A:BC', call_arg_dict['description'])
self.assertIn('CPCSubset=' + self.conf['cpcsubset_name'],
self.assertIn('CPCSubset=' + vm.CONF.host,
call_arg_dict['description'])
# virtual-switch-uri
self.assertEqual(
@@ -173,7 +176,6 @@ class VmHBATestCase(TestCase):
def setUp(self):
super(VmHBATestCase, self).setUp()
vm.zhmcclient = fakezhmcclient
self.conf = fakeutils.getFakeCPCconf()
self.inst = getMockInstance()
@@ -193,7 +195,7 @@ class VmHBATestCase(TestCase):
@mock.patch.object(vm.LOG, 'debug')
def test_attach_hba(self, mock_debug):
self.inst.attach_hbas(self.conf)
self.inst.attach_hbas()
class InstancePartitionLifecycleTestCase(TestCase):

View File

@@ -77,27 +77,16 @@ class DPMDriver(driver.ComputeDriver):
"""Driver initialization of the hypervisor node"""
LOG.debug("init_host")
# retrieve from ncpu service configurationfile
self._conf = {'cpcsubset_name': CONF.host,
'cpc_object_id': CONF.dpm.cpc_object_id,
'max_processors': CONF.dpm.max_processors,
'max_memory_mb': CONF.dpm.max_memory,
'max_partitions': CONF.dpm.max_instances,
'physical_storage_adapter_mappings':
CONF.dpm.physical_storage_adapter_mappings,
'target_wwpn_ignore_list':
CONF.dpm.target_wwpn_ignore_list}
self._cpc = self._client.cpcs.find(**{
"object-id": self._conf['cpc_object_id']})
"object-id": CONF.dpm.cpc_object_id})
LOG.debug("Matching hypervisor found %(cpcsubset_name)s for object-id "
"%(cpcid)s and CPC %(cpcname)s" %
{'cpcsubset_name': self._conf['cpcsubset_name'],
'cpcid': self._conf['cpc_object_id'],
{'cpcsubset_name': CONF.host,
'cpcid': CONF.dpm.cpc_object_id,
'cpcname': self._cpc.properties['name']})
utils.valide_host_conf(self._conf, self._cpc)
self._host = Host.Host(self._conf, self._cpc, self._client)
utils.valide_host_conf(self._cpc)
self._host = Host.Host(self._cpc, self._client)
def get_available_resource(self, nodename):
"""Retrieve resource information.
@@ -329,7 +318,7 @@ class DPMDriver(driver.ComputeDriver):
inst = vm.PartitionInstance(instance, self._cpc, flavor)
inst.create(inst.properties())
inst.attach_hbas(self._conf)
inst.attach_hbas()
def spawn(self, context, instance, image_meta, injected_files,
admin_password, network_info=None, block_device_info=None,
@@ -353,11 +342,11 @@ class DPMDriver(driver.ComputeDriver):
))
nic_boot_string = ""
for vif in network_info:
nic = inst.attach_nic(self._conf, vif)
nic = inst.attach_nic(vif)
nic_boot_string += self._get_nic_string_for_guest_os(nic, vif)
inst.set_boot_os_specific_parameters(nic_boot_string)
hba_uri = inst.get_boot_hba_uri(self._conf)
hba_uri = inst.get_boot_hba_uri()
LOG.debug("HBA boot uri %(uri)s for the instance %(name)s"
% {'uri': hba_uri, 'name': instance.hostname})
@@ -418,7 +407,7 @@ class DPMDriver(driver.ComputeDriver):
['initiator_target_map'][partition_wwpn])
target_wwpns = [wwpn for wwpn in list_target_wwpns
if wwpn not in self._conf['target_wwpn_ignore_list']]
if wwpn not in CONF.dpm.target_wwpn_ignore_list]
# target_wwpns is a list of wwpns which will be accessible
# from host wwpn. So we can use any of the target wwpn in the

View File

@@ -17,6 +17,8 @@
Host will have the handle to the CPCSubsetMgr which will retrieve cpcsubsets
"""
import nova_dpm.conf
from nova.objects import fields as obj_fields
from nova_dpm.virt.dpm import vm
from oslo_log import log as logging
@@ -24,6 +26,7 @@ from oslo_serialization import jsonutils
LOG = logging.getLogger(__name__)
CONF = nova_dpm.conf.CONF
PRSM_HYPERVISOR = 'PRSM'
S390_ARCH = 's390x'
IBM = 'IBM'
@@ -36,12 +39,11 @@ HYPERVISOR_VERSION = 1000 # TODO(preethipy): Update with
class Host(object):
def __init__(self, conf, cpc, client):
def __init__(self, cpc, client):
LOG.debug('Host initializing for cpcsubset %(cpcsubset_name)s'
% {'cpcsubset_name': conf['cpcsubset_name']})
% {'cpcsubset_name': CONF.host})
self._conf = conf
self._client = client
self._cpc = cpc
self._instances = [] # TODO(preethipy): Instance details
@@ -59,17 +61,17 @@ class Host(object):
def _get_host_poperties(self):
LOG.debug('_get_host_properties')
dict_mo = {
"memory_mb": self._conf["max_memory_mb"],
"vcpus": self._conf["max_processors"],
"memory_mb": CONF.dpm.max_memory,
"vcpus": CONF.dpm.max_processors,
'vcpus_used': self._get_proc_used(),
"local_gb": 1024, # TODO(preethipy): Update with relevant value
"memory_mb_used": self._get_mem_used(),
"local_gb_used": 0, # TODO(preethipy): Update with relevant value
"cpu_info": self._get_cpu_info(self._conf["max_processors"]),
"cpu_info": self._get_cpu_info(CONF.dpm.max_processors),
"hypervisor_type": PRSM_HYPERVISOR,
"hypervisor_version": HYPERVISOR_VERSION,
"numa_topology": None,
"hypervisor_hostname": self._conf['cpcsubset_name'],
"hypervisor_hostname": CONF.host,
"cpc_name": self._cpc.properties['name'],
"disk_available_least": 1024, # TODO(preethipy): Update with
# relevant value

View File

@@ -12,42 +12,45 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import nova_dpm.conf
from nova import exception
from nova.i18n import _
from oslo_log import log as logging
LOG = logging.getLogger(__name__)
CONF = nova_dpm.conf.CONF
def valide_host_conf(conf, cpc):
def valide_host_conf(cpc):
LOG.debug('valide_host_conf')
if not cpc.dpm_enabled:
# TODO(preethipy): Exception infrastructure to be finalized
raise Exception("Host not in DPM mode")
if (conf['max_processors'] > cpc.get_property('processor-count-ifl')):
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['max_processors'],
'cpcsubset_name': conf['cpcsubset_name'],
% {'config_proc': CONF.dpm.max_processors,
'cpcsubset_name': CONF.host,
'max_proc': cpc.get_property('processor-count-ifl'),
'cpcid': conf['cpc_object_id'],
'cpcid': CONF.dpm.cpc_object_id,
'cpcname': cpc.get_property('name')})
raise exception.ValidationError(errormsg)
if (conf['max_memory_mb'] > cpc.get_property('storage-customer')):
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['max_processors'],
'cpcsubset_name': conf['cpcsubset_name'],
% {'config_mem': CONF.dpm.max_processors,
'cpcsubset_name': CONF.host,
'max_mem': cpc.get_property('processor-count-ifl'),
'cpcid': conf['cpc_object_id'],
'cpcid': CONF.dpm.cpc_object_id,
'cpcname': cpc.get_property('name')})
raise exception.ValidationError(errormsg)

View File

@@ -161,7 +161,7 @@ class PartitionInstance(object):
'boot-os-specific-parameters': data
})
def attach_nic(self, conf, vif):
def attach_nic(self, vif):
# TODO(preethipy): Implement the listener flow to register for
# nic creation events
LOG.debug("Creating nic interface for the instance")
@@ -180,7 +180,7 @@ class PartitionInstance(object):
"name": "OpenStack_Port_" + str(port_id),
"description": "OpenStack mac=" + mac +
", CPCSubset=" +
conf[CPCSUBSET_NAME],
CONF.host,
"virtual-switch-uri": "/api/virtual-switches/"
+ dpm_object_id
}
@@ -193,10 +193,10 @@ class PartitionInstance(object):
'virtual-switch-uri']})
return nic_interface
def attach_hbas(self, conf):
def attach_hbas(self):
LOG.debug('Creating vhbas for instance',
instance=self.instance)
mapping = self.get_adapter_port_mappings(conf)
mapping = self.get_adapter_port_mappings()
for adapterPort in mapping.get_adapter_port_mapping():
adapter_object_id = adapterPort['adapter_id']
adapter_port = adapterPort['port']
@@ -204,7 +204,7 @@ class PartitionInstance(object):
"name": "OpenStack_Port_" + adapter_object_id +
"_" + str(adapter_port),
"description": "OpenStack CPCSubset= " +
conf[CPCSUBSET_NAME],
CONF.host,
"adapter-port-uri": "/api/adapters/"
+ adapter_object_id +
"/storage-ports/" +
@@ -220,9 +220,9 @@ class PartitionInstance(object):
'adapter-port-uri': hba.properties[
'adapter-port-uri']})
def get_adapter_port_mappings(self, conf):
def get_adapter_port_mappings(self):
LOG.debug('Creating Adapter uris')
interface_mappings = conf['physical_storage_adapter_mappings']
interface_mappings = CONF.dpm.physical_storage_adapter_mappings
mapping = PhysicalAdapterModel(self.cpc)
for entry in interface_mappings:
adapter_uuid, port = (
@@ -250,7 +250,7 @@ class PartitionInstance(object):
LOG.debug('Get Hba properties')
return self.partition.get_property('hba-uris')
def get_boot_hba_uri(self, conf):
def get_boot_hba_uri(self):
hbas = self.get_hba_uris()
adapter_uuid, port = (
@@ -259,7 +259,7 @@ class PartitionInstance(object):
# storage in configuration. So
# we will use one i.e first adapter
# in the list
conf['physical_storage_adapter_mappings'][0]))
CONF.dpm.physical_storage_adapter_mappings[0]))
hba_uri = None