Skip to content

Commit

Permalink
Merge "Prevent creation of extraneous resource trackers."
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins authored and openstack-gerrit committed Dec 7, 2012
2 parents 87e609c + 7f06537 commit 86cc905
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
12 changes: 10 additions & 2 deletions nova/compute/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,11 @@ def __init__(self, compute_driver=None, *args, **kwargs):
def _get_resource_tracker(self, nodename):
rt = self._resource_tracker_dict.get(nodename)
if not rt:
if nodename not in self.driver.get_available_nodes():
msg = _("%(nodename)s is not a valid node managed by this "
"compute host.") % locals()
raise exception.NovaException(msg)

rt = resource_tracker.ResourceTracker(self.host,
self.driver,
nodename)
Expand All @@ -342,8 +347,11 @@ def _instance_update(self, context, instance_uuid, **kwargs):
instance_ref = self.conductor_api.instance_update(context,
instance_uuid,
**kwargs)
rt = self._get_resource_tracker(instance_ref.get('node'))
rt.update_usage(context, instance_ref)
if (instance_ref['host'] == self.host and
instance_ref['node'] in self.driver.get_available_nodes()):

rt = self._get_resource_tracker(instance_ref.get('node'))
rt.update_usage(context, instance_ref)

return instance_ref

Expand Down
21 changes: 21 additions & 0 deletions nova/tests/compute/test_compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -2971,6 +2971,27 @@ def fake_set_instance_error_state(_ctxt, instance_uuid, **kwargs):
self.assertTrue(called['get_all'])
self.assertEqual(called['set_error_state'], 4)

def test_get_resource_tracker_fail(self):
self.assertRaises(exception.NovaException,
self.compute._get_resource_tracker,
'invalidnodename')

def test_instance_update_host_check(self):
# make sure rt usage doesn't happen if the host or node is different
def fail_get(nodename):
raise test.TestingException(_("wrong host/node"))
self.stubs.Set(self.compute, '_get_resource_tracker', fail_get)

instance = self._create_fake_instance({'host': 'someotherhost'})
self.compute._instance_update(self.context, instance['uuid'])

instance = self._create_fake_instance({'node': 'someothernode'})
self.compute._instance_update(self.context, instance['uuid'])

params = {'host': 'someotherhost', 'node': 'someothernode'}
instance = self._create_fake_instance(params)
self.compute._instance_update(self.context, instance['uuid'])


class ComputeAPITestCase(BaseTestCase):

Expand Down

0 comments on commit 86cc905

Please sign in to comment.