Remove the dependency on the "mock" package

Now that we are python3 only, we should move to using the built
in version of mock that supports all of our testing needs and
remove the dependency on the "mock" package.

This patch moves all references to "import mock" to
"from unittest import mock". It also cleans up some new line
inconsistency.

Fixed an inconsistency in the OVSBridge.deferred() definition
as it needs to also have an *args argument.

Fixed an issue where an l3-agent test was mocking
functools.partial, causing a python3.8 failure.

Unit tests only, removing from tests/base.py affects
functional tests which need additional work.

Change-Id: I40e8a8410840c3774c72ae1a8054574445d66ece
This commit is contained in:
Brian Haley 2020-04-24 17:25:18 -04:00
parent 4b02ed8225
commit 7594bb0627
257 changed files with 368 additions and 278 deletions

View File

@ -500,8 +500,8 @@ class OVSBridge(BaseOVS):
return [f for f in self.run_ofctl("dump-flows", []).splitlines()
if is_a_flow_line(f)]
def deferred(self, **kwargs):
return DeferredOVSBridge(self, **kwargs)
def deferred(self, *args, **kwargs):
return DeferredOVSBridge(self, *args, **kwargs)
def add_tunnel_port(self, port_name, remote_ip, local_ip,
tunnel_type=p_const.TYPE_GRE,

View File

@ -14,11 +14,11 @@
import signal
import sys
from unittest import mock
import eventlet.event
from eventlet.green import subprocess
import eventlet.queue
import mock
import testtools
from neutron.agent.common import async_process

View File

@ -13,8 +13,8 @@
# under the License.
import collections
from unittest import mock
import mock
from neutron_lib import exceptions
from oslo_serialization import jsonutils
from oslo_utils import uuidutils

View File

@ -12,7 +12,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from oslo_serialization import jsonutils
from neutron.agent.common import async_process

View File

@ -12,10 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from unittest import mock
import uuid
import mock
from neutron.agent.common import placement_report
from neutron.tests import base

View File

@ -12,7 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from neutron.agent.common import base_polling
from neutron.agent.common import polling

View File

@ -14,8 +14,7 @@
# under the License.
import socket
import mock
from unittest import mock
from neutron.agent.common import utils
from neutron.agent.linux import interface

View File

@ -16,10 +16,10 @@
import collections
import copy
import sys
from unittest import mock
import uuid
import eventlet
import mock
from neutron_lib.agent import constants as agent_consts
from neutron_lib import constants as const
from neutron_lib import exceptions

View File

@ -14,8 +14,8 @@
# under the License.
import copy
from unittest import mock
import mock
from neutron_lib import constants
from neutron_lib.utils import helpers
from oslo_config import cfg

View File

@ -13,7 +13,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from neutron_lib import constants as common_constants
from neutron_lib import context
from neutron_lib.db import constants as db_consts

View File

@ -10,7 +10,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from oslo_config import cfg
from neutron.agent.l2 import l2_agent_extensions_manager as l2_ext_manager

View File

@ -13,7 +13,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from oslo_utils import uuidutils
from neutron.agent.l3.extensions.qos import base as qos_base

View File

@ -13,7 +13,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from neutron_lib import constants as lib_const
from neutron_lib import context
from neutron_lib import rpc as n_rpc

View File

@ -14,8 +14,8 @@
# under the License.
import copy
from unittest import mock
import mock
from neutron_lib import constants as lib_const
from neutron_lib import context
from oslo_utils import uuidutils

View File

@ -13,7 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from neutron_lib import constants
from neutron_lib import context

View File

@ -13,7 +13,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
import netaddr
from neutron_lib import constants as lib_const
from neutron_lib import context

View File

@ -13,7 +13,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from neutron_lib import constants as lib_const
from neutron.agent.l3.extensions import snat_log

View File

@ -14,15 +14,14 @@
# under the License.
import copy
import functools
from itertools import chain as iter_chain
from itertools import combinations as iter_combinations
import os
import pwd
from unittest import mock
import eventlet
import fixtures
import mock
import netaddr
from neutron_lib.agent import constants as agent_consts
from neutron_lib.api.definitions import portbindings
@ -3998,14 +3997,11 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
ri.remove_floating_ip.assert_called_once_with(
device, need_to_remove_fip[0]['cidr'])
@mock.patch.object(functools, 'partial')
@mock.patch.object(common_utils, 'load_interface_driver')
def test_interface_driver_init(self, load_driver_mock, funct_partial_mock):
agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)
def test_interface_driver_init(self, load_driver_mock):
l3_agent.L3NATAgent(HOSTNAME, self.conf)
load_driver_mock.assert_called_once_with(
self.conf, get_networks_callback=mock.ANY)
funct_partial_mock.assert_called_once_with(
self.plugin_api.get_networks, agent.context)
def test_stop_no_cleanup(self):
agent = l3_agent.L3NATAgent(HOSTNAME, self.conf)

View File

@ -13,8 +13,8 @@
# under the License.
import copy
from unittest import mock
import mock
from neutron_lib.exceptions import l3 as l3_exc
from oslo_config import cfg
from oslo_utils import uuidutils

View File

@ -12,7 +12,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from neutron_lib.api.definitions import portbindings
from neutron_lib import constants as lib_constants
from oslo_config import cfg

View File

@ -12,7 +12,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from oslo_config import cfg
from oslo_utils import uuidutils

View File

@ -14,8 +14,8 @@
import copy
import signal
from unittest import mock
import mock
from neutron_lib import constants as n_consts
from neutron_lib import fixture as lib_fixtures
from oslo_utils import uuidutils

View File

@ -12,7 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from neutron.agent.l3 import item_allocator as ia
from neutron.tests import base

View File

@ -14,7 +14,7 @@
# under the License.
#
import mock
from unittest import mock
from oslo_utils import uuidutils

View File

@ -12,7 +12,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from neutron_lib import constants as lib_constants
from oslo_utils import uuidutils

View File

@ -13,7 +13,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from oslo_utils import uuidutils
from neutron.agent.l3 import dvr_fip_ns

View File

@ -10,7 +10,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from neutron_lib import constants as lib_constants
from neutron_lib.exceptions import l3 as l3_exc
from oslo_utils import uuidutils

View File

@ -12,7 +12,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from neutron_lib.callbacks import events as callbacks_events
from neutron_lib.callbacks import registry as callbacks_registry
from neutron_lib.callbacks import resources as callbacks_resources

View File

@ -13,7 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from neutron.agent.linux import iptables_firewall
from neutron.agent.linux.openvswitch_firewall import iptables

View File

@ -12,7 +12,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from neutron_lib import constants
from neutron.agent.linux.openvswitch_firewall import constants as ovsfw_consts

View File

@ -15,7 +15,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from oslo_utils import netutils
from neutron.agent.linux import bridge_lib

View File

@ -17,8 +17,8 @@ import logging
from logging import handlers
import os
import sys
from unittest import mock
import mock
from neutron_lib import exceptions
from neutron_lib import fixture as lib_fixtures
import testtools

View File

@ -15,8 +15,8 @@
import copy
import os
from unittest import mock
import mock
import netaddr
from neutron_lib.api.definitions import extra_dhcp_opt as edo_ext
from neutron_lib import constants

View File

@ -13,8 +13,8 @@
# under the License.
import os.path
from unittest import mock
import mock
from neutron_lib import fixture as lib_fixtures
from oslo_config import cfg
from oslo_utils import fileutils

View File

@ -13,7 +13,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from neutron_lib import constants
from oslo_utils import excutils
from pyroute2.netlink import exceptions as pyroute2_exc

View File

@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import mock
from unittest import mock
from neutron.agent.linux import ip_conntrack
from neutron.tests import base

View File

@ -16,8 +16,8 @@
import copy
import errno
import socket
from unittest import mock
import mock
import netaddr
from neutron_lib import constants
from neutron_lib import exceptions

View File

@ -13,8 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import mock
from unittest import mock
from neutron.agent.linux import ip_link_support as ip_link
from neutron.tests import base

View File

@ -11,7 +11,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import mock
from unittest import mock
from neutron.agent.linux import ipset_manager
from neutron.tests import base

View File

@ -14,8 +14,8 @@
# under the License.
import copy
from unittest import mock
import mock
from neutron_lib import constants
from neutron_lib import exceptions
from oslo_config import cfg

View File

@ -15,9 +15,9 @@
import os
import sys
from unittest import mock
import fixtures
import mock
from neutron_lib import constants
from neutron_lib import exceptions
from neutron_lib.exceptions import l3 as l3_exc

View File

@ -15,8 +15,8 @@
import os
import textwrap
from unittest import mock
import mock
from neutron_lib import constants as n_consts
import testtools

View File

@ -10,7 +10,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from neutron_lib import constants
from neutron_lib import exceptions

View File

@ -10,7 +10,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from neutron.agent.l3 import dvr_edge_router
from neutron.agent.l3 import dvr_local_router

View File

@ -13,7 +13,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from neutron_lib import constants
from neutron_lib.exceptions import qos as qos_exc
from neutron_lib.services.qos import constants as qos_consts

View File

@ -15,8 +15,8 @@
import copy
import signal
import socket
from unittest import mock
import mock
import six
import testtools

View File

@ -12,7 +12,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from oslo_config import cfg
from oslo_rootwrap import cmd as oslo_rootwrap_cmd

View File

@ -12,7 +12,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from neutron_lib import constants as n_const
import testtools
import webob

View File

@ -14,8 +14,8 @@
# under the License.
import os
from unittest import mock
import mock
from neutron_lib import constants
from neutron_lib import fixture as lib_fixtures
from oslo_config import cfg

View File

@ -13,8 +13,8 @@
# limitations under the License.
import collections
from unittest import mock
import mock
from oslo_config import cfg
from oslo_config import fixture as config_fixture

View File

@ -14,8 +14,8 @@
# under the License.
import os
from unittest import mock
import mock
from neutron_lib import fixture as lib_fixtures
from oslo_config import cfg
from oslo_utils import uuidutils

View File

@ -13,8 +13,8 @@
# limitations under the License.
import collections
from unittest import mock
import mock
from oslo_config import cfg
from oslo_config import fixture as config_fixture
from oslo_utils import fileutils

View File

@ -12,7 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from ovs.db import idl
from ovs import jsonrpc

View File

@ -12,10 +12,10 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
import testtools
from unittest import mock
from ovsdbapp import exceptions
import testtools
from neutron.agent.ovsdb import impl_idl
from neutron.tests import base

View File

@ -10,7 +10,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from oslo_config import cfg
from neutron.agent import agent_extensions_manager as ext_manager

View File

@ -12,7 +12,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from neutron_lib.callbacks import events
from neutron_lib.callbacks import registry
from neutron_lib import context

View File

@ -14,8 +14,8 @@
# under the License.
import datetime
from unittest import mock
import mock
import netaddr
from neutron_lib.agent import topics as lib_topics
from neutron_lib.callbacks import events

View File

@ -15,8 +15,8 @@
import collections
import contextlib
from unittest import mock
import mock
import netaddr
from neutron_lib.api.definitions import allowedaddresspairs as addr_apidef
from neutron_lib import constants as const

View File

@ -13,7 +13,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
import netifaces
from neutron.agent.windows import ip_lib

View File

@ -14,11 +14,11 @@
# under the License.
import io
from unittest import mock
import ddt
import eventlet
from eventlet import tpool
import mock
from neutron_lib import exceptions
import six

View File

@ -15,8 +15,8 @@
import copy
import datetime
from unittest import mock
import mock
from neutron_lib.api import extensions
from neutron_lib.callbacks import events
from neutron_lib.callbacks import registry

View File

@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import mock
from unittest import mock
from neutron_lib import rpc

View File

@ -10,7 +10,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from neutron.api.rpc.callbacks.consumer import registry
from neutron.tests import base

View File

@ -10,7 +10,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from neutron_lib.callbacks import exceptions

View File

@ -10,7 +10,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from neutron.api.rpc.callbacks import exceptions
from neutron.api.rpc.callbacks import resources

View File

@ -13,7 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import mock
from unittest import mock
from neutron_lib.api.definitions import portbindings
from neutron_lib.callbacks import resources
from neutron_lib import constants

View File

@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import mock
from unittest import mock
from neutron.api.rpc.handlers import dvr_rpc
from neutron.tests import base

View File

@ -13,7 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import mock
from unittest import mock
from neutron_lib.agent import topics
from neutron_lib import context
from neutron_lib.objects import common_types

View File

@ -12,7 +12,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
import netaddr
from neutron_lib import context
from oslo_utils import uuidutils

View File

@ -14,9 +14,9 @@
# under the License.
import copy
from unittest import mock
import fixtures
import mock
from neutron_lib import exceptions
from neutron_lib.plugins import constants as lib_const
from neutron_lib.plugins import directory

View File

@ -14,8 +14,8 @@
# under the License.
import os
from unittest import mock
import mock
from neutron_lib.api import attributes
from neutron_lib.api import converters
from neutron_lib.api.definitions import empty_string_filtering

View File

@ -13,7 +13,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from neutron_lib import context
from neutron_lib import exceptions as n_exc
import oslo_i18n

View File

@ -10,7 +10,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from neutron.api.v2 import router
from neutron.tests import base

View File

@ -14,8 +14,8 @@
# under the License.
import signal
from unittest import mock
import mock
import testtools
from neutron.cmd import netns_cleanup as util

View File

@ -13,7 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from neutron.cmd import ovs_cleanup as util
from neutron.tests import base

View File

@ -13,7 +13,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from oslo_config import cfg
from neutron.cmd import sanity_check

View File

@ -12,7 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from neutron.cmd import status
from neutron.tests import base

View File

@ -12,7 +12,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from oslo_config import cfg
from oslo_upgradecheck.upgradecheck import Code

View File

@ -12,8 +12,8 @@
# under the License.
import copy
from unittest import mock
import mock
from neutron_lib import constants as const
from oslo_config import cfg
from ovsdbapp.backend.ovs_idl import idlutils

View File

@ -14,8 +14,8 @@
# under the License.
import datetime
from unittest import mock
import mock
from neutron_lib import context
from oslo_utils import timeutils

View File

@ -11,7 +11,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import mock
from unittest import mock
from oslo_utils import importutils
from neutron.tests import base

View File

@ -10,7 +10,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from oslo_config import cfg
from oslo_config import fixture as config_fixture

View File

@ -11,7 +11,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from oslo_concurrency import lockutils
from neutron.common import coordination

View File

@ -17,11 +17,11 @@ import random
import re
import sys
import time
from unittest import mock
import ddt
import eventlet
from eventlet import queue
import mock
import netaddr
from neutron_lib import constants
from oslo_log import log as logging

View File

@ -14,8 +14,8 @@
# under the License.
import itertools
from unittest import mock
import mock
from neutron_lib import context
from neutron_lib.exceptions import qos as qos_exc
from neutron_lib.plugins import constants as plugin_constants

View File

@ -13,8 +13,8 @@
# under the License.
import datetime
from unittest import mock
import mock
from neutron_lib import context
from neutron_lib.plugins import constants as const
from neutron_lib.plugins import directory

View File

@ -13,7 +13,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from neutron_lib import context
from neutron.db import _utils as db_utils

View File

@ -16,8 +16,8 @@
import copy
import datetime
from unittest import mock
import mock
from neutron_lib import constants
from neutron_lib import context
from neutron_lib.db import api as db_api

View File

@ -14,8 +14,8 @@
# limitations under the License.
import datetime
from unittest import mock
import mock
from neutron_lib.api.definitions import dhcpagentscheduler as das_apidef
from neutron_lib.api.definitions import portbindings
from neutron_lib import constants

View File

@ -18,9 +18,9 @@ import copy
import functools
import itertools
import random
from unittest import mock
import eventlet
import mock
import netaddr
from neutron_lib.callbacks import exceptions
from neutron_lib.callbacks import registry

View File

@ -13,7 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import mock
from unittest import mock
from neutron_lib.api.definitions import portbindings
from neutron_lib.callbacks import events
from neutron_lib.callbacks import registry

View File

@ -13,7 +13,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from neutron_lib.callbacks import events
from neutron_lib.callbacks import registry
from neutron_lib import context

View File

@ -13,7 +13,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
import netaddr
from neutron_lib.api.definitions import portbindings
from neutron_lib import constants

View File

@ -14,8 +14,8 @@
# under the License.
import copy
from unittest import mock
import mock
import netaddr
from neutron_lib import constants
from neutron_lib import context as ncontext

View File

@ -13,7 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import mock
from unittest import mock
import netaddr
from neutron_lib.callbacks import events
from neutron_lib.callbacks import registry

View File

@ -13,7 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import mock
from unittest import mock
from neutron_lib.api.definitions import portbindings
from neutron_lib.callbacks import events
from neutron_lib.callbacks import registry

View File

@ -12,7 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from neutron_lib.api.definitions import dvr as dvr_apidef
from neutron_lib.api.definitions import external_net as extnet_apidef

View File

@ -18,13 +18,13 @@ import os
import re
import sys
import textwrap
from unittest import mock
from alembic.autogenerate import api as alembic_ag_api
from alembic import config as alembic_config
from alembic.operations import ops as alembic_ops
from alembic import script as alembic_script
import fixtures
import mock
from neutron_lib import fixture as lib_fixtures
from neutron_lib.utils import helpers
from oslo_utils import fileutils

View File

@ -14,8 +14,8 @@
# under the License.
import datetime
from unittest import mock
import mock
from neutron_lib import context
from neutron_lib.db import api as db_api
from oslo_utils import timeutils

View File

@ -13,7 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from neutron_lib import constants as n_const
from neutron_lib import context

Some files were not shown because too many files have changed in this diff Show More