From: Adrien Vergé Date: Mon, 25 May 2015 16:46:03 +0000 (+0200) Subject: Fix indentation errors in tests X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=880252868b8509125f6463e2709c2d0c4f3957ea;p=openstack-build%2Fneutron-build.git Fix indentation errors in tests They are some missing/extra indentations in tests source code. This results in variables used out their scope (which remains unnoticed as long as `with` contexts do not fail), and prevent refactoring scripts (such as the one for getting rid of `contextlib.nested` [1]) from performing well. This simple patch fixes these indentation errors. [1]: See change I8d1de09ff38ed0af9fb56f423a2c43476408e0fb Change-Id: Icef34c7755e0d96c4c5ee85982de86d0ccc196c7 Related-Blueprint: neutron-python3 --- diff --git a/neutron/tests/unit/api/rpc/handlers/test_securitygroups_rpc.py b/neutron/tests/unit/api/rpc/handlers/test_securitygroups_rpc.py index 672806209..4728e3de3 100644 --- a/neutron/tests/unit/api/rpc/handlers/test_securitygroups_rpc.py +++ b/neutron/tests/unit/api/rpc/handlers/test_securitygroups_rpc.py @@ -28,10 +28,10 @@ class SecurityGroupServerRpcApiTestCase(base.BaseTestCase): prepare_mock.return_value = rpcapi.client rpcapi.security_group_rules_for_devices('context', ['fake_device']) - rpc_mock.assert_called_once_with( - 'context', - 'security_group_rules_for_devices', - devices=['fake_device']) + rpc_mock.assert_called_once_with( + 'context', + 'security_group_rules_for_devices', + devices=['fake_device']) class SGAgentRpcCallBackMixinTestCase(base.BaseTestCase): diff --git a/neutron/tests/unit/extensions/test_l3.py b/neutron/tests/unit/extensions/test_l3.py index 35a632dfa..2e67d40f0 100644 --- a/neutron/tests/unit/extensions/test_l3.py +++ b/neutron/tests/unit/extensions/test_l3.py @@ -1170,19 +1170,19 @@ class L3NatTestCaseBase(L3NatTestCaseMixin): with contextlib.nested( self.subnet(network=n1, cidr='10.0.0.0/24'), self.subnet(network=n2, cidr='10.1.0.0/24')) as (s1, s2): - body = self._router_interface_action( - 'add', - r['router']['id'], - s2['subnet']['id'], - None) - self.assertIn('port_id', body) - self._router_interface_action( - 'add', - r['router']['id'], - s1['subnet']['id'], - None, - tenant_id=tenant_id) - self.assertIn('port_id', body) + body = self._router_interface_action( + 'add', + r['router']['id'], + s2['subnet']['id'], + None) + self.assertIn('port_id', body) + self._router_interface_action( + 'add', + r['router']['id'], + s1['subnet']['id'], + None, + tenant_id=tenant_id) + self.assertIn('port_id', body) def test_router_add_interface_port(self): with self.router() as r: @@ -1598,45 +1598,45 @@ class L3NatTestCaseBase(L3NatTestCaseMixin): self.router(), self.subnet(), mock.patch.object(registry, 'notify')) as (r, s, notify): - errors = [ - exceptions.NotificationError( - 'foo_callback_id', n_exc.InUse()), - ] - # we fail the first time, but not the second, when - # the clean-up takes place - notify.side_effect = [ - exceptions.CallbackFailure(errors=errors), None - ] - self._router_interface_action('add', - r['router']['id'], - s['subnet']['id'], - None) - self._router_interface_action( - 'remove', - r['router']['id'], - s['subnet']['id'], - None, - exc.HTTPConflict.code) + errors = [ + exceptions.NotificationError( + 'foo_callback_id', n_exc.InUse()), + ] + # we fail the first time, but not the second, when + # the clean-up takes place + notify.side_effect = [ + exceptions.CallbackFailure(errors=errors), None + ] + self._router_interface_action('add', + r['router']['id'], + s['subnet']['id'], + None) + self._router_interface_action( + 'remove', + r['router']['id'], + s['subnet']['id'], + None, + exc.HTTPConflict.code) def test_router_clear_gateway_callback_failure_returns_409(self): with contextlib.nested( self.router(), self.subnet(), mock.patch.object(registry, 'notify')) as (r, s, notify): - errors = [ - exceptions.NotificationError( - 'foo_callback_id', n_exc.InUse()), - ] - notify.side_effect = exceptions.CallbackFailure(errors=errors) - self._set_net_external(s['subnet']['network_id']) - self._add_external_gateway_to_router( - r['router']['id'], - s['subnet']['network_id']) - self._remove_external_gateway_from_router( + errors = [ + exceptions.NotificationError( + 'foo_callback_id', n_exc.InUse()), + ] + notify.side_effect = exceptions.CallbackFailure(errors=errors) + self._set_net_external(s['subnet']['network_id']) + self._add_external_gateway_to_router( r['router']['id'], - s['subnet']['network_id'], - external_gw_info={}, - expected_code=exc.HTTPConflict.code) + s['subnet']['network_id']) + self._remove_external_gateway_from_router( + r['router']['id'], + s['subnet']['network_id'], + external_gw_info={}, + expected_code=exc.HTTPConflict.code) def test_router_remove_interface_wrong_subnet_returns_400(self): with self.router() as r: diff --git a/neutron/tests/unit/plugins/linuxbridge/agent/test_linuxbridge_neutron_agent.py b/neutron/tests/unit/plugins/linuxbridge/agent/test_linuxbridge_neutron_agent.py index b7adf56b8..192637f28 100644 --- a/neutron/tests/unit/plugins/linuxbridge/agent/test_linuxbridge_neutron_agent.py +++ b/neutron/tests/unit/plugins/linuxbridge/agent/test_linuxbridge_neutron_agent.py @@ -874,7 +874,7 @@ class TestLinuxBridgeManager(base.BaseTestCase): mock.patch.object( ip_lib, 'iproute_arg_supported', return_value=iproute_arg_supported)): - self.assertEqual(expected, self.lbm.vxlan_ucast_supported()) + self.assertEqual(expected, self.lbm.vxlan_ucast_supported()) def test_vxlan_ucast_supported(self): self._check_vxlan_ucast_supported( diff --git a/neutron/tests/unit/plugins/openvswitch/agent/test_ovs_neutron_agent.py b/neutron/tests/unit/plugins/openvswitch/agent/test_ovs_neutron_agent.py index af4c5496b..9063df417 100644 --- a/neutron/tests/unit/plugins/openvswitch/agent/test_ovs_neutron_agent.py +++ b/neutron/tests/unit/plugins/openvswitch/agent/test_ovs_neutron_agent.py @@ -350,7 +350,7 @@ class TestOvsNeutronAgent(object): self.agent.treat_devices_added_or_updated([{}], False)) # The function should not raise self.assertFalse(skip_devs) - return func.called + return func.called def test_treat_devices_added_updated_ignores_invalid_ofport(self): port = mock.Mock() @@ -1003,19 +1003,19 @@ class TestOvsNeutronAgent(object): except Exception: pass - scan_ports.assert_has_calls([ - mock.call(set(), set()), - mock.call(set(), set()) - ]) - process_network_ports.assert_has_calls([ - mock.call(reply2, False), - mock.call(reply3, True) - ]) - self.assertTrue(update_stale.called) - # Verify the OVS restart we triggered in the loop - # re-setup the bridges - setup_int_br.assert_has_calls([mock.call()]) - setup_phys_br.assert_has_calls([mock.call({})]) + scan_ports.assert_has_calls([ + mock.call(set(), set()), + mock.call(set(), set()) + ]) + process_network_ports.assert_has_calls([ + mock.call(reply2, False), + mock.call(reply3, True) + ]) + self.assertTrue(update_stale.called) + # Verify the OVS restart we triggered in the loop + # re-setup the bridges + setup_int_br.assert_has_calls([mock.call()]) + setup_phys_br.assert_has_calls([mock.call({})]) def test_ovs_status(self): self._test_ovs_status(constants.OVS_NORMAL, @@ -1652,26 +1652,26 @@ class TestOvsDvrNeutronAgent(object): mock.patch.object(self.agent.dvr_agent, 'int_br', new=int_br), mock.patch.object(self.agent.dvr_agent, 'tun_br', new=tun_br), ) as (reclaim_vlan_fn, update_dev_down_fn, _, _, _, _): - self.agent.treat_devices_removed([self._port.vif_id]) - if ip_version == 4: - expected = [ - mock.call.delete_dvr_process_ipv4( - vlan_tag=lvid, - gateway_ip=gateway_ip), - ] - else: - expected = [ - mock.call.delete_dvr_process_ipv6( - vlan_tag=lvid, - gateway_mac=gateway_mac), - ] - expected.extend([ - mock.call.delete_dvr_process( + self.agent.treat_devices_removed([self._port.vif_id]) + if ip_version == 4: + expected = [ + mock.call.delete_dvr_process_ipv4( + vlan_tag=lvid, + gateway_ip=gateway_ip), + ] + else: + expected = [ + mock.call.delete_dvr_process_ipv6( vlan_tag=lvid, - vif_mac=self._port.vif_mac), - ]) - self.assertEqual([], int_br.mock_calls) - self.assertEqual(expected, tun_br.mock_calls) + gateway_mac=gateway_mac), + ] + expected.extend([ + mock.call.delete_dvr_process( + vlan_tag=lvid, + vif_mac=self._port.vif_mac), + ]) + self.assertEqual([], int_br.mock_calls) + self.assertEqual(expected, tun_br.mock_calls) def _test_treat_devices_removed_for_dvr(self, device_owner, ip_version=4): self._setup_for_dvr_test() @@ -1757,15 +1757,15 @@ class TestOvsDvrNeutronAgent(object): mock.patch.object(self.agent.dvr_agent, 'int_br', new=int_br), mock.patch.object(self.agent.dvr_agent, 'tun_br', new=tun_br), ) as (reclaim_vlan_fn, update_dev_down_fn, _, _, _, _): - self.agent.treat_devices_removed([self._compute_port.vif_id]) - int_br.assert_has_calls([ - mock.call.delete_dvr_to_src_mac( - network_type='vxlan', - vlan_tag=lvid, - dst_mac=self._compute_port.vif_mac, - ), - ]) - self.assertEqual([], tun_br.mock_calls) + self.agent.treat_devices_removed([self._compute_port.vif_id]) + int_br.assert_has_calls([ + mock.call.delete_dvr_to_src_mac( + network_type='vxlan', + vlan_tag=lvid, + dst_mac=self._compute_port.vif_mac, + ), + ]) + self.assertEqual([], tun_br.mock_calls) def test_treat_devices_removed_for_dvr_with_compute_ports(self): self._test_treat_devices_removed_for_dvr( @@ -1847,17 +1847,17 @@ class TestOvsDvrNeutronAgent(object): mock.patch.object(self.agent.dvr_agent, 'int_br', new=int_br), mock.patch.object(self.agent.dvr_agent, 'tun_br', new=tun_br), ) as (reclaim_vlan_fn, update_dev_down_fn, _, _, _, _): - self.agent.treat_devices_removed([self._port.vif_id]) - expected_on_int_br = [ - mock.call.delete_dvr_to_src_mac( - network_type='vxlan', - dst_mac=self._port.vif_mac, - vlan_tag=lvid, - ), - ] - self.assertEqual(expected_on_int_br, int_br.mock_calls) - expected_on_tun_br = [] - self.assertEqual(expected_on_tun_br, tun_br.mock_calls) + self.agent.treat_devices_removed([self._port.vif_id]) + expected_on_int_br = [ + mock.call.delete_dvr_to_src_mac( + network_type='vxlan', + dst_mac=self._port.vif_mac, + vlan_tag=lvid, + ), + ] + self.assertEqual(expected_on_int_br, int_br.mock_calls) + expected_on_tun_br = [] + self.assertEqual(expected_on_tun_br, tun_br.mock_calls) def test_setup_dvr_flows_on_int_br(self): self._setup_for_dvr_test() diff --git a/neutron/tests/unit/plugins/openvswitch/test_ovs_tunnel.py b/neutron/tests/unit/plugins/openvswitch/test_ovs_tunnel.py index a3f8600ed..64d130b4b 100644 --- a/neutron/tests/unit/plugins/openvswitch/test_ovs_tunnel.py +++ b/neutron/tests/unit/plugins/openvswitch/test_ovs_tunnel.py @@ -524,23 +524,24 @@ class TunnelTest(object): except Exception: pass - # FIXME(salv-orlando): There should not be assertions on log messages - log_exception.assert_called_once_with( - "Error while processing VIF ports") - scan_ports.assert_has_calls([ - mock.call(set(), set()), - mock.call(set(['tap0']), set()) - ]) - process_network_ports.assert_has_calls([ - mock.call({'current': set(['tap0']), - 'removed': set([]), - 'added': set(['tap2'])}, False), - mock.call({'current': set(['tap2']), - 'removed': set(['tap0']), - 'added': set([])}, False) - ]) - self.assertTrue(update_stale.called) - self._verify_mock_calls() + # FIXME(salv-orlando): There should not be assertions on log + # messages + log_exception.assert_called_once_with( + "Error while processing VIF ports") + scan_ports.assert_has_calls([ + mock.call(set(), set()), + mock.call(set(['tap0']), set()) + ]) + process_network_ports.assert_has_calls([ + mock.call({'current': set(['tap0']), + 'removed': set([]), + 'added': set(['tap2'])}, False), + mock.call({'current': set(['tap2']), + 'removed': set(['tap0']), + 'added': set([])}, False) + ]) + self.assertTrue(update_stale.called) + self._verify_mock_calls() class TunnelTestOFCtl(TunnelTest, ovs_test_base.OVSOFCtlTestBase): diff --git a/neutron/tests/unit/scheduler/test_l3_agent_scheduler.py b/neutron/tests/unit/scheduler/test_l3_agent_scheduler.py index 93ceae597..07f06db7a 100644 --- a/neutron/tests/unit/scheduler/test_l3_agent_scheduler.py +++ b/neutron/tests/unit/scheduler/test_l3_agent_scheduler.py @@ -134,10 +134,10 @@ class L3SchedulerBaseTestCase(base.BaseTestCase): ) as (gs, gr): result = self.scheduler.auto_schedule_routers( self.plugin, mock.ANY, mock.ANY, mock.ANY) - self.assertTrue(self.plugin.get_enabled_agent_on_host.called) - self.assertTrue(result) - self.assertTrue(gs.called) - self.assertTrue(gr.called) + self.assertTrue(self.plugin.get_enabled_agent_on_host.called) + self.assertTrue(result) + self.assertTrue(gs.called) + self.assertTrue(gr.called) def test_auto_schedule_routers_no_agents(self): self.plugin.get_enabled_agent_on_host.return_value = None @@ -257,9 +257,9 @@ class L3SchedulerBaseTestCase(base.BaseTestCase): ) as ( mock_has_binding, mock_bind): self.scheduler._bind_routers(mock.ANY, mock.ANY, routers, agent) - mock_has_binding.assert_called_once_with(mock.ANY, 'foo_router', - 'foo_agent') - self.assertEqual(not has_binding, mock_bind.called) + mock_has_binding.assert_called_once_with(mock.ANY, 'foo_router', + 'foo_agent') + self.assertEqual(not has_binding, mock_bind.called) def test__bind_routers_ha_has_binding(self): self._test__bind_routers_ha(has_binding=True) @@ -473,10 +473,9 @@ class L3SchedulerTestBaseMixin(object): with contextlib.nested( mock.patch.object(scheduler, 'bind_router'), mock.patch.object( - plugin, 'get_snat_bindings', return_value=False) - ): - scheduler._schedule_router( - plugin, self.adminContext, 'foo_router_id', None) + plugin, 'get_snat_bindings', return_value=False)): + scheduler._schedule_router( + plugin, self.adminContext, 'foo_router_id', None) expected_calls = [ mock.call.get_router(mock.ANY, 'foo_router_id'), mock.call.get_l3_agents_hosting_routers( @@ -1308,8 +1307,8 @@ class L3DvrSchedulerTestCase(testlib_api.SqlTestCase): mock.patch.object(self.dut, 'bind_dvr_router_servicenode') ) as (mock_gl3, mock_snat_canidates, mock_bind_snat, mock_bind_dvr): self.dut.schedule_snat_router(self.adminContext, 'foo', 'bar') - self.assertTrue(mock_bind_snat.called) - self.assertFalse(mock_bind_dvr.called) + self.assertTrue(mock_bind_snat.called) + self.assertFalse(mock_bind_dvr.called) def test_schedule_snat_router_return_value(self): agent, router = self._prepare_schedule_snat_tests() @@ -1340,7 +1339,7 @@ class L3DvrSchedulerTestCase(testlib_api.SqlTestCase): mock_snat_bind.return_value = False self.dut.schedule_snat_router( self.adminContext, 'foo_router_id', router) - self.assertFalse(mock_unbind.called) + self.assertFalse(mock_unbind.called) def test_schedule_snat_router_with_snat_candidates(self): agent, router = self._prepare_schedule_snat_tests() @@ -1359,8 +1358,8 @@ class L3DvrSchedulerTestCase(testlib_api.SqlTestCase): mock_candidates.return_value = [agent] self.dut.schedule_snat_router( self.adminContext, 'foo_router_id', mock.ANY) - mock_bind.assert_called_once_with( - self.adminContext, 'foo_router_id', [agent]) + mock_bind.assert_called_once_with( + self.adminContext, 'foo_router_id', [agent]) def test_unbind_snat_servicenode(self): router_id = 'foo_router_id' @@ -1383,9 +1382,9 @@ class L3DvrSchedulerTestCase(testlib_api.SqlTestCase): mock_query.return_value = binding mock_get_subnets.return_value = ['foo_subnet_id'] self.dut.unbind_snat_servicenode(self.adminContext, router_id) - mock_get_subnets.assert_called_with(self.adminContext, router_id) - self.assertTrue(mock_session.call_count) - self.assertTrue(mock_delete.call_count) + mock_get_subnets.assert_called_with(self.adminContext, router_id) + self.assertTrue(mock_session.call_count) + self.assertTrue(mock_delete.call_count) core_plugin.assert_called_once_with() l3_notifier.assert_called_once_with()