def test_call_driver(self): network = mock.Mock() network.id = '1' with mock.patch('quantum.agent.dhcp_agent.DeviceManager') as dev_mgr: dhcp = dhcp_agent.DhcpAgent(cfg.CONF) self.assertTrue(dhcp.call_driver('foo', network)) self.assertTrue(dev_mgr.called) self.driver.assert_called_once_with(cfg.CONF, mock.ANY, 'sudo', mock.ANY, 'qdhcp-1')
def test_call_driver_failure(self): network = mock.Mock() network.id = '1' self.driver.return_value.foo.side_effect = Exception with mock.patch('quantum.agent.dhcp_agent.DeviceManager') as dev_mgr: with mock.patch.object(dhcp_agent.LOG, 'exception') as log: dhcp = dhcp_agent.DhcpAgent(HOSTNAME) self.assertIsNone(dhcp.call_driver('foo', network)) self.assertTrue(dev_mgr.called) self.driver.assert_called_once_with(cfg.CONF, mock.ANY, 'sudo', mock.ANY, 'qdhcp-1') self.assertEqual(log.call_count, 1) self.assertTrue(dhcp.needs_resync)