]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Fix indentation errors in tests
authorAdrien Vergé <adrienverge@gmail.com>
Mon, 25 May 2015 16:46:03 +0000 (18:46 +0200)
committerAdrien Vergé <adrienverge@gmail.com>
Fri, 29 May 2015 21:17:51 +0000 (23:17 +0200)
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

neutron/tests/unit/api/rpc/handlers/test_securitygroups_rpc.py
neutron/tests/unit/extensions/test_l3.py
neutron/tests/unit/plugins/linuxbridge/agent/test_linuxbridge_neutron_agent.py
neutron/tests/unit/plugins/openvswitch/agent/test_ovs_neutron_agent.py
neutron/tests/unit/plugins/openvswitch/test_ovs_tunnel.py
neutron/tests/unit/scheduler/test_l3_agent_scheduler.py

index 6728062091e971e1956c4066e3056d33b191fad6..4728e3de327cd8d14565fc30c0a6ec4e9d99716a 100644 (file)
@@ -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):
index 35a632dfa227b16956b5897b5547ac34f8c9d552..2e67d40f03759883ff6a35831cff9fe968c9827b 100644 (file)
@@ -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:
index b7adf56b8216c46380f54590a57734c41aeeac96..192637f28e181790e838a51f0e7cf982a62e4f20 100644 (file)
@@ -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(
index af4c5496b58c0cb71b78b2619019ab3fdf2cf56e..9063df417eafd28ba1fce126b597938c70bbfcc4 100644 (file)
@@ -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()
index a3f8600ed999bf1525ec499bca7f824192e43a69..64d130b4bbea98d46bef3eca954ab261d7ae727a 100644 (file)
@@ -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):
index 93ceae59761ee6aa328f633d382f6a54d6028884..07f06db7a113479de1390c0581df624e4428ba3f 100644 (file)
@@ -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()