Merge "Remove mox and Stubs from tests/unit/pci/test_manager.py"

This commit is contained in:
Jenkins
2016-01-09 04:51:12 +00:00
committed by Gerrit Code Review

View File

@@ -21,7 +21,6 @@ from oslo_serialization import jsonutils
import nova
from nova.compute import vm_states
from nova import context
from nova import db
from nova import objects
from nova.objects import fields
from nova.pci import manager
@@ -110,7 +109,7 @@ class PciDevTrackerTestCase(test.NoDBTestCase):
def setUp(self):
super(PciDevTrackerTestCase, self).setUp()
self.fake_context = context.get_admin_context()
self.stubs.Set(db, 'pci_device_get_all_by_node',
self.stub_out('nova.db.pci_device_get_all_by_node',
self._fake_get_pci_devices)
# The fake_pci_whitelist must be called before creating the fake
# devices
@@ -274,7 +273,9 @@ class PciDevTrackerTestCase(test.NoDBTestCase):
set(['v', 'v1']))
def test_save(self):
self.stubs.Set(db, "pci_device_update", self._fake_pci_device_update)
self.stub_out(
'nova.db.pci_device_update',
self._fake_pci_device_update)
fake_pci_v3 = dict(fake_pci, address='0000:00:00.2', vendor_id='v3')
fake_pci_devs = [copy.deepcopy(fake_pci), copy.deepcopy(fake_pci_2),
copy.deepcopy(fake_pci_v3)]
@@ -284,8 +285,12 @@ class PciDevTrackerTestCase(test.NoDBTestCase):
self.assertEqual(self.update_called, 3)
def test_save_removed(self):
self.stubs.Set(db, "pci_device_update", self._fake_pci_device_update)
self.stubs.Set(db, "pci_device_destroy", self._fake_pci_device_destroy)
self.stub_out(
'nova.db.pci_device_update',
self._fake_pci_device_update)
self.stub_out(
'nova.db.pci_device_destroy',
self._fake_pci_device_destroy)
self.destroy_called = 0
self.assertEqual(len(self.tracker.pci_devs), 3)
dev = self.tracker.pci_devs[0]
@@ -366,21 +371,23 @@ class PciGetInstanceDevs(test.TestCase):
super(PciGetInstanceDevs, self).setUp()
self.fake_context = context.get_admin_context()
def test_get_devs_object(self):
@mock.patch('nova.db.instance_get')
def test_get_devs_object(self, mock_instance_get):
def _fake_obj_load_attr(foo, attrname):
if attrname == 'pci_devices':
self.load_attr_called = True
foo.pci_devices = objects.PciDeviceList()
inst = fakes.stub_instance(id='1')
self.mox.StubOutWithMock(db, 'instance_get')
db.instance_get(self.fake_context, '1', columns_to_join=[]
).AndReturn(inst)
self.mox.ReplayAll()
mock_instance_get.return_value = inst
inst = objects.Instance.get_by_id(self.fake_context, '1',
expected_attrs=[])
self.stubs.Set(objects.Instance, 'obj_load_attr', _fake_obj_load_attr)
self.stub_out(
'nova.objects.Instance.obj_load_attr',
_fake_obj_load_attr)
self.load_attr_called = False
manager.get_instance_pci_devs(inst)
self.assertEqual(self.load_attr_called, True)
mock_instance_get.assert_called_with(self.fake_context, '1',
columns_to_join=[])