Trim the fat from InstanceInfo
Nova removed several fields from InstanceInfo that were not being used [1]. This copies our corresponding in-tree driver changes to the out-of-tree driver. [1] 5db9389c01b0cb6eeacf57c22550876ffcd1a87c Closes-Bug: #1695924 Change-Id: I865d9177329294f555dfda14f2ffd85bd022db56
This commit is contained in:
parent
38bf784642
commit
a4e0721c6b
|
@ -28,10 +28,10 @@ from nova import objects
|
|||
from nova.objects import base as obj_base
|
||||
from nova.objects import block_device as bdmobj
|
||||
from nova import test
|
||||
from nova.tests.unit import fake_instance
|
||||
from nova.virt import block_device as nova_virt_bdm
|
||||
from nova.virt import driver as virt_driver
|
||||
from nova.virt import fake
|
||||
from nova.virt import hardware
|
||||
from pypowervm import adapter as pvm_adp
|
||||
from pypowervm import const as pvm_const
|
||||
from pypowervm import exceptions as pvm_exc
|
||||
|
@ -232,29 +232,28 @@ class TestPowerVMDriver(test.NoDBTestCase):
|
|||
[mock.call(powervm.TEST_INST1), mock.call(powervm.TEST_INST2)])
|
||||
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_pvm_uuid')
|
||||
@mock.patch('nova.context.get_admin_context')
|
||||
def test_driver_ops(self, mock_get_ctx, mock_getuuid):
|
||||
"""Validates the PowerVM driver operations."""
|
||||
# get_info()
|
||||
inst = fake_instance.fake_instance_obj(mock.sentinel.ctx)
|
||||
mock_getuuid.return_value = '1234'
|
||||
info = self.drv.get_info(inst)
|
||||
self.assertEqual(info.id, '1234')
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_vm_qp')
|
||||
@mock.patch('nova_powervm.virt.powervm.vm._translate_vm_state')
|
||||
def test_get_info(self, mock_tx_state, mock_qp, mock_uuid):
|
||||
mock_tx_state.return_value = 'fake-state'
|
||||
self.assertEqual(hardware.InstanceInfo('fake-state'),
|
||||
self.drv.get_info('inst'))
|
||||
mock_uuid.assert_called_once_with('inst')
|
||||
mock_qp.assert_called_once_with(
|
||||
self.drv.adapter, mock_uuid.return_value, 'PartitionState')
|
||||
mock_tx_state.assert_called_once_with(mock_qp.return_value)
|
||||
|
||||
# list_instances()
|
||||
tgt_mock = 'nova_powervm.virt.powervm.vm.get_lpar_names'
|
||||
with mock.patch(tgt_mock) as mock_get_list:
|
||||
fake_lpar_list = ['1', '2']
|
||||
mock_get_list.return_value = fake_lpar_list
|
||||
inst_list = self.drv.list_instances()
|
||||
self.assertEqual(fake_lpar_list, inst_list)
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.get_lpar_names')
|
||||
def test_list_instances(self, mock_names):
|
||||
mock_names.return_value = ['one', 'two', 'three']
|
||||
self.assertEqual(['one', 'two', 'three'], self.drv.list_instances())
|
||||
mock_names.assert_called_once_with(self.drv.adapter)
|
||||
|
||||
# instance_exists()
|
||||
tgt_mock = 'nova_powervm.virt.powervm.vm.instance_exists'
|
||||
with mock.patch(tgt_mock) as mock_inst_exists:
|
||||
mock_inst_exists.side_effect = [True, False]
|
||||
self.assertTrue(self.drv.instance_exists(mock.Mock()))
|
||||
self.assertFalse(self.drv.instance_exists(mock.Mock()))
|
||||
@mock.patch('nova_powervm.virt.powervm.vm.instance_exists')
|
||||
def test_instance_exists(self, mock_inst_exists):
|
||||
mock_inst_exists.side_effect = [True, False]
|
||||
self.assertTrue(self.drv.instance_exists(mock.Mock()))
|
||||
self.assertFalse(self.drv.instance_exists(mock.Mock()))
|
||||
|
||||
def test_instance_on_disk(self):
|
||||
"""Validates the instance_on_disk method."""
|
||||
|
|
|
@ -343,36 +343,6 @@ class TestVM(test.NoDBTestCase):
|
|||
self.assertEqual(power_state.CRASHED,
|
||||
vm._translate_vm_state('error'))
|
||||
|
||||
def test_instance_info(self):
|
||||
inst_info = vm.InstanceInfo(self.apt, 'inst_name', '1234')
|
||||
# Test the static properties
|
||||
self.assertEqual(inst_info.id, '1234')
|
||||
self.assertEqual(inst_info.cpu_time_ns, 0)
|
||||
|
||||
# Check that we raise an exception if the instance is gone.
|
||||
self.apt.read.side_effect = pvm_exc.HttpNotFound(
|
||||
mock.MagicMock(status=404))
|
||||
self.assertRaises(exception.InstanceNotFound,
|
||||
inst_info.__getattribute__, 'state')
|
||||
|
||||
# Reset the test inst_info
|
||||
inst_info = vm.InstanceInfo(self.apt, 'inst_name', '1234')
|
||||
|
||||
class FakeResp2(object):
|
||||
def __init__(self, body):
|
||||
self.body = '"%s"' % body
|
||||
|
||||
self.apt.read.side_effect = None
|
||||
self.apt.read.return_value = FakeResp2('running')
|
||||
self.assertEqual(inst_info.state, power_state.RUNNING)
|
||||
|
||||
# Check the __eq__ method
|
||||
inst_info1 = vm.InstanceInfo(self.apt, 'inst_name', '1234')
|
||||
inst_info2 = vm.InstanceInfo(self.apt, 'inst_name', '1234')
|
||||
self.assertEqual(inst_info1, inst_info2)
|
||||
inst_info2 = vm.InstanceInfo(self.apt, 'name', '4321')
|
||||
self.assertNotEqual(inst_info1, inst_info2)
|
||||
|
||||
def test_get_lpars(self):
|
||||
self.apt.read.return_value = self.resp
|
||||
lpars = vm.get_lpars(self.apt)
|
||||
|
|
|
@ -227,19 +227,12 @@ class PowerVMDriver(driver.ComputeDriver):
|
|||
'name': instance.name}, instance=instance)
|
||||
|
||||
def get_info(self, instance):
|
||||
"""Get the current status of an instance, by name (not ID!)
|
||||
"""Get the current status of an instance.
|
||||
|
||||
Returns a dict containing:
|
||||
|
||||
:state: the running state, one of the power_state codes
|
||||
:max_mem: (int) the maximum memory in KBytes allowed
|
||||
:mem: (int) the memory in KBytes used by the domain
|
||||
:num_cpu: (int) the number of virtual CPUs for the domain
|
||||
:cpu_time: (int) the CPU time used in nanoseconds
|
||||
:param instance: nova.objects.instance.Instance object
|
||||
:returns: An InstanceInfo object
|
||||
"""
|
||||
info = vm.InstanceInfo(self.adapter, instance.name,
|
||||
vm.get_pvm_uuid(instance))
|
||||
return info
|
||||
return vm.get_vm_info(self.adapter, instance)
|
||||
|
||||
def instance_exists(self, instance):
|
||||
"""Checks existence of an instance on the host.
|
||||
|
|
|
@ -563,6 +563,19 @@ def get_vm_qp(adapter, lpar_uuid, qprop=None, log_errors=True):
|
|||
return jsonutils.loads(resp.body)
|
||||
|
||||
|
||||
def get_vm_info(adapter, instance):
|
||||
"""Get the InstanceInfo for an instance.
|
||||
|
||||
:param adapter: The pypowervm.adapter.Adapter for the PowerVM REST API.
|
||||
:param instance: nova.objects.instance.Instance object
|
||||
:returns: An InstanceInfo object.
|
||||
"""
|
||||
pvm_uuid = get_pvm_uuid(instance)
|
||||
pvm_state = get_vm_qp(adapter, pvm_uuid, 'PartitionState')
|
||||
nova_state = _translate_vm_state(pvm_state)
|
||||
return hardware.InstanceInfo(nova_state)
|
||||
|
||||
|
||||
def create_lpar(adapter, host_wrapper, instance, nvram=None, slot_mgr=None):
|
||||
"""Create an LPAR based on the host based on the instance
|
||||
|
||||
|
|
Loading…
Reference in New Issue