def test_treat_devices_removed_with_existed_device(self, *args): agent = sriov_nic_agent.SriovNicSwitchAgent({}, {}, 0) devices = [(DEVICE_MAC, PCI_SLOT)] with mock.patch.object(agent.plugin_rpc, "update_device_down") as fn_udd: fn_udd.return_value = {'device': DEVICE_MAC, 'exists': True} resync = agent.treat_devices_removed(devices) self.assertFalse(resync) self.assertTrue(fn_udd.called)
def test_report_loaded_extension(self, *args): with mock.patch.object(agent_rpc.PluginReportStateAPI, 'report_state') as mock_report_state: agent = sriov_nic_agent.SriovNicSwitchAgent({}, {}, 0, {}, {}) agent._report_state() mock_report_state.assert_called_with(agent.context, agent.agent_state) self.assertEqual(['qos'], agent.agent_state['configurations']['extensions'])
def test_configurations_has_rp_bandwidth(self): rp_bandwidth = {'ens7': {'egress': 10000, 'ingress': 10000}} agent = sriov_nic_agent.SriovNicSwitchAgent({}, {}, 0, rp_bandwidth, {}) self.assertIn(c_const.RP_BANDWIDTHS, agent.agent_state['configurations']) rp_bandwidths = agent.agent_state['configurations'][ c_const.RP_BANDWIDTHS] self.assertEqual(rp_bandwidth['ens7'], rp_bandwidths['ens7'])
def test_treat_devices_removed_failed(self, *args): agent = sriov_nic_agent.SriovNicSwitchAgent({}, {}, 0) devices = [(DEVICE_MAC, PCI_SLOT)] with mock.patch.object(agent.plugin_rpc, "update_device_down") as fn_udd: fn_udd.side_effect = Exception() with mock.patch.object(sriov_nic_agent.LOG, 'debug') as log: resync = agent.treat_devices_removed(devices) self.assertEqual(1, log.call_count) self.assertTrue(resync) self.assertTrue(fn_udd.called)
def test_treat_devices_removed_with_not_existed_device(self): agent = sriov_nic_agent.SriovNicSwitchAgent({}, {}, 0) devices = [DEVICE_MAC] with mock.patch.object(agent.plugin_rpc, "update_device_down") as fn_udd: fn_udd.return_value = {'device': DEVICE_MAC, 'exists': False} with mock.patch.object(sriov_nic_agent.LOG, 'debug') as log: resync = agent.treat_devices_removed(devices) self.assertEqual(1, log.call_count) self.assertFalse(resync) self.assertTrue(fn_udd.called)
def test_configurations_has_rp_default_inventory(self): rp_inventory_values = { 'allocation_ratio': 1.0, 'min_unit': 1, 'step_size': 1, 'reserved': 0 } agent = sriov_nic_agent.SriovNicSwitchAgent({}, {}, 0, {}, rp_inventory_values) self.assertIn(c_const.RP_INVENTORY_DEFAULTS, agent.agent_state['configurations']) rp_inv_defaults = agent.agent_state['configurations'][ c_const.RP_INVENTORY_DEFAULTS] self.assertListEqual(sorted(list(rp_inventory_values)), sorted(list(rp_inv_defaults.keys()))) for inv_key, inv_value in rp_inventory_values.items(): self.assertEqual(inv_value, rp_inv_defaults[inv_key])
def setUp(self): super(TestSriovAgent, self).setUp() # disable setting up periodic state reporting cfg.CONF.set_override('report_interval', 0, 'AGENT') cfg.CONF.set_default('firewall_driver', 'neutron.agent.firewall.NoopFirewallDriver', group='SECURITYGROUP') cfg.CONF.set_default('enable_security_group', False, group='SECURITYGROUP') class MockFixedIntervalLoopingCall(object): def __init__(self, f): self.f = f def start(self, interval=0): self.f() mock.patch('oslo_service.loopingcall.' 'FixedIntervalLoopingCall', new=MockFixedIntervalLoopingCall) self.agent = sriov_nic_agent.SriovNicSwitchAgent({}, {}, 0)