diff options
author | Brian Elliott <brian.elliott@rackspace.com> | 2012-10-08 18:35:14 +0000 |
---|---|---|
committer | Brian Elliott <brian.elliott@rackspace.com> | 2012-10-08 20:16:34 +0000 |
commit | 5fd7a9dba127bae812333196a5fa48a933212aeb (patch) | |
tree | 7018c19caeb106bb30f9fb8f9da2b7224ae7be8b /nova/tests | |
parent | 9d4ecc2c553b85f2fccf444498df15b09b6fe54b (diff) | |
download | nova-5fd7a9dba127bae812333196a5fa48a933212aeb.tar.gz nova-5fd7a9dba127bae812333196a5fa48a933212aeb.tar.xz nova-5fd7a9dba127bae812333196a5fa48a933212aeb.zip |
Set instance host field after resource claim
Set the 'host' field on the instance after the resource tracker
on the compute node has accepted the build.
The field is set after resources are confirmed to be available while the
COMPUTE_RESOURCES_SEMAPHORE is held. The semaphore ensures the
resources usage values will be consistent even if the
update_available_resource periodic task audit runs.
bug 1060255
Change-Id: I92105ec14924960ac8ef7ca8c810783085314e10
Diffstat (limited to 'nova/tests')
-rw-r--r-- | nova/tests/compute/test_resource_tracker.py | 36 | ||||
-rw-r--r-- | nova/tests/scheduler/test_chance_scheduler.py | 8 | ||||
-rw-r--r-- | nova/tests/scheduler/test_scheduler.py | 2 |
3 files changed, 26 insertions, 20 deletions
diff --git a/nova/tests/compute/test_resource_tracker.py b/nova/tests/compute/test_resource_tracker.py index 04b2dfdba..61d728ba4 100644 --- a/nova/tests/compute/test_resource_tracker.py +++ b/nova/tests/compute/test_resource_tracker.py @@ -22,6 +22,7 @@ import uuid from nova.compute import resource_tracker from nova.compute import task_states from nova.compute import vm_states +from nova import context from nova import db from nova import exception from nova.openstack.common import log as logging @@ -32,14 +33,6 @@ from nova.virt import driver LOG = logging.getLogger(__name__) -class FakeContext(object): - def __init__(self, is_admin=False): - self.is_admin = is_admin - - def elevated(self): - return FakeContext(is_admin=True) - - class UnsupportedVirtDriver(driver.ComputeDriver): """Pretend version of a lame virt driver""" def get_available_resource(self): @@ -81,11 +74,13 @@ class BaseTestCase(test.TestCase): self.flags(reserved_host_disk_mb=0, reserved_host_memory_mb=0) - self.context = FakeContext() + self.context = context.RequestContext('fake', 'fake') - self._instances = [] + self._instances = {} self.stubs.Set(db, 'instance_get_all_by_host', - lambda c, h: self._instances) + lambda c, h: self._instances.values()) + self.stubs.Set(db, 'instance_update_and_get_original', + self._fake_instance_update_and_get_original) def _create_compute_node(self, values=None): compute = { @@ -122,8 +117,10 @@ class BaseTestCase(test.TestCase): return service def _fake_instance(self, *args, **kwargs): + + instance_uuid = str(uuid.uuid1()) instance = { - 'uuid': str(uuid.uuid1()), + 'uuid': instance_uuid, 'vm_state': vm_states.BUILDING, 'task_state': None, 'memory_mb': 2, @@ -136,9 +133,17 @@ class BaseTestCase(test.TestCase): } instance.update(kwargs) - self._instances.append(instance) + self._instances[instance_uuid] = instance return instance + def _fake_instance_update_and_get_original(self, context, instance_uuid, + values): + instance = self._instances[instance_uuid] + instance.update(values) + # the test doesn't care what the original instance values are, it's + # only used in the subsequent notification: + return (instance, instance) + def _tracker(self, unsupported=False): host = "fakehost" @@ -168,7 +173,8 @@ class UnsupportedDriverTestCase(BaseTestCase): def testDisabledClaim(self): # basic claim: - claim = self.tracker.begin_resource_claim(self.context, 1, 1) + instance = self._fake_instance() + claim = self.tracker.begin_resource_claim(self.context, instance) self.assertEqual(None, claim) def testDisabledInstanceClaim(self): @@ -200,7 +206,7 @@ class UnsupportedDriverTestCase(BaseTestCase): class MissingServiceTestCase(BaseTestCase): def setUp(self): super(MissingServiceTestCase, self).setUp() - self.context = FakeContext(is_admin=True) + self.context = context.get_admin_context() self.tracker = self._tracker() def testMissingService(self): diff --git a/nova/tests/scheduler/test_chance_scheduler.py b/nova/tests/scheduler/test_chance_scheduler.py index 4fb9ab617..26cde055b 100644 --- a/nova/tests/scheduler/test_chance_scheduler.py +++ b/nova/tests/scheduler/test_chance_scheduler.py @@ -90,8 +90,8 @@ class ChanceSchedulerTestCase(test_scheduler.SchedulerTestCase): self.driver.hosts_up(ctxt_elevated, 'compute').AndReturn( ['host1', 'host2', 'host3', 'host4']) random.random().AndReturn(.5) - driver.instance_update_db(ctxt, instance1['uuid'], - 'host3').WithSideEffects(inc_launch_index).AndReturn(instance1) + driver.instance_update_db(ctxt, instance1['uuid']).WithSideEffects( + inc_launch_index).AndReturn(instance1) compute_rpcapi.ComputeAPI.run_instance(ctxt, host='host3', instance=instance1, requested_networks=None, injected_files=None, admin_password=None, is_first_time=None, @@ -102,8 +102,8 @@ class ChanceSchedulerTestCase(test_scheduler.SchedulerTestCase): self.driver.hosts_up(ctxt_elevated, 'compute').AndReturn( ['host1', 'host2', 'host3', 'host4']) random.random().AndReturn(.2) - driver.instance_update_db(ctxt, instance2['uuid'], - 'host1').WithSideEffects(inc_launch_index).AndReturn(instance2) + driver.instance_update_db(ctxt, instance2['uuid']).WithSideEffects( + inc_launch_index).AndReturn(instance2) compute_rpcapi.ComputeAPI.run_instance(ctxt, host='host1', instance=instance2, requested_networks=None, injected_files=None, admin_password=None, is_first_time=None, diff --git a/nova/tests/scheduler/test_scheduler.py b/nova/tests/scheduler/test_scheduler.py index 83e9cffc8..af297b589 100644 --- a/nova/tests/scheduler/test_scheduler.py +++ b/nova/tests/scheduler/test_scheduler.py @@ -712,7 +712,7 @@ class SchedulerDriverModuleTestCase(test.TestCase): timeutils.utcnow().AndReturn('fake-now') db.instance_update(self.context, 'fake_uuid', - {'host': host, 'scheduled_at': 'fake-now'}) + {'host': None, 'scheduled_at': 'fake-now'}) rpc.queue_get_for(self.context, 'compute', host).AndReturn(queue) rpc.cast(self.context, queue, {'method': method, |