From 712977fcb76c54540331dc6548906b0ec8f2c12e Mon Sep 17 00:00:00 2001 From: Devananda van der Veen Date: Tue, 4 Feb 2014 12:40:29 -0800 Subject: [PATCH] Fix log and test for NeutronAPI.update_port_dhcp_opts The unit tets for NeutronAPI.update_port_dhcp_opts were raising the wrong exception, and would pass regardless of the behaviour of update_port_dhcp_opts. This patch causes the mock to raise a neutron_client exception and correctly asserts that ironic.common.neutron.NeutronAPI converts the neutron client expcetion to an ironic exception. It also adjusts the LOG behavior of this method to properly record the exception traceback, which could be useful in determining the failure in the neutron client. Change-Id: I6f231b6a823386709b5778d140d6aa48ae4997ce --- ironic/common/neutron.py | 6 ++---- ironic/tests/test_neutron.py | 3 ++- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/ironic/common/neutron.py b/ironic/common/neutron.py index 8fb406ac31..826d0dfb1a 100644 --- a/ironic/common/neutron.py +++ b/ironic/common/neutron.py @@ -88,7 +88,5 @@ class NeutronAPI(object): try: self.client.update_port(port_id, port_req_body) except neutron_client_exc.NeutronClientException: - LOG.exception(_('Neutron error updating port: %s') % - port_id) - raise exception.FailedToUpdateDHCPOptOnPort( - port_id=port_id) + LOG.exception(_("Failed to update Neutron port %s."), port_id) + raise exception.FailedToUpdateDHCPOptOnPort(port_id=port_id) diff --git a/ironic/tests/test_neutron.py b/ironic/tests/test_neutron.py index 5a566445b7..5cc82d9257 100644 --- a/ironic/tests/test_neutron.py +++ b/ironic/tests/test_neutron.py @@ -16,6 +16,7 @@ import mock +from neutronclient.common import exceptions as neutron_client_exc from neutronclient.v2_0 import client from oslo.config import cfg @@ -108,7 +109,7 @@ class TestNeutron(base.TestCase): with mock.patch.object(client.Client, "update_port") as mock_update_port: mock_update_port.side_effect = ( - exception.FailedToUpdateDHCPOptOnPort("test exception")) + neutron_client_exc.NeutronClientException()) self.assertRaises( exception.FailedToUpdateDHCPOptOnPort, api.update_port_dhcp_opts,