Move declaration of int_br_device_count earlier

_report_state is being called by setup_rpc so int_br_device_count needs
to be initialized earlier. To avoid
AttributeError: object has no attribute 'int_br_device_count'

This wasn't caught by unit tests for 3 separate reason
o The reference to self.int_br_device_count is wrapped in
  except Exception: log / pass
- This reference has been moved outside of the try/except

o Unit tests set report_interval to 0 so the heartbeat wasn't called
  during unit tests.
- now removed

o The function passed into FixedIntervalLoopingCall isn't started
  anyways so wasn't calling self._report_state
- replaced FixedIntervalLoopingCall with a mock that calls the
  function once.

Fixes bug #1221054

Change-Id: I572af4ee017c1f7f016c8f9981ca54d1301442d1
This commit is contained in:
Derek Higgins
2013-09-04 23:05:08 +01:00
parent 062ee16e09
commit becadd39df
2 changed files with 17 additions and 8 deletions

View File

@@ -179,6 +179,9 @@ class OVSNeutronAgent(sg_rpc.SecurityGroupAgentRpcCallbackMixin):
'agent_type': q_const.AGENT_TYPE_OVS,
'start_flag': True}
# Keep track of int_br's device count for use by _report_state()
self.int_br_device_count = 0
self.int_br = ovs_lib.OVSBridge(integ_br, self.root_helper)
self.setup_rpc()
self.setup_integration_br()
@@ -202,9 +205,6 @@ class OVSNeutronAgent(sg_rpc.SecurityGroupAgentRpcCallbackMixin):
# Collect additional bridges to monitor
self.ancillary_brs = self.setup_ancillary_bridges(integ_br, tun_br)
# Keep track of int_br's device count for use by _report_state()
self.int_br_device_count = 0
# Security group agent supprot
self.sg_agent = OVSSecurityGroupAgent(self.context,
self.plugin_rpc,
@@ -216,10 +216,10 @@ class OVSNeutronAgent(sg_rpc.SecurityGroupAgentRpcCallbackMixin):
self.root_helper)
def _report_state(self):
# How many devices are likely used by a VM
self.agent_state.get('configurations')['devices'] = (
self.int_br_device_count)
try:
# How many devices are likely used by a VM
self.agent_state.get('configurations')['devices'] = (
self.int_br_device_count)
self.state_rpc.report_state(self.context,
self.agent_state)
self.agent_state.pop('start_flag', None)

View File

@@ -96,9 +96,15 @@ class TestOvsNeutronAgent(base.BaseTestCase):
# Avoid rpc initialization for unit tests
cfg.CONF.set_override('rpc_backend',
'neutron.openstack.common.rpc.impl_fake')
cfg.CONF.set_override('report_interval', 0, 'AGENT')
kwargs = ovs_neutron_agent.create_agent_config_map(cfg.CONF)
class MockFixedIntervalLoopingCall(object):
def __init__(self, f):
self.f = f
def start(self, interval=0):
self.f()
with contextlib.nested(
mock.patch('neutron.plugins.openvswitch.agent.ovs_neutron_agent.'
'OVSNeutronAgent.setup_integration_br',
@@ -110,7 +116,10 @@ class TestOvsNeutronAgent(base.BaseTestCase):
'get_local_port_mac',
return_value='00:00:00:00:00:01'),
mock.patch('neutron.agent.linux.utils.get_interface_mac',
return_value='00:00:00:00:00:01')):
return_value='00:00:00:00:00:01'),
mock.patch('neutron.openstack.common.loopingcall.'
'FixedIntervalLoopingCall',
new=MockFixedIntervalLoopingCall)):
self.agent = ovs_neutron_agent.OVSNeutronAgent(**kwargs)
self.agent.tun_br = mock.Mock()
self.agent.sg_agent = mock.Mock()