Implemented Partition start as part of spawn function

+ Implemented partition start flow as part of spawn
function
+ Corrected minor errors with zhmcclient
 initialization, function declaration
+ Workaround to loop for partition status introduced
to resolve DPM bug- Paritition status is not updated
immediately after the Start partition API returning.

Change-Id: I1a6262eb11b5a25a95e92deba96b0a8b2af55d65
blueprint: Start-Instance-spawn
This commit is contained in:
preethipy
2017-01-04 19:34:10 +05:30
parent c0f2c1c610
commit ac5dbc45bf
4 changed files with 67 additions and 19 deletions

View File

@@ -48,7 +48,7 @@ ALL_DPM_OPTS = [
Maximum amount of memory available on CpcSubset"""),
cfg.IntOpt('max_instances', help="""
Maximum number of instances that can be created on CpcSubset"""),
cfg.IntOpt('physical_storage_adapter_mappings', help="""
cfg.StrOpt('physical_storage_adapter_mappings', help="""
Physical storage adapter with port details for hba creation""")
]

View File

@@ -160,7 +160,7 @@ class CpcManager(BaseManager):
class Cpc(BaseResource):
def __init__(self, manager, uri, properties):
super(Cpc, self).__init__(manager, uri, properties,
super(Cpc, self).__init__(manager, uri, None, properties,
uri_prop='object-uri',
name_prop='name')
@@ -200,7 +200,7 @@ class PartitionManager(BaseManager):
class Partition(BaseResource):
def __init__(self, manager, uri, properties):
super(Partition, self).__init__(
manager, uri, properties,
manager, uri, None, properties,
uri_prop='object-uri', name_prop='name')
def pull_full_properties(self):
@@ -231,7 +231,7 @@ class NicManager(BaseManager):
class Nic(BaseResource):
def __init__(self, manager, uri, properties):
super(Nic, self).__init__(manager, uri, properties,
super(Nic, self).__init__(manager, uri, None, properties,
uri_prop='object-uri',
name_prop='name')
@@ -263,7 +263,7 @@ class HbaManager(BaseManager):
class Hba(BaseResource):
def __init__(self, manager, uri, properties):
super(Hba, self).__init__(manager, uri, properties,
super(Hba, self).__init__(manager, uri, None, properties,
uri_prop='object-uri',
name_prop='name')
@@ -296,7 +296,7 @@ class AdapterManager(BaseManager):
class Adapter(BaseResource):
def __init__(self, manager, uri, properties):
super(Adapter, self).__init__(manager, uri, properties,
super(Adapter, self).__init__(manager, uri, None, properties,
uri_prop='object-uri',
name_prop='name')

View File

@@ -70,6 +70,12 @@ class DPMDriver(driver.ComputeDriver):
self.volume_drivers = self._get_volume_drivers()
def _get_zhmclient(self, zhmc, userid, password):
"""Lazy initialization for zhmcclient
This function helps in lazy loading zhmclient. The zhmcclient can
otherwise be set to fakezhmcclient for unittest framework
"""
LOG.debug("_get_zhmclient")
# TODO(preethipy): The below line will be removed once the warnings are
# supressed within zhmclient code
@@ -245,4 +251,4 @@ class DPMDriver(driver.ComputeDriver):
inst.attachHba(self._conf)
inst._build_resources(context, instance, block_device_mapping)
# TODO(pranjank): implement start partition
inst.launch()

View File

@@ -17,6 +17,7 @@
Partition will map nova parameter to PRSM parameter
"""
import sys
import time
from nova.compute import manager as compute_manager
from nova.compute import power_state
@@ -36,7 +37,7 @@ DPM_TO_NOVA_STATE = {
utils.PartitionState.STOPPED: power_state.SHUTDOWN,
utils.PartitionState.UNKNOWN: power_state.NOSTATE,
utils.PartitionState.PAUSED: power_state.PAUSED,
utils.PartitionState.STARTING: power_state.NOSTATE
utils.PartitionState.STARTING: power_state.PAUSED
}
OBJECT_ID = 'object-id'
@@ -57,21 +58,28 @@ def _translate_vm_state(dpm_state):
return nova_state
def _get_zhmclient():
"""Lazy initialization for zhmcclient
This function helps in lazy loading zhmclient. The zhmcclient can
otherwise be set to fakezhmcclient for unittest framework
"""
LOG.debug("_get_zhmclient")
global zhmcclient
if zhmcclient is None:
zhmcclient = importutils.import_module('zhmcclient')
class Instance(object):
def __init__(self, instance, cpc, client, flavor=None):
self._get_zhmclient()
_get_zhmclient()
self.instance = instance
self.flavor = flavor
self.cpc = cpc
self.client = client
self.partition = self.get_partition(self.cpc, self.instance)
def _get_zhmclient(self):
LOG.debug("_get_zhmclient")
global zhmcclient
if zhmcclient is None:
zhmcclient = importutils.import_module('zhmcclient')
def properties(self):
properties = {}
properties['name'] = self.instance.hostname
@@ -86,7 +94,6 @@ class Instance(object):
self.partition = partition_manager.create(properties)
def attach_nic(self, conf, network_info):
# TODO(preethipy): This function can be moved to Partition.py
# TODO(preethipy): Implement the listener flow to register for
# nic creation events
LOG.debug("Creating nic interface for the instance")
@@ -172,11 +179,44 @@ class Instance(object):
resources['block_device_info'] = block_device_info
return resources
def get_hba_properties():
def get_hba_properties(self):
LOG.debug('Get Hba properties')
def launch(self):
self.create()
def launch(self, partition=None):
LOG.debug('Partition launch triggered')
self.instance.vm_state = vm_states.BUILDING
self.instance.task_state = task_states.SPAWNING
self.instance.save()
bootproperties = self.get_boot_properties()
self.partition.update_properties(properties=bootproperties)
result = self.partition.start(True)
# TODO(preethipy): The below method to be removed once the bug
# on DPM is fixed to return correct status on API return
self._loop_status_update(result, 5)
def _loop_status_update(self, result, iterations):
# TODO(preethipy): This method loops until the partition goes out
# of pause state or until the iterations complete. Introduced because
# of the bug in DPM for having status populated correctly only
# after 4-5 seconds
self.partition.pull_full_properties()
if (result['status'] == 'complete'):
while (self.partition.properties['status'] == 'paused') and \
(iterations):
LOG.debug("sleep for 2 seconds every iteration for"
" status check")
time.sleep(2)
iterations -= 1
def get_boot_properties(self):
LOG.debug('Retrieving boot properties for partition')
# TODO(preethipy): update the boot-device to storage-adapter
# TODO(preethipy): update the boot-storage-device with valid
# HBA uri
# TODO(preethipy): update boot-logical-unit-number and
# boot-world-wide-port-name
bootProperties = {'boot-device': 'test-operating-system'}
return bootProperties
def get_partition(self, cpc, instance):
partition = None
@@ -197,6 +237,7 @@ class InstanceInfo(object):
"""
def __init__(self, instance, cpc):
_get_zhmclient()
self.instance = instance
self.cpc = cpc
self.partition = None
@@ -205,6 +246,7 @@ class InstanceInfo(object):
for partition in partition_lists:
if partition.properties['name'] == self.instance.hostname:
self.partition = partition
self.partition.pull_full_properties()
@property
def state(self):