Use unittest.mock instead of third party mock

Now that we no longer support py27, we can use the standard library
unittest.mock module instead of the third party mock lib.

Change-Id: Ifd0d1b8aa419e39361e76a4f846cb4eeaf0d46ca
Signed-off-by: Sean McGinnis <sean.mcginnis@gmail.com>
This commit is contained in:
Sean McGinnis 2020-04-18 11:53:33 -05:00
parent 0764f5dab1
commit 3df667582c
No known key found for this signature in database
GPG Key ID: CE7EE4BFAF8D70C8
72 changed files with 204 additions and 159 deletions

View File

@ -11,9 +11,9 @@
# under the License.
import logging
from unittest import mock
import fixtures
import mock
from oslo_config import cfg
from oslo_messaging import conffixture as messaging_conffixture
from oslo_utils import timeutils

View File

@ -14,13 +14,13 @@
Test suites for 'common' code used throughout the OpenStack HTTP API.
"""
import mock
from unittest import mock
from oslo_config import cfg
from testtools import matchers
import webob
import webob.exc
from oslo_config import cfg
from karbor.api import common
from karbor.tests import base

View File

@ -9,14 +9,15 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from mock import mock
from unittest import mock
from webob import exc
from karbor.api.v1 import copies
from karbor import context
from karbor import exception
from karbor.tests import base
from karbor.tests.unit.api import fakes
from webob import exc
PROVIDER_ID_1 = 'efc6a88b-9096-4bb6-8634-cda182a6e12a'
PROVIDER_ID_2 = '3241a88b-9096-4bb6-8634-cda182a6e12a'

View File

@ -11,7 +11,8 @@
# under the License.
import mock
from unittest import mock
from oslo_config import cfg
from webob import exc

View File

@ -11,7 +11,8 @@
# under the License.
import mock
from unittest import mock
from oslo_config import cfg
from webob import exc

View File

@ -11,7 +11,8 @@
# under the License.
import mock
from unittest import mock
from oslo_config import cfg
from webob import exc

View File

@ -11,9 +11,9 @@
# under the License.
import mock
from oslo_config import cfg
from unittest import mock
from oslo_config import cfg
from webob import exc
from karbor.api.v1 import providers

View File

@ -11,7 +11,8 @@
# under the License.
import mock
from unittest import mock
from oslo_config import cfg
from webob import exc

View File

@ -11,7 +11,8 @@
# under the License.
import mock
from unittest import mock
from oslo_config import cfg
from webob import exc

View File

@ -11,7 +11,8 @@
# under the License.
import mock
from unittest import mock
from oslo_config import cfg
from webob import exc

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_utils import uuidutils
from webob import exc

View File

@ -9,7 +9,8 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from mock import mock
from unittest import mock
from webob import exc
from karbor.api.v1 import services

View File

@ -10,7 +10,8 @@
# License for the specific language governing permissions and limitations
# under the License.
from datetime import datetime
import mock
from unittest import mock
from webob import exc
from karbor.api.v1 import triggers as trigger_api

View File

@ -11,7 +11,8 @@
# under the License.
import mock
from unittest import mock
from oslo_config import cfg
from webob import exc

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 karbor.context import RequestContext

View File

@ -11,7 +11,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from karbor.context import RequestContext
from karbor.services.protection.clients import eisoo

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 keystoneauth1 import session as keystone_session
from oslo_config import cfg

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_config import cfg
from karbor.context import RequestContext

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 keystoneauth1 import session as keystone_session
from oslo_config import cfg

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_config import cfg
from karbor.context import RequestContext

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 keystoneauth1 import session as keystone_session
from oslo_config import cfg

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 karbor.common import karbor_keystone_plugin as kkp

View File

@ -10,15 +10,14 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from karbor.common import karbor_keystone_plugin
from karbor.tests import base
from unittest import mock
from oslo_config import cfg
from oslo_config import fixture
from karbor.common import karbor_keystone_plugin
from karbor.tests import base
class KarborKeystonePluginTest(base.TestCase):

View File

@ -11,8 +11,8 @@
# under the License.
"""The notification module."""
from mock import Mock
from mock import patch
from unittest import mock
from unittest.mock import patch
from karbor.common import notification
from karbor.common.notification import EndNotification
@ -86,7 +86,7 @@ class TestKarborNotification(base.TestCase):
def setUp(self):
super(TestKarborNotification, self).setUp()
self.test_n = KarborTestNotification(Mock(), request=Mock())
self.test_n = KarborTestNotification(mock.Mock(), request=mock.Mock())
def test_missing_required_start_traits(self):
self.assertRaisesRegex(exception.InvalidInput,
@ -164,10 +164,10 @@ class TestKarborNotification(base.TestCase):
def _test_notify_callback(self, fn, *args, **kwargs):
with patch.object(rpc, 'get_notifier') as notifier:
mock_callback = Mock()
mock_callback = mock.Mock()
self.test_n.register_notify_callback(mock_callback)
mock_context = Mock()
mock_context.notification = Mock()
mock_context = mock.Mock()
mock_context.notification = mock.Mock()
self.test_n.context = mock_context
fn(*args, **kwargs)
self.assertTrue(notifier().info.called)

View File

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

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_utils import timeutils
from karbor import objects

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 karbor import objects
from karbor.tests.unit import fake_operation_log

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 oslo_serialization import jsonutils

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 karbor import objects
from karbor.tests.unit import fake_restore

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_serialization import jsonutils
from oslo_utils import timeutils

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_utils import timeutils
from karbor import exception

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_utils import timeutils
from karbor import context

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 karbor import objects
from karbor.tests.unit import fake_service

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_serialization import jsonutils
from oslo_utils import timeutils

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 karbor import objects
from karbor.tests.unit import fake_verification

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 stevedore import extension as import_driver
from karbor import exception

View File

@ -12,7 +12,8 @@
from datetime import datetime
from datetime import timedelta
import eventlet
import mock
from unittest import mock
from oslo_config import cfg
from karbor import exception

View File

@ -16,7 +16,8 @@ from datetime import timedelta
import eventlet
import functools
import heapq
import mock
from unittest import mock
from oslo_config import cfg
from oslo_utils import uuidutils

View File

@ -11,7 +11,7 @@
# under the License.
from datetime import datetime
import mock
from unittest import mock
from karbor.common import constants
from karbor import context

View File

@ -12,7 +12,7 @@
from datetime import datetime
from datetime import timedelta
import mock
from unittest import mock
from karbor.common import constants
from karbor import context

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 oslo_config import cfg

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_messaging.rpc import dispatcher as rpc_dispatcher
from karbor.common import constants

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 karbor import exception
from karbor.services.operationengine import operation_manager

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 karbor import context
from karbor.services.operationengine import user_trust_manager

View File

@ -11,18 +11,18 @@
# under the License.
import collections
from unittest import mock
from oslo_config import cfg
from troveclient.v1 import instances
from karbor.context import RequestContext
from karbor.resource import Resource
# Need to register trove_client
from karbor.services.protection.clients import trove # noqa
from karbor.services.protection.protectable_plugins.database \
import DatabaseInstanceProtectablePlugin
from karbor.tests import base
import mock
from oslo_config import cfg
from troveclient.v1 import instances
class DatabaseInstanceProtectablePluginTest(base.TestCase):

View File

@ -11,17 +11,19 @@
# under the License.
from collections import namedtuple
from unittest import mock
from glanceclient.v2 import images
from keystoneauth1 import session as keystone_session
from novaclient.v2 import servers
from oslo_config import cfg
from karbor.common import constants
from karbor.context import RequestContext
from karbor import resource
from karbor.services.protection.protectable_plugins.image import \
ImageProtectablePlugin
from karbor.tests import base
from keystoneauth1 import session as keystone_session
import mock
from novaclient.v2 import servers
from oslo_config import cfg
CONF = cfg.CONF

View File

@ -11,7 +11,11 @@
# under the License.
from collections import namedtuple
import mock
from unittest import mock
from keystoneauth1 import session as keystone_session
from neutronclient.v2_0 import client
from oslo_config import cfg
from karbor.common import constants
from karbor.context import RequestContext
@ -19,9 +23,6 @@ from karbor import resource
from karbor.services.protection.protectable_plugins.network import \
NetworkProtectablePlugin
from karbor.tests import base
from keystoneauth1 import session as keystone_session
from neutronclient.v2_0 import client
from oslo_config import cfg
CONF = cfg.CONF

View File

@ -10,22 +10,21 @@
# License for the specific language governing permissions and limitations
# under the License.
from karbor.context import RequestContext
from karbor.resource import Resource
from karbor.services.protection.clients import k8s # noqa
from karbor.services.protection.protectable_plugins.pod \
import K8sPodProtectablePlugin
from unittest import mock
import uuid
from kubernetes.client.models.v1_object_meta import V1ObjectMeta
from kubernetes.client.models.v1_pod import V1Pod
from kubernetes.client.models.v1_pod_list import V1PodList
from kubernetes.client.models.v1_pod_status import V1PodStatus
from oslo_config import cfg
from karbor.context import RequestContext
from karbor.resource import Resource
from karbor.services.protection.clients import k8s # noqa
from karbor.services.protection.protectable_plugins.pod \
import K8sPodProtectablePlugin
from karbor.tests import base
import mock
import uuid
class PodProtectablePluginTest(base.TestCase):

View File

@ -11,16 +11,17 @@
# under the License.
import collections
from unittest import mock
from keystoneauth1 import session as keystone_session
from novaclient.v2 import servers
from oslo_config import cfg
from karbor.context import RequestContext
from karbor.resource import Resource
from karbor.services.protection.protectable_plugins.server \
import ServerProtectablePlugin
from karbor.tests import base
from keystoneauth1 import session as keystone_session
import mock
from novaclient.v2 import servers
from oslo_config import cfg
class ServerProtectablePluginTest(base.TestCase):

View File

@ -11,16 +11,16 @@
# under the License.
import collections
from unittest import mock
from manilaclient.v2 import shares
from oslo_config import cfg
from karbor.context import RequestContext
from karbor.resource import Resource
from karbor.services.protection.protectable_plugins.share \
import ShareProtectablePlugin
from karbor.tests import base
import mock
from manilaclient.v2 import shares
from oslo_config import cfg
class ShareProtectablePluginTest(base.TestCase):

View File

@ -10,9 +10,10 @@
# License for the specific language governing permissions and limitations
# under the License.
from unittest import mock
from cinderclient.v3 import volumes
from collections import namedtuple
import mock
from karbor.common import constants
from karbor.context import RequestContext

View File

@ -13,11 +13,15 @@
# License for the specific language governing permissions and limitations
# under the License.
import futurist
import mock
from unittest import mock
import futurist
from oslo_config import cfg
from oslo_log import log as logging
from taskflow import engines
from taskflow.patterns import graph_flow
from taskflow.patterns import linear_flow
from taskflow import task
from karbor.resource import Resource
from karbor.services.protection.bank_plugin import Bank
@ -28,11 +32,6 @@ from karbor.services.protection import protection_plugin
from karbor.services.protection import provider
from karbor.services.protection import resource_flow
from taskflow import engines
from taskflow.patterns import graph_flow
from taskflow.patterns import linear_flow
from taskflow import task
LOG = logging.getLogger(__name__)
A = Resource(id='A', type='fake', name='fake')

View File

@ -11,7 +11,7 @@
# under the License.
from datetime import datetime
import mock
from unittest import mock
from oslo_utils import timeutils

View File

@ -11,6 +11,10 @@
# under the License.
import collections
from unittest import mock
from oslo_config import cfg
from oslo_config import fixture
from karbor.common import constants
from karbor.context import RequestContext
@ -23,11 +27,7 @@ from karbor.services.protection.protection_plugins.volume import \
volume_freezer_plugin_schemas
from karbor.services.protection.protection_plugins.volume.\
volume_freezer_plugin import FreezerProtectionPlugin
from karbor.tests import base
import mock
from oslo_config import cfg
from oslo_config import fixture
class FakeBankPlugin(BankPlugin):

View File

@ -11,6 +11,11 @@
# under the License.
import collections
from unittest import mock
from oslo_config import cfg
from oslo_config import fixture
from karbor.common import constants
from karbor.context import RequestContext
from karbor import exception
@ -24,9 +29,6 @@ from karbor.services.protection.protection_plugins.volume.\
from karbor.services.protection.protection_plugins.volume import \
volume_glance_plugin_schemas
from karbor.tests import base
import mock
from oslo_config import cfg
from oslo_config import fixture
class FakeBankPlugin(BankPlugin):

View File

@ -10,8 +10,13 @@
# License for the specific language governing permissions and limitations
# under the License.
from cinderclient import exceptions as cinder_exc
import collections
from unittest import mock
from cinderclient import exceptions as cinder_exc
from oslo_config import cfg
from oslo_config import fixture
from karbor.common import constants
from karbor.context import RequestContext
from karbor import exception
@ -24,9 +29,6 @@ from karbor.services.protection.protection_plugins.volume \
import volume_plugin_cinder_schemas as cinder_schemas
from karbor.tests import base
from karbor.tests.unit.protection import fakes
import mock
from oslo_config import cfg
from oslo_config import fixture
ResourceNode = collections.namedtuple(

View File

@ -11,6 +11,11 @@
# under the License.
import collections
from unittest import mock
from oslo_config import cfg
from oslo_config import fixture
from karbor.common import constants
from karbor.context import RequestContext
from karbor.resource import Resource
@ -23,9 +28,6 @@ from karbor.services.protection.protection_plugins. \
from karbor.services.protection.protection_plugins.volume \
import volume_snapshot_plugin_schemas
from karbor.tests import base
import mock
from oslo_config import cfg
from oslo_config import fixture
class FakeBankPlugin(BankPlugin):

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 karbor.services.protection.client_factory import ClientFactory
from karbor.tests import base

View File

@ -11,6 +11,11 @@
# under the License.
import collections
from unittest import mock
from oslo_config import cfg
from oslo_config import fixture
from karbor.common import constants
from karbor.context import RequestContext
from karbor.resource import Resource
@ -18,16 +23,11 @@ from karbor.services.protection.bank_plugin import Bank
from karbor.services.protection.bank_plugin import BankPlugin
from karbor.services.protection.bank_plugin import BankSection
from karbor.services.protection import client_factory
from karbor.services.protection.protection_plugins. \
database.database_backup_plugin import DatabaseBackupProtectionPlugin
from karbor.services.protection.protection_plugins.database \
import database_backup_plugin_schemas
from karbor.tests import base
import mock
from oslo_config import cfg
from oslo_config import fixture
class FakeBankPlugin(BankPlugin):

View File

@ -11,6 +11,12 @@
# under the License.
import collections
from unittest import mock
from keystoneauth1 import session as keystone_session
from oslo_config import cfg
from oslo_config import fixture
from karbor.common import constants
from karbor.context import RequestContext
from karbor.resource import Resource
@ -23,10 +29,6 @@ from karbor.services.protection.protection_plugins. \
from karbor.services.protection.protection_plugins.image \
import image_plugin_schemas
from karbor.tests import base
from keystoneauth1 import session as keystone_session
import mock
from oslo_config import cfg
from oslo_config import fixture
class FakeBankPlugin(BankPlugin):

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 oslo_config import cfg
import oslo_messaging

View File

@ -11,6 +11,11 @@
# under the License.
import collections
from unittest import mock
from oslo_config import cfg
from oslo_config import fixture
from karbor.common import constants
from karbor.context import RequestContext
from karbor.resource import Resource
@ -23,9 +28,6 @@ from karbor.services.protection.protection_plugins. \
from karbor.services.protection.protection_plugins.share \
import share_snapshot_plugin_schemas
from karbor.tests import base
import mock
from oslo_config import cfg
from oslo_config import fixture
class FakeBankPlugin(BankPlugin):

View File

@ -11,6 +11,10 @@
# under the License.
import collections
from unittest import mock
from oslo_config import cfg
from karbor.common import constants
from karbor.context import RequestContext
from karbor.resource import Resource
@ -23,8 +27,6 @@ from karbor.services.protection.protection_plugins.network \
from karbor.services.protection.protection_plugins.network. \
neutron_protection_plugin import NeutronProtectionPlugin
from karbor.tests import base
import mock
from oslo_config import cfg
FakeNetworks = {'networks': [
{u'status': u'ACTIVE',

View File

@ -11,7 +11,8 @@
# under the License.
from collections import namedtuple
import mock
from unittest import mock
from oslo_config import cfg
from karbor.common import constants

View File

@ -10,6 +10,15 @@
# License for the specific language governing permissions and limitations
# under the License.
from unittest import mock
from kubernetes.client.models.v1_object_meta import V1ObjectMeta
from kubernetes.client.models.v1_pod import V1Pod
from kubernetes.client.models.v1_pod_spec import V1PodSpec
from kubernetes.client.models.v1_pod_status import V1PodStatus
from oslo_config import cfg
from oslo_config import fixture
from karbor.common import constants
from karbor.context import RequestContext
from karbor.resource import Resource
@ -18,21 +27,11 @@ from karbor.services.protection.bank_plugin import BankPlugin
from karbor.services.protection.bank_plugin import BankSection
from karbor.services.protection import client_factory
from karbor.services.protection.clients import k8s
from karbor.services.protection.protection_plugins. \
pod.pod_protection_plugin import PodProtectionPlugin
from karbor.services.protection.protection_plugins.pod \
import pod_plugin_schemas
from kubernetes.client.models.v1_object_meta import V1ObjectMeta
from kubernetes.client.models.v1_pod import V1Pod
from kubernetes.client.models.v1_pod_spec import V1PodSpec
from kubernetes.client.models.v1_pod_status import V1PodStatus
from karbor.tests import base
import mock
from oslo_config import cfg
from oslo_config import fixture
class FakeBankPlugin(BankPlugin):

View File

@ -10,13 +10,14 @@
# License for the specific language governing permissions and limitations
# under the License.
import mock
from unittest import mock
from oslo_config import cfg
from karbor.resource import Resource
from karbor.services.protection import provider
from karbor.tests import base
from karbor.tests.unit.protection import fakes
from oslo_config import cfg
CONF = cfg.CONF

View File

@ -11,7 +11,9 @@
# under the License.
from functools import partial
import mock
from unittest import mock
from oslo_config import cfg
from karbor.common import constants
from karbor.resource import Resource
@ -20,7 +22,6 @@ from karbor.services.protection import graph
from karbor.services.protection import resource_flow
from karbor.tests import base
from karbor.tests.unit.protection import fakes
from oslo_config import cfg
CONF = cfg.CONF

View File

@ -10,14 +10,16 @@
# License for the specific language governing permissions and limitations
# under the License.
import math
import time
from unittest import mock
from oslo_config import cfg
from oslo_utils import importutils
from karbor.services.protection.clients import s3
from karbor.tests import base
from karbor.tests.unit.protection.fake_s3_client import FakeS3Client
import math
import mock
from oslo_config import cfg
from oslo_utils import importutils
import time
CONF = cfg.CONF

View File

@ -10,15 +10,17 @@
# License for the specific language governing permissions and limitations
# under the License.
import math
import os
import time
from unittest import mock
from oslo_config import cfg
from oslo_utils import importutils
from karbor.services.protection.clients import swift
from karbor.tests import base
from karbor.tests.unit.protection.fake_swift_client import FakeSwiftClient
import math
import mock
import os
from oslo_config import cfg
from oslo_utils import importutils
import time
CONF = cfg.CONF

View File

@ -10,15 +10,15 @@
# License for the specific language governing permissions and limitations
# under the License.
from unittest import mock
import six
from six.moves import http_client
import webob.util
from karbor import exception
from karbor.tests import base
import mock
import six
import webob.util
class KarborExceptionTestCase(base.TestCase):
def test_default_error_msg(self):

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 oslo_config import cfg

View File

@ -14,7 +14,8 @@
Unit Tests for remote procedure calls using queue
"""
import mock
from unittest import mock
from oslo_concurrency import processutils
from oslo_config import cfg
from oslo_db import exception as db_exc