def test__update_neutron_some_failures(self, mock_updo, mock_gnvi): # confirm update is called twice, one fails, but no exception raised mock_gnvi.return_value = {"p1": "v1", "p2": "v2"} exc = exception.FailedToUpdateDHCPOptOnPort("fake exception") mock_updo.side_effect = [None, exc] with task_manager.acquire(self.context, self.node.uuid) as task: pxe._update_neutron(task) self.assertEqual(2, mock_updo.call_count)
def test__update_neutron_no_vif_data(self): with mock.patch.object(pxe, '_get_node_vif_ids') as mock_gnvi: mock_gnvi.return_value = {} with mock.patch.object(neutron.NeutronAPI, '__init__') as mock_init: with task_manager.acquire(self.context, self.node.uuid) as task: pxe._update_neutron(task, self.node) mock_init.assert_not_called()
def test__update_neutron(self): opts = pxe._dhcp_options_for_instance() with mock.patch.object(pxe, '_get_node_vif_ids') as mock_gnvi: mock_gnvi.return_value = {'port-uuid': 'vif-uuid'} with mock.patch.object(neutron.NeutronAPI, 'update_port_dhcp_opts') as mock_updo: with task_manager.acquire(self.context, self.node.uuid) as task: pxe._update_neutron(task, self.node) mock_updo.assertCalleOnceWith('vif-uuid', opts)
def test__update_neutron_some_failures(self): # confirm update is called twice, one fails, but no exception raised with mock.patch.object(pxe, '_get_node_vif_ids') as mock_gnvi: mock_gnvi.return_value = {'p1': 'v1', 'p2': 'v2'} with mock.patch.object(neutron.NeutronAPI, 'update_port_dhcp_opts') as mock_updo: exc = exception.FailedToUpdateDHCPOptOnPort('fake exception') mock_updo.side_effect = [None, exc] with task_manager.acquire(self.context, self.node.uuid) as task: pxe._update_neutron(task, self.node) self.assertEqual(2, mock_updo.call_count)
def test__update_neutron_no_vif_data(self, mock_init, mock_gnvi): mock_gnvi.return_value = {} with task_manager.acquire(self.context, self.node.uuid) as task: pxe._update_neutron(task) self.assertFalse(mock_init.called)
def test__update_neutron(self, mock_updo, mock_gnvi): opts = pxe._dhcp_options_for_instance() mock_gnvi.return_value = {"port-uuid": "vif-uuid"} with task_manager.acquire(self.context, self.node.uuid) as task: pxe._update_neutron(task) mock_updo.assert_called_once_with("vif-uuid", opts)