Convert local fakes to nova objects

Convert fake instance and flavors to actual nova objects.
This will allow logging code that is expecting a nova object
(like an instance) to process it correctly during UT.

Change-Id: I2a82ad29b75110a505a6c8df11ef7f49b47cfa4d
This commit is contained in:
Kyle L. Henderson 2015-01-23 10:38:53 -06:00
parent 5a48a29b5c
commit a89cd84ec0
3 changed files with 43 additions and 46 deletions

View File

@ -18,6 +18,27 @@
import os
import sys
SYS_META = {
'instance_type_memory_mb': 2048,
'instance_type_swap': 0,
'instance_type_vcpu_weight': None,
'instance_type_root_gb': 1,
'instance_type_id': 2,
'instance_type_name': u'm1.small',
'instance_type_ephemeral_gb': 0,
'instance_type_rxtx_factor': 1.0,
'instance_type_flavorid': u'1',
'instance_type_vcpus': 1
}
TEST_INSTANCE = {
'id': 1,
'uuid': '49629a5c-f4c4-4721-9511-9725786ff2e5',
'display_name': 'Fake Instance',
'instance_type_id': '5',
'system_metadata': SYS_META
}
# NOTE(mikal): All of this is because if dnspython is present in your
# environment then eventlet monkeypatches socket.getaddrinfo() with an
# implementation which doesn't work for IPv6. What we're checking here is

View File

@ -20,12 +20,15 @@ import logging
import mock
from nova import exception as exc
from nova import objects
from nova import test
from nova.tests.unit import fake_instance
from nova.virt import fake
from pypowervm.tests.wrappers.util import pvmhttp
from pypowervm.wrappers import constants as wpr_consts
import pypowervm.wrappers.managed_system as msentry_wrapper
from nova_powervm.tests.virt import powervm
from nova_powervm.virt.powervm import driver
from nova_powervm.virt.powervm import host as pvm_host
@ -36,21 +39,6 @@ LOG = logging.getLogger(__name__)
logging.basicConfig()
class FakeInstance(object):
def __init__(self):
self.name = 'fake_instance'
self.display_name = 'fake_display_name'
self.instance_type_id = 'instance_type_id'
self.uuid = 'fake_uuid'
class FakeFlavor(object):
def __init__(self):
self.name = 'fake_flavor'
self.memory_mb = 256
self.vcpus = 1
class TestPowerVMDriver(test.TestCase):
def setUp(self):
super(TestPowerVMDriver, self).setUp()
@ -104,7 +92,7 @@ class TestPowerVMDriver(test.TestCase):
drv.adapter = mock_apt
# get_info()
inst = FakeInstance()
inst = fake_instance.fake_instance_obj(mock.sentinel.ctx)
mock_uuidcache.lookup.return_value = '1234'
drv.pvm_uuids = mock_uuidcache
info = drv.get_info(inst)
@ -138,8 +126,8 @@ class TestPowerVMDriver(test.TestCase):
drv.adapter = mock_apt
# Set up the mocks to the tasks.
inst = FakeInstance()
my_flavor = FakeFlavor()
inst = objects.Instance(**powervm.TEST_INSTANCE)
my_flavor = inst.get_flavor()
mock_get_flv.return_value = my_flavor
mock_crt.return_value = mock.MagicMock()
mock_cfg_drv.return_value = False
@ -180,8 +168,8 @@ class TestPowerVMDriver(test.TestCase):
drv.adapter = mock_apt
# Set up the mocks to the tasks.
inst = FakeInstance()
my_flavor = FakeFlavor()
inst = objects.Instance(**powervm.TEST_INSTANCE)
my_flavor = inst.get_flavor()
mock_get_flv.return_value = my_flavor
mock_crt.return_value = mock.MagicMock()
mock_cfg_drv.return_value = True
@ -220,8 +208,8 @@ class TestPowerVMDriver(test.TestCase):
drv.adapter = mock_apt
# Set up the mocks to the tasks.
inst = FakeInstance()
my_flavor = FakeFlavor()
inst = objects.Instance(**powervm.TEST_INSTANCE)
my_flavor = inst.get_flavor()
mock_get_flv.return_value = my_flavor
mock_crt.return_value = mock.MagicMock()
mock_cfg_drv.return_value = False
@ -247,11 +235,12 @@ class TestPowerVMDriver(test.TestCase):
def test_log_op(self, mock_log):
"""Validates the log_operations."""
drv = driver.PowerVMDriver(fake.FakeVirtAPI())
inst = FakeInstance()
inst = objects.Instance(**powervm.TEST_INSTANCE)
drv._log_operation('fake_op', inst)
entry = ('Operation: fake_op. Virtual machine display name: '
'fake_display_name, name: fake_instance, UUID: fake_uuid')
entry = ('Operation: fake_op. Virtual machine display '
'name: Fake Instance, name: instance-00000001, '
'UUID: 49629a5c-f4c4-4721-9511-9725786ff2e5')
mock_log.info.assert_called_with(entry)
def test_host_resources(self):

View File

@ -21,10 +21,12 @@ import mock
from nova.compute import power_state
from nova import exception
from nova import objects
from nova import test
from pypowervm import exceptions as pvm_exc
from pypowervm.tests.wrappers.util import pvmhttp
from nova_powervm.tests.virt import powervm
from nova_powervm.virt.powervm import vm
LPAR_HTTPRESP_FILE = "lpar.txt"
@ -43,18 +45,6 @@ class FakeAdapterResponse(object):
self.status = status
class FakeInstance(object):
def __init__(self):
self.name = 'fake_instance'
class FakeFlavor(object):
def __init__(self):
self.name = 'fake_flavor'
self.memory_mb = 256
self.vcpus = 1
class TestVM(test.TestCase):
def setUp(self):
super(TestVM, self).setUp()
@ -165,11 +155,8 @@ class TestVM(test.TestCase):
@mock.patch('pypowervm.wrappers.logical_partition.crt_shared_procs')
@mock.patch('pypowervm.wrappers.logical_partition.crt_lpar')
def test_crt_lpar(self, mock_crt_lpar, mock_crt_sp, mock_adr):
instance = FakeInstance()
instance.name = 'Fake'
flavor = FakeFlavor()
flavor.memory_mb = 100
instance = objects.Instance(**powervm.TEST_INSTANCE)
flavor = instance.get_flavor()
# Create a side effect that can validate the input into the create
# call.
@ -185,15 +172,15 @@ class TestVM(test.TestCase):
def validate_of_create_lpar(*kargs, **kwargs):
instance_name = kargs[0]
self.assertEqual('Fake', instance_name)
self.assertEqual('instance-00000001', instance_name)
_type = kargs[1]
self.assertEqual('AIX/Linux', _type)
# sprocs = kargs[2]
mem = kargs[3]
self.assertEqual('100', mem)
self.assertEqual('2048', mem)
self.assertEqual('100', kwargs.get('min_mem'))
self.assertEqual('100', kwargs.get('max_mem'))
self.assertEqual('2048', kwargs.get('min_mem'))
self.assertEqual('2048', kwargs.get('max_mem'))
self.assertEqual('64', kwargs.get('max_io_slots'))
mock_crt_lpar.side_effect = validate_of_create_lpar