Failed to sync nova-powervc as kilo source codes change

Provides some fixes for kilo nova base code changed.

Change-Id: I2b7da3b688e88084939f10cf060c2b7ecc5e0a55
Closes-Bug:1408888
This commit is contained in:
Jerry Cai 2015-01-09 13:38:58 +08:00
parent ecdc1066a7
commit b06a892915
4 changed files with 46 additions and 18 deletions

View File

@ -304,7 +304,9 @@ class PowerVCCloudManager(manager.Manager):
# the hosting OS and PowerVC.
base_options['display_name'] = local_instance.get('display_name')
self.compute_api.update(context, local_instance, **base_options)
inst = instance_obj.Instance.get_by_uuid(context,
local_instance.get('uuid'))
self.compute_api.update(context, inst, **base_options)
LOG.debug('update local db instance: %s with '
'data: %s' % (local_instance, base_options))
self.sync_volume_attachment(context,
@ -470,7 +472,7 @@ class PowerVCCloudManager(manager.Manager):
ins, image, flavor = self._translate_pvc_instance(ctx, pvc_instance)
security_group_map = self.\
_get_security_group_for_instance(ctx, pvc_instance)
new_instance = instance_obj.Instance()
new_instance = instance_obj.Instance(ctx)
new_instance.update(ins)
block_device_map = [block_device.create_image_bdm(image['id'])]
db_instance = self.compute_api.\
@ -507,9 +509,11 @@ class PowerVCCloudManager(manager.Manager):
self._fix_instance_nw_info(ctx, db_instance)
# Send notification about instance creation due to sync operation
# Need to get a instance object rather than db instance as the related
# API changed
inst = instance_obj.Instance.get_by_uuid(ctx, db_instance['uuid'])
compute.utils.notify_about_instance_usage(
self.notifier, ctx, db_instance, 'create.sync', network_info={},
system_metadata={}, extra_usage_info={})
self.notifier, ctx, inst, 'create.sync')
LOG.debug('exiting to insert local instance for: %s' % pvc_instance)
# Remove an instance that is not in pvc anymore from local DB.
@ -925,7 +929,7 @@ class PowerVCCloudManager(manager.Manager):
LOG.info(_("Return the first public "
"PowerVC flavor that fits "
"into the resource "
"instance instead"), rtn)
"instance instead"))
break
if rtn is None:
for key in rtns.keys():

View File

@ -11,6 +11,7 @@ from nova.openstack.common import log as logging
from oslo.utils import excutils
from powervc.nova.driver.virt.powervc import service
from powervc.nova.driver.compute import constants
from powervc.nova.driver.virt.powervc import pvc_vm_states
from powervc.nova.common import exception as pvc_exception
from powervc.common.client import factory
from powervc.common.gettextutils import _
@ -143,11 +144,12 @@ class PowerVCDriver(driver.ComputeDriver):
max_mem = self._int_or_none(lpar_instance._info.get('max_memory_mb'))
mem = self._int_or_none(lpar_instance._info.get('memory_mb'))
num_cpu = self._int_or_none(lpar_instance._info.get('cpus'))
return {'state': lpar_instance._info['OS-EXT-STS:power_state'],
'max_mem': max_mem,
'mem': mem,
'num_cpu': num_cpu,
'cpu_time': 0}
hardwareInfo = pvc_vm_states.InstanceInfo(
state=lpar_instance._info['OS-EXT-STS:power_state'],
max_mem_kb=max_mem,
mem_kb=mem,
num_cpu=num_cpu)
return hardwareInfo
def get_num_instances(self):
"""Return the total number of virtual machines.

View File

@ -7,3 +7,27 @@ SHUTOFF = u'SHUTOFF'
RESIZE = u'RESIZE'
VERIFY_RESIZE = u'VERIFY_RESIZE'
MIGRATING = u' MIGRATING'
class InstanceInfo(object):
def __init__(self, state=None, max_mem_kb=0, mem_kb=0, num_cpu=0,
cpu_time_ns=0):
"""Create a new Instance Info object
:param state: the running state, one of the power_state codes
:param max_mem_kb: (int) the maximum memory in KBytes allowed
:param mem_kb: (int) the memory in KBytes used by the instance
:param num_cpu: (int) the number of virtual CPUs for the instance
:param cpu_time_ns: (int) the CPU time used in nanoseconds
:param id: a unique ID for the instance
"""
self.state = state
self.max_mem_kb = max_mem_kb
self.mem_kb = mem_kb
self.num_cpu = num_cpu
self.cpu_time_ns = cpu_time_ns
def __eq__(self, other):
return (self.__class__ == other.__class__ and
self.__dict__ == other.__dict__)

View File

@ -834,14 +834,12 @@ class TestGetInfo(testtools.TestCase):
"""When everything is fine in the main path."""
self.pvc_drv.get_instance = \
mock.MagicMock(return_value=self.pvc_instance)
self.assertEqual(self.pvc_drv.get_info(self.os_instance),
{'state': 1,
'max_mem': 8192,
'mem': 2048,
'num_cpu': 2,
'cpu_time': 0
}
)
hardwareInfo = pvc_vm_states.InstanceInfo(
state=1,
max_mem_kb=8192,
mem_kb=2048,
num_cpu=2)
self.assertEqual(self.pvc_drv.get_info(self.os_instance), hardwareInfo)
def test_get_info_instance_not_found_0(self):
"""When any exception occurred during fetch PVC LPAR instance."""