From 7fa05a75c2057fb42486cb9100c48ceb21f637e6 Mon Sep 17 00:00:00 2001 From: Brian Haley Date: Mon, 16 Oct 2017 18:20:37 -0400 Subject: [PATCH] Only create one IPWrapper class instance in _arping() We are calling arping many times in the same namespace, no need to create multiple IPWrapper class instances. Trivialfix Change-Id: Id360324d4d31181ebf39f7796346635da043f350 --- neutron/agent/linux/ip_lib.py | 2 +- neutron/tests/unit/agent/linux/test_ip_lib.py | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/neutron/agent/linux/ip_lib.py b/neutron/agent/linux/ip_lib.py index d3323fdfe91..dc4b38eea61 100644 --- a/neutron/agent/linux/ip_lib.py +++ b/neutron/agent/linux/ip_lib.py @@ -1051,6 +1051,7 @@ def _arping(ns_name, iface_name, address, count, log_exception): # not expected. In some cases (no response) and with some # platforms (>=Ubuntu 14.04), arping exit code can be 1. extra_ok_codes = [1] + ip_wrapper = IPWrapper(namespace=ns_name) for i in range(count): if not first: # hopefully enough for kernel to get out of locktime loop @@ -1075,7 +1076,6 @@ def _arping(ns_name, iface_name, address, count, log_exception): # removed while running '-w', 1.5, address] try: - ip_wrapper = IPWrapper(namespace=ns_name) ip_wrapper.netns.execute(arping_cmd, extra_ok_codes=extra_ok_codes) except Exception as exc: diff --git a/neutron/tests/unit/agent/linux/test_ip_lib.py b/neutron/tests/unit/agent/linux/test_ip_lib.py index 8ff58bef97e..972be9d1e15 100644 --- a/neutron/tests/unit/agent/linux/test_ip_lib.py +++ b/neutron/tests/unit/agent/linux/test_ip_lib.py @@ -1699,15 +1699,10 @@ class TestArpPing(TestIPCmdBase): mIPWrapper.assert_has_calls([ mock.call(namespace=mock.sentinel.ns_name), mock.call().netns.execute(mock.ANY, extra_ok_codes=[1]), - mock.call(namespace=mock.sentinel.ns_name), mock.call().netns.execute(mock.ANY, extra_ok_codes=[1]), - mock.call(namespace=mock.sentinel.ns_name), mock.call().netns.execute(mock.ANY, extra_ok_codes=[1, 2]), - mock.call(namespace=mock.sentinel.ns_name), mock.call().netns.execute(mock.ANY, extra_ok_codes=[1, 2]), - mock.call(namespace=mock.sentinel.ns_name), mock.call().netns.execute(mock.ANY, extra_ok_codes=[1, 2]), - mock.call(namespace=mock.sentinel.ns_name), mock.call().netns.execute(mock.ANY, extra_ok_codes=[1, 2])]) ip_wrapper = mIPWrapper(namespace=mock.sentinel.ns_name)