Fix some straggling uses of passing context to remotable methods in tests
We are on a path to remove the implicit context argument for remotable methods when we move to oslo.versiondobjects (o.vo). In the process of doing a POC for nova using o.vo, I discovered a few straggling cases where we still depend on that in the tests. Related to blueprint kilo-objects Change-Id: I0dda2aca4dc8c30166f2a576864fe2ab2009a77a
This commit is contained in:
parent
9802c9bc6f
commit
8272dedfb8
|
@ -285,9 +285,9 @@ class BaseTestCase(test.TestCase):
|
|||
return fake_instance.fake_instance_obj(None, **updates)
|
||||
|
||||
def _create_fake_instance_obj(self, params=None, type_name='m1.tiny',
|
||||
services=False):
|
||||
services=False, context=None):
|
||||
flavor = flavors.get_flavor_by_name(type_name)
|
||||
inst = objects.Instance(context=self.context)
|
||||
inst = objects.Instance(context=context or self.context)
|
||||
inst.vm_state = vm_states.ACTIVE
|
||||
inst.task_state = None
|
||||
inst.power_state = power_state.RUNNING
|
||||
|
@ -5538,7 +5538,7 @@ class ComputeTestCase(BaseTestCase):
|
|||
# Confirm live_migration() works as expected correctly.
|
||||
# creating instance testdata
|
||||
c = context.get_admin_context()
|
||||
instance = self._create_fake_instance_obj()
|
||||
instance = self._create_fake_instance_obj(context=c)
|
||||
instance.host = self.compute.host
|
||||
dest = 'desthost'
|
||||
|
||||
|
@ -5579,7 +5579,7 @@ class ComputeTestCase(BaseTestCase):
|
|||
self.assertIsNone(ret)
|
||||
|
||||
# cleanup
|
||||
instance.destroy(c)
|
||||
instance.destroy()
|
||||
|
||||
def test_post_live_migration_no_shared_storage_working_correctly(self):
|
||||
"""Confirm post_live_migration() works correctly as expected
|
||||
|
@ -5649,11 +5649,12 @@ class ComputeTestCase(BaseTestCase):
|
|||
instance = self._create_fake_instance_obj({
|
||||
'host': srchost,
|
||||
'state_description': 'migrating',
|
||||
'state': power_state.PAUSED})
|
||||
'state': power_state.PAUSED},
|
||||
context=c)
|
||||
|
||||
instance.update({'task_state': task_states.MIGRATING,
|
||||
'power_state': power_state.PAUSED})
|
||||
instance.save(c)
|
||||
instance.save()
|
||||
|
||||
# creating mocks
|
||||
with contextlib.nested(
|
||||
|
@ -5701,10 +5702,11 @@ class ComputeTestCase(BaseTestCase):
|
|||
instance = self._create_fake_instance_obj({
|
||||
'host': self.compute.host,
|
||||
'state_description': 'migrating',
|
||||
'state': power_state.PAUSED})
|
||||
'state': power_state.PAUSED},
|
||||
context=c)
|
||||
instance.update({'task_state': task_states.MIGRATING,
|
||||
'power_state': power_state.PAUSED})
|
||||
instance.save(c)
|
||||
instance.save()
|
||||
|
||||
bdms = block_device_obj.block_device_make_list(c,
|
||||
[fake_block_device.FakeDbBlockDeviceDict({
|
||||
|
@ -7208,10 +7210,11 @@ class ComputeTestCase(BaseTestCase):
|
|||
instance = self._create_fake_instance_obj(
|
||||
params={'root_device_name': '/dev/hda'})
|
||||
bdm = objects.BlockDeviceMapping(
|
||||
context=self.context,
|
||||
**{'source_type': 'image', 'destination_type': 'local',
|
||||
'image_id': 'fake-image-id', 'device_name': '/dev/hda',
|
||||
'instance_uuid': instance.uuid})
|
||||
bdm.create(self.context)
|
||||
bdm.create()
|
||||
|
||||
self.compute.reserve_block_device_name(self.context, instance,
|
||||
'/dev/vdb', 'fake-volume-id',
|
||||
|
|
|
@ -87,8 +87,8 @@ class _TestBandwidthUsage(test.TestCase):
|
|||
def test_create(self, mock_create):
|
||||
mock_create.return_value = self.expected_bw_usage
|
||||
|
||||
bw_usage = bandwidth_usage.BandwidthUsage()
|
||||
bw_usage.create(self.context, 'fake_uuid', 'fake_mac',
|
||||
bw_usage = bandwidth_usage.BandwidthUsage(context=self.context)
|
||||
bw_usage.create('fake_uuid', 'fake_mac',
|
||||
100, 200, 12345, 67890,
|
||||
start_period=self.expected_bw_usage['start_period'])
|
||||
|
||||
|
@ -103,12 +103,12 @@ class _TestBandwidthUsage(test.TestCase):
|
|||
|
||||
mock_update.side_effect = [expected_bw_usage1, self.expected_bw_usage]
|
||||
|
||||
bw_usage = bandwidth_usage.BandwidthUsage()
|
||||
bw_usage.create(self.context, 'fake_uuid1', 'fake_mac1',
|
||||
bw_usage = bandwidth_usage.BandwidthUsage(context=self.context)
|
||||
bw_usage.create('fake_uuid1', 'fake_mac1',
|
||||
100, 200, 42, 42,
|
||||
start_period=self.expected_bw_usage['start_period'])
|
||||
self._compare(self, expected_bw_usage1, bw_usage)
|
||||
bw_usage.create(self.context, 'fake_uuid1', 'fake_mac1',
|
||||
bw_usage.create('fake_uuid1', 'fake_mac1',
|
||||
100, 200, 12345, 67890,
|
||||
start_period=self.expected_bw_usage['start_period'])
|
||||
self._compare(self, self.expected_bw_usage, bw_usage)
|
||||
|
|
|
@ -349,6 +349,7 @@ class _TestInstanceObject(object):
|
|||
inst.vm_state = 'meow'
|
||||
inst.task_state = 'wuff'
|
||||
inst.user_data = 'new'
|
||||
save_kwargs.pop('context', None)
|
||||
inst.save(**save_kwargs)
|
||||
self.assertEqual('newhost', inst.host)
|
||||
self.assertEqual('meow', inst.vm_state)
|
||||
|
|
|
@ -155,7 +155,7 @@ class _TestInstanceActionObject(object):
|
|||
mock_finish.return_value = fake_action
|
||||
action = instance_action.InstanceAction.action_start(
|
||||
self.context, 'fake-uuid', 'fake-action')
|
||||
action.finish(self.context)
|
||||
action.finish()
|
||||
mock_start.assert_called_once_with(self.context,
|
||||
expected_packed_action_start)
|
||||
mock_finish.assert_called_once_with(self.context,
|
||||
|
|
|
@ -272,11 +272,11 @@ class _TestInstanceGroupObjects(object):
|
|||
|
||||
group = instance_group.InstanceGroup.get_by_uuid(self.context,
|
||||
group.uuid)
|
||||
hosts = group.get_hosts(self.context)
|
||||
hosts = group.get_hosts()
|
||||
self.assertEqual(2, len(hosts))
|
||||
self.assertIn('hostA', hosts)
|
||||
self.assertIn('hostB', hosts)
|
||||
hosts = group.get_hosts(self.context, exclude=[instance1.uuid])
|
||||
hosts = group.get_hosts(exclude=[instance1.uuid])
|
||||
self.assertEqual(1, len(hosts))
|
||||
self.assertIn('hostB', hosts)
|
||||
|
||||
|
@ -298,7 +298,7 @@ class _TestInstanceGroupObjects(object):
|
|||
|
||||
group = instance_group.InstanceGroup.get_by_uuid(self.context,
|
||||
group.uuid)
|
||||
hosts = group.get_hosts(self.context)
|
||||
hosts = group.get_hosts()
|
||||
self.assertEqual(1, len(hosts))
|
||||
self.assertIn('hostB', hosts)
|
||||
|
||||
|
@ -333,9 +333,9 @@ class _TestInstanceGroupObjects(object):
|
|||
|
||||
group = instance_group.InstanceGroup.get_by_uuid(self.context,
|
||||
group.uuid)
|
||||
count_user1 = group.count_members_by_user(self.context, 'user1')
|
||||
count_user2 = group.count_members_by_user(self.context, 'user2')
|
||||
count_user3 = group.count_members_by_user(self.context, 'user3')
|
||||
count_user1 = group.count_members_by_user('user1')
|
||||
count_user2 = group.count_members_by_user('user2')
|
||||
count_user3 = group.count_members_by_user('user3')
|
||||
self.assertEqual(1, count_user1)
|
||||
self.assertEqual(2, count_user2)
|
||||
self.assertEqual(0, count_user3)
|
||||
|
|
|
@ -90,7 +90,7 @@ class _TestQuotasObject(object):
|
|||
|
||||
def test_reserve(self):
|
||||
fake_reservations = ['1', '2']
|
||||
quotas = quotas_obj.Quotas()
|
||||
quotas = quotas_obj.Quotas(context=self.context)
|
||||
|
||||
self.mox.StubOutWithMock(QUOTAS, 'reserve')
|
||||
QUOTAS.reserve(self.context, expire='expire',
|
||||
|
@ -98,7 +98,7 @@ class _TestQuotasObject(object):
|
|||
moo='cow').AndReturn(fake_reservations)
|
||||
|
||||
self.mox.ReplayAll()
|
||||
quotas.reserve(self.context, expire='expire',
|
||||
quotas.reserve(expire='expire',
|
||||
project_id='project_id', user_id='user_id',
|
||||
moo='cow')
|
||||
self.assertEqual(self.context, quotas._context)
|
||||
|
|
|
@ -63,9 +63,9 @@ class _TestSecurityGroupObject(object):
|
|||
self.mox.StubOutWithMock(db, 'security_group_in_use')
|
||||
db.security_group_in_use(self.context, 123).AndReturn(True)
|
||||
self.mox.ReplayAll()
|
||||
secgroup = security_group.SecurityGroup()
|
||||
secgroup = security_group.SecurityGroup(context=self.context)
|
||||
secgroup.id = 123
|
||||
self.assertTrue(secgroup.in_use(self.context))
|
||||
self.assertTrue(secgroup.in_use())
|
||||
self.assertRemotes()
|
||||
|
||||
def test_save(self):
|
||||
|
@ -76,7 +76,8 @@ class _TestSecurityGroupObject(object):
|
|||
updated_secgroup)
|
||||
self.mox.ReplayAll()
|
||||
secgroup = security_group.SecurityGroup._from_db_object(
|
||||
self.context, security_group.SecurityGroup(), fake_secgroup)
|
||||
self.context, security_group.SecurityGroup(),
|
||||
fake_secgroup)
|
||||
secgroup.description = 'foobar'
|
||||
secgroup.save()
|
||||
self.assertEqual(self._fix_deleted(updated_secgroup),
|
||||
|
@ -88,7 +89,8 @@ class _TestSecurityGroupObject(object):
|
|||
self.mox.StubOutWithMock(db, 'security_group_update')
|
||||
self.mox.ReplayAll()
|
||||
secgroup = security_group.SecurityGroup._from_db_object(
|
||||
self.context, security_group.SecurityGroup(), fake_secgroup)
|
||||
self.context, security_group.SecurityGroup(),
|
||||
fake_secgroup)
|
||||
secgroup.save()
|
||||
|
||||
def test_refresh(self):
|
||||
|
@ -97,7 +99,8 @@ class _TestSecurityGroupObject(object):
|
|||
db.security_group_get(self.context, 1).AndReturn(updated_secgroup)
|
||||
self.mox.ReplayAll()
|
||||
secgroup = security_group.SecurityGroup._from_db_object(
|
||||
self.context, security_group.SecurityGroup(), fake_secgroup)
|
||||
self.context, security_group.SecurityGroup(self.context),
|
||||
fake_secgroup)
|
||||
secgroup.refresh()
|
||||
self.assertEqual(self._fix_deleted(updated_secgroup),
|
||||
dict(secgroup.items()))
|
||||
|
|
|
@ -127,8 +127,7 @@ class _TestServiceObject(object):
|
|||
service_obj = service.Service(context=self.context)
|
||||
service_obj.host = 'fake-host'
|
||||
service_obj.create()
|
||||
self.assertRaises(exception.ObjectActionError, service_obj.create,
|
||||
self.context)
|
||||
self.assertRaises(exception.ObjectActionError, service_obj.create)
|
||||
|
||||
def test_save(self):
|
||||
self.mox.StubOutWithMock(db, 'service_update')
|
||||
|
|
|
@ -3082,10 +3082,10 @@ class XenAPIAggregateTestCase(stubs.XenAPITestBase):
|
|||
pool_states.POOL_FLAG: "XenAPI",
|
||||
pool_states.KEY: pool_states.CREATED}
|
||||
|
||||
aggregate = objects.Aggregate()
|
||||
aggregate = objects.Aggregate(context=self.context)
|
||||
aggregate.name = 'fake_aggregate'
|
||||
aggregate.metadata = dict(metadata)
|
||||
aggregate.create(self.context)
|
||||
aggregate.create()
|
||||
aggregate.add_host('host')
|
||||
self.assertEqual(["host"], aggregate.hosts)
|
||||
self.assertEqual(metadata, aggregate.metadata)
|
||||
|
@ -3149,7 +3149,7 @@ class XenAPIAggregateTestCase(stubs.XenAPITestBase):
|
|||
aggr_zone='fake_zone',
|
||||
aggr_state=pool_states.CREATED,
|
||||
hosts=['host'], metadata=None):
|
||||
aggregate = objects.Aggregate()
|
||||
aggregate = objects.Aggregate(context=self.context)
|
||||
aggregate.name = aggr_name
|
||||
aggregate.metadata = {'availability_zone': aggr_zone,
|
||||
pool_states.POOL_FLAG: 'XenAPI',
|
||||
|
@ -3157,7 +3157,7 @@ class XenAPIAggregateTestCase(stubs.XenAPITestBase):
|
|||
}
|
||||
if metadata:
|
||||
aggregate.metadata.update(metadata)
|
||||
aggregate.create(self.context)
|
||||
aggregate.create()
|
||||
for aggregate_host in hosts:
|
||||
aggregate.add_host(aggregate_host)
|
||||
return aggregate
|
||||
|
|
Loading…
Reference in New Issue