Fix _poll_bandwidth_usage if no network on vif

Bugfix for lp901819

Move DB lookups out of the virt layer for bw usage.
Migrate to storing the mac address in the table.
Only lookup network label when sending usage events.
Attempt to use info_cache for label lookup before
    punting to rpc call.

Change-Id: Iffb4bc220804be7d5fe26d6416b90cd747b72753
This commit is contained in:
Jason Kölker
2011-12-12 16:41:40 -06:00
parent 7cd698e04a
commit e7422c5ecc
3 changed files with 86 additions and 26 deletions

View File

@@ -190,6 +190,15 @@ class BaseTestCase(test.TestCase):
class ComputeTestCase(BaseTestCase):
def setUp(self):
def fake_get_nw_info(cls, ctxt, instance):
self.assertTrue(ctxt.is_admin)
return fake_network.fake_get_instance_nw_info(self.stubs, 1, 1,
spectacular=True)
super(ComputeTestCase, self).setUp()
self.stubs.Set(nova.network.API, 'get_instance_nw_info',
fake_get_nw_info)
def test_wrap_instance_fault(self):
inst_uuid = "fake_uuid"
@@ -966,38 +975,66 @@ class ComputeTestCase(BaseTestCase):
def test_finish_resize(self):
"""Contrived test to ensure finish_resize doesn't raise anything"""
nw_info = fake_network.fake_get_instance_nw_info(self.stubs,
spectacular=True)
def fake(*args, **kwargs):
pass
def fake_nw_info(*args, **kwargs):
return nw_info
# NOTE(jkoelker) There is a bit of a stubbing issue here.
# fake_network stubs out a bunch of stuff which
# this functional test expects to be acting on
# the db or the stubs it sets.
self.stubs.UnsetAll()
self.stubs.SmartUnsetAll()
self.setUp()
self.stubs.Set(self.compute.driver, 'finish_migration', fake)
self.stubs.Set(self.compute.network_api, 'get_instance_nw_info', fake)
self.stubs.Set(self.compute.network_api, 'get_instance_nw_info',
fake_nw_info)
fake_network.stub_out_nw_api_get_instance_nw_info(self.stubs,
func=fake_nw_info)
context = self.context.elevated()
instance = self._create_fake_instance()
self.compute.prep_resize(context, instance['uuid'], 1,
filter_properties={})
migration_ref = db.migration_get_by_instance_and_status(context,
instance['uuid'], 'pre-migrating')
try:
self.compute.finish_resize(context, instance['uuid'],
int(migration_ref['id']), {})
except KeyError, e:
# Only catch key errors. We want other reasons for the test to
# fail to actually error out so we don't obscure anything
self.fail()
self.compute.finish_resize(context, instance['uuid'],
int(migration_ref['id']), {})
self.compute.terminate_instance(self.context, instance['uuid'])
def test_finish_resize_handles_error(self):
"""Make sure we don't leave the instance in RESIZE on error"""
nw_info = fake_network.fake_get_instance_nw_info(self.stubs,
spectacular=True)
def throw_up(*args, **kwargs):
raise Exception()
def fake(*args, **kwargs):
pass
def fake_nw_info(*args, **kwargs):
return nw_info
# NOTE(jkoelker) There is a bit of a stubbing issue here.
# fake_network stubs out a bunch of stuff which
# this functional test expects to be acting on
# the db or the stubs it sets.
self.stubs.UnsetAll()
self.stubs.SmartUnsetAll()
self.setUp()
self.stubs.Set(self.compute.driver, 'finish_migration', throw_up)
self.stubs.Set(self.compute.network_api, 'get_instance_nw_info', fake)
fake_network.stub_out_nw_api_get_instance_nw_info(self.stubs,
func=fake_nw_info)
context = self.context.elevated()
instance = self._create_fake_instance()
self.compute.prep_resize(context, instance['uuid'], 1,
@@ -1123,13 +1160,32 @@ class ComputeTestCase(BaseTestCase):
def test_finish_revert_resize(self):
"""Ensure that the flavor is reverted to the original on revert"""
context = self.context.elevated()
instance = self._create_fake_instance()
instance_uuid = instance['uuid']
nw_info = fake_network.fake_get_instance_nw_info(self.stubs,
spectacular=True)
def fake(*args, **kwargs):
pass
def fake_nw_info(*args, **kwargs):
return nw_info
# NOTE(jkoelker) There is a bit of a stubbing issue here.
# fake_network stubs out a bunch of stuff which
# this functional test expects to be acting on
# the db or the stubs it sets.
self.stubs.UnsetAll()
self.stubs.SmartUnsetAll()
self.setUp()
self.stubs.Set(self.compute.network_api, 'get_instance_nw_info',
fake_nw_info)
fake_network.stub_out_nw_api_get_instance_nw_info(self.stubs,
func=fake_nw_info)
context = self.context.elevated()
instance = self._create_fake_instance()
instance_uuid = instance['uuid']
self.stubs.Set(self.compute.driver, 'finish_migration', fake)
self.stubs.Set(self.compute.driver, 'finish_revert_migration', fake)
self.stubs.Set(self.compute.network_api, 'get_instance_nw_info', fake)
@@ -1450,7 +1506,14 @@ class ComputeTestCase(BaseTestCase):
class ComputeAPITestCase(BaseTestCase):
def setUp(self):
def fake_get_nw_info(cls, ctxt, instance):
self.assertTrue(ctxt.is_admin)
return fake_network.fake_get_instance_nw_info(self.stubs, 1, 1,
spectacular=True)
super(ComputeAPITestCase, self).setUp()
self.stubs.Set(nova.network.API, 'get_instance_nw_info',
fake_get_nw_info)
self.compute_api = compute.API()
self.fake_image = {
'id': 1,
@@ -2267,17 +2330,9 @@ class ComputeAPITestCase(BaseTestCase):
fixed_address):
called['associate'] = True
def fake_get_nw_info(cls, ctxt, instance):
self.assertTrue(ctxt.is_admin)
return fake_network.fake_get_instance_nw_info(self.stubs, 1, 1,
spectacular=True)
self.stubs.Set(nova.network.API, 'associate_floating_ip',
fake_associate_ip_network_api)
self.stubs.Set(nova.network.API, 'get_instance_nw_info',
fake_get_nw_info)
instance = self._create_fake_instance()
instance_uuid = instance['uuid']
address = '0.1.2.3'
@@ -2995,12 +3050,6 @@ class ComputeAPITestCase(BaseTestCase):
self.assertTrue(self.compute_api.get_lock(self.context, instance))
def test_add_remove_security_group(self):
def fake_get_nw_info(cls, ctxt, instance):
return fake_network.fake_get_instance_nw_info(self.stubs, 1, 1,
spectacular=True)
self.stubs.Set(nova.network.API, 'get_instance_nw_info',
fake_get_nw_info)
instance = self._create_fake_instance()
self.compute.run_instance(self.context, instance['uuid'])

View File

@@ -29,6 +29,7 @@ import nova.image.fake
from nova.compute import utils as compute_utils
from nova.compute import instance_types
from nova.notifier import test_notifier
from nova.tests import fake_network
LOG = logging.getLogger('nova.tests.compute_utils')
@@ -39,7 +40,15 @@ flags.DECLARE('stub_network', 'nova.compute.manager')
class UsageInfoTestCase(test.TestCase):
def setUp(self):
def fake_get_nw_info(cls, ctxt, instance):
self.assertTrue(ctxt.is_admin)
return fake_network.fake_get_instance_nw_info(self.stubs, 1, 1,
spectacular=True)
super(UsageInfoTestCase, self).setUp()
self.stubs.Set(nova.network.API, 'get_instance_nw_info',
fake_get_nw_info)
self.flags(connection_type='fake',
stub_network=True,
notification_driver='nova.notifier.test_notifier',

View File

@@ -16,6 +16,7 @@
import stubout
import nova
import nova.notifier.no_op_notifier
from nova import log
import nova.notifier.api
from nova.notifier.api import notify
@@ -26,6 +27,7 @@ class NotifierTestCase(test.TestCase):
"""Test case for notifications"""
def setUp(self):
super(NotifierTestCase, self).setUp()
self.flags(notification_driver='nova.notifier.no_op_notifier')
self.stubs = stubout.StubOutForTesting()
def tearDown(self):