diff --git a/HACKING.rst b/HACKING.rst index 466ea8649c..bbebe43810 100644 --- a/HACKING.rst +++ b/HACKING.rst @@ -19,8 +19,9 @@ Manila Specific Commandments - [M336] Must use a dict comprehension instead of a dict constructor with a sequence of key-value pairs. - [M337] Ensure to not use xrange(). -- [M354] Use oslo_utils.uuidutils to generate UUID instead of uuid4(). - [M338] Ensure to not use LOG.warn(). +- [M339] Ensure 'mock' is not imported/used. Use 'unittest.mock' instead. +- [M354] Use oslo_utils.uuidutils to generate UUID instead of uuid4(). - [M359] Validate that log messages are not translated. LOG Translations diff --git a/lower-constraints.txt b/lower-constraints.txt index d87bdfbb13..053e932bb5 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -46,7 +46,6 @@ lxml==3.4.1 Mako==1.0.7 MarkupSafe==1.0 mccabe==0.2.1 -mock==2.0.0 monotonic==1.4 mox3==0.25.0 msgpack==0.5.6 diff --git a/manila/hacking/checks.py b/manila/hacking/checks.py index 2708d533e7..f66e554688 100644 --- a/manila/hacking/checks.py +++ b/manila/hacking/checks.py @@ -53,6 +53,8 @@ dict_constructor_with_list_copy_re = re.compile(r".*\bdict\((\[)?(\(|\[)") assert_no_xrange_re = re.compile(r"\s*xrange\s*\(") assert_True = re.compile(r".*assertEqual\(True, .*\)") no_log_warn = re.compile(r"\s*LOG.warn\(.*") +third_party_mock = re.compile(r"^import.mock") +from_third_party_mock = re.compile(r"^from.mock.import") class BaseASTChecker(ast.NodeVisitor): @@ -333,3 +335,14 @@ def no_log_warn_check(logical_line): msg = ("M338: LOG.warn is deprecated, use LOG.warning.") if re.match(no_log_warn, logical_line): yield(0, msg) + + +@core.flake8ext +def no_third_party_mock(logical_line): + # We should only use unittest.mock, not the third party mock library that + # was needed for py2 support. + if (re.match(third_party_mock, logical_line) or + re.match(from_third_party_mock, logical_line)): + msg = ('M339: Unit tests should use the standard library "mock" ' + 'module, not the third party mock library.') + yield(0, msg) diff --git a/manila/test.py b/manila/test.py index 71768c0ecd..6fe00ec43e 100644 --- a/manila/test.py +++ b/manila/test.py @@ -23,9 +23,9 @@ inline callbacks. import os import shutil +from unittest import mock import fixtures -import mock from oslo_concurrency import lockutils from oslo_config import cfg from oslo_config import fixture as config_fixture diff --git a/manila/tests/api/openstack/test_wsgi.py b/manila/tests/api/openstack/test_wsgi.py index d222ab8539..13767733d5 100644 --- a/manila/tests/api/openstack/test_wsgi.py +++ b/manila/tests/api/openstack/test_wsgi.py @@ -10,13 +10,13 @@ # License for the specific language governing permissions and limitations # under the License. +import inspect +from unittest import mock + import ddt -import mock import six import webob -import inspect - from manila.api.openstack import api_version_request as api_version from manila.api.openstack import wsgi from manila import context diff --git a/manila/tests/api/test_common.py b/manila/tests/api/test_common.py index be386d2a94..4334135ed9 100644 --- a/manila/tests/api/test_common.py +++ b/manila/tests/api/test_common.py @@ -17,8 +17,9 @@ Test suites for 'common' code used throughout the OpenStack HTTP API. """ +from unittest import mock + import ddt -import mock import webob import webob.exc diff --git a/manila/tests/api/test_extensions.py b/manila/tests/api/test_extensions.py index fa73f1e3d2..c521b2aaf8 100644 --- a/manila/tests/api/test_extensions.py +++ b/manila/tests/api/test_extensions.py @@ -14,9 +14,10 @@ # License for the specific language governing permissions and limitations # under the License. +from unittest import mock + import ddt import iso8601 -import mock from oslo_config import cfg from oslo_serialization import jsonutils import webob diff --git a/manila/tests/api/test_versions.py b/manila/tests/api/test_versions.py index d0a4e56f8b..ee39c2a688 100644 --- a/manila/tests/api/test_versions.py +++ b/manila/tests/api/test_versions.py @@ -13,8 +13,9 @@ # License for the specific language governing permissions and limitations # under the License. +from unittest import mock + import ddt -import mock from oslo_serialization import jsonutils from oslo_utils import encodeutils diff --git a/manila/tests/api/v1/test_scheduler_stats.py b/manila/tests/api/v1/test_scheduler_stats.py index 1c2b65979c..c9fa440fe0 100644 --- a/manila/tests/api/v1/test_scheduler_stats.py +++ b/manila/tests/api/v1/test_scheduler_stats.py @@ -12,8 +12,9 @@ # License for the specific language governing permissions and limitations # under the License. +from unittest import mock + import ddt -import mock from oslo_utils import uuidutils from webob import exc diff --git a/manila/tests/api/v1/test_security_service.py b/manila/tests/api/v1/test_security_service.py index 11709e5d7a..9fe2c02831 100644 --- a/manila/tests/api/v1/test_security_service.py +++ b/manila/tests/api/v1/test_security_service.py @@ -13,8 +13,9 @@ # License for the specific language governing permissions and limitations # under the License. +from unittest import mock + import ddt -import mock from six.moves.urllib import parse import webob diff --git a/manila/tests/api/v1/test_share_manage.py b/manila/tests/api/v1/test_share_manage.py index 1dcad16d20..68affd208e 100644 --- a/manila/tests/api/v1/test_share_manage.py +++ b/manila/tests/api/v1/test_share_manage.py @@ -13,8 +13,9 @@ # License for the specific language governing permissions and limitations # under the License. +from unittest import mock + import ddt -import mock import webob from manila.api import common diff --git a/manila/tests/api/v1/test_share_servers.py b/manila/tests/api/v1/test_share_servers.py index e7ac003b1f..f4234d08e4 100644 --- a/manila/tests/api/v1/test_share_servers.py +++ b/manila/tests/api/v1/test_share_servers.py @@ -13,8 +13,9 @@ # License for the specific language governing permissions and limitations # under the License. +from unittest import mock + import ddt -import mock from webob import exc from manila.api.openstack import api_version_request as api_version diff --git a/manila/tests/api/v1/test_share_snapshots.py b/manila/tests/api/v1/test_share_snapshots.py index b9fcec0fc0..7e3f06b443 100644 --- a/manila/tests/api/v1/test_share_snapshots.py +++ b/manila/tests/api/v1/test_share_snapshots.py @@ -13,8 +13,9 @@ # License for the specific language governing permissions and limitations # under the License. +from unittest import mock + import ddt -import mock from oslo_serialization import jsonutils import six import webob diff --git a/manila/tests/api/v1/test_share_types_extra_specs.py b/manila/tests/api/v1/test_share_types_extra_specs.py index 983ed61359..a76c90e113 100644 --- a/manila/tests/api/v1/test_share_types_extra_specs.py +++ b/manila/tests/api/v1/test_share_types_extra_specs.py @@ -15,8 +15,9 @@ # License for the specific language governing permissions and limitations # under the License. +from unittest import mock + import ddt -import mock from oslo_utils import strutils import webob diff --git a/manila/tests/api/v1/test_share_unmanage.py b/manila/tests/api/v1/test_share_unmanage.py index be6c9cb8f4..a7027e67cb 100644 --- a/manila/tests/api/v1/test_share_unmanage.py +++ b/manila/tests/api/v1/test_share_unmanage.py @@ -13,8 +13,9 @@ # License for the specific language governing permissions and limitations # under the License. +from unittest import mock + import ddt -import mock import webob from manila.api.v1 import share_unmanage diff --git a/manila/tests/api/v1/test_shares.py b/manila/tests/api/v1/test_shares.py index 3dc83f36f7..e621290fdc 100644 --- a/manila/tests/api/v1/test_shares.py +++ b/manila/tests/api/v1/test_shares.py @@ -15,9 +15,9 @@ import copy import datetime +from unittest import mock import ddt -import mock from oslo_config import cfg from oslo_serialization import jsonutils import six diff --git a/manila/tests/api/v2/test_availability_zones.py b/manila/tests/api/v2/test_availability_zones.py index bc399bc565..f9fa6b5af4 100644 --- a/manila/tests/api/v2/test_availability_zones.py +++ b/manila/tests/api/v2/test_availability_zones.py @@ -12,8 +12,9 @@ # License for the specific language governing permissions and limitations # under the License. +from unittest import mock + import ddt -import mock from manila.api.v2 import availability_zones from manila import context diff --git a/manila/tests/api/v2/test_messages.py b/manila/tests/api/v2/test_messages.py index d5c5b8e8a5..a43de7d5b1 100644 --- a/manila/tests/api/v2/test_messages.py +++ b/manila/tests/api/v2/test_messages.py @@ -10,9 +10,10 @@ # License for the specific language governing permissions and limitations # under the License. +from unittest import mock + import datetime import iso8601 -import mock from oslo_config import cfg import webob diff --git a/manila/tests/api/v2/test_quota_class_sets.py b/manila/tests/api/v2/test_quota_class_sets.py index 9777963619..4621b5245c 100644 --- a/manila/tests/api/v2/test_quota_class_sets.py +++ b/manila/tests/api/v2/test_quota_class_sets.py @@ -19,9 +19,9 @@ Tests for manila.api.v1.quota_class_sets.py """ import copy +from unittest import mock import ddt -import mock from oslo_config import cfg import webob.exc import webob.response diff --git a/manila/tests/api/v2/test_quota_sets.py b/manila/tests/api/v2/test_quota_sets.py index 161d18846f..46e21eae4b 100644 --- a/manila/tests/api/v2/test_quota_sets.py +++ b/manila/tests/api/v2/test_quota_sets.py @@ -18,8 +18,9 @@ Tests for manila.api.v2.quota_sets.py """ +from unittest import mock + import ddt -import mock from oslo_config import cfg import webob.exc import webob.response diff --git a/manila/tests/api/v2/test_security_services.py b/manila/tests/api/v2/test_security_services.py index e1e2c7db4b..060e1c5c6e 100644 --- a/manila/tests/api/v2/test_security_services.py +++ b/manila/tests/api/v2/test_security_services.py @@ -12,9 +12,10 @@ # License for the specific language governing permissions and limitations # under the License. +from unittest import mock + import datetime import ddt -import mock from manila.api.v1 import security_service from manila.common import constants diff --git a/manila/tests/api/v2/test_services.py b/manila/tests/api/v2/test_services.py index 8ec047970e..819d55300c 100644 --- a/manila/tests/api/v2/test_services.py +++ b/manila/tests/api/v2/test_services.py @@ -16,9 +16,9 @@ import datetime +from unittest import mock import ddt -import mock from oslo_utils import timeutils from manila.api.v2 import services diff --git a/manila/tests/api/v2/test_share_access_metadata.py b/manila/tests/api/v2/test_share_access_metadata.py index 0346044eea..312c0e7aab 100644 --- a/manila/tests/api/v2/test_share_access_metadata.py +++ b/manila/tests/api/v2/test_share_access_metadata.py @@ -13,8 +13,9 @@ # License for the specific language governing permissions and limitations # under the License. +from unittest import mock + import ddt -import mock import webob from manila.api.v2 import share_access_metadata diff --git a/manila/tests/api/v2/test_share_accesses.py b/manila/tests/api/v2/test_share_accesses.py index 6d718633f3..4163729a19 100644 --- a/manila/tests/api/v2/test_share_accesses.py +++ b/manila/tests/api/v2/test_share_accesses.py @@ -13,8 +13,9 @@ # License for the specific language governing permissions and limitations # under the License. +from unittest import mock + import ddt -import mock from webob import exc from manila.api.v2 import share_accesses diff --git a/manila/tests/api/v2/test_share_export_locations.py b/manila/tests/api/v2/test_share_export_locations.py index 501cb99cf7..268e2dee02 100644 --- a/manila/tests/api/v2/test_share_export_locations.py +++ b/manila/tests/api/v2/test_share_export_locations.py @@ -13,8 +13,9 @@ # License for the specific language governing permissions and limitations # under the License. +from unittest import mock + import ddt -import mock from webob import exc from manila.api.openstack import api_version_request as api_version diff --git a/manila/tests/api/v2/test_share_group_snapshots.py b/manila/tests/api/v2/test_share_group_snapshots.py index ac7ed7bd7f..7562f8087e 100644 --- a/manila/tests/api/v2/test_share_group_snapshots.py +++ b/manila/tests/api/v2/test_share_group_snapshots.py @@ -15,9 +15,9 @@ import copy import datetime +from unittest import mock import ddt -import mock from oslo_config import cfg from oslo_serialization import jsonutils from oslo_utils import uuidutils diff --git a/manila/tests/api/v2/test_share_group_type_specs.py b/manila/tests/api/v2/test_share_group_type_specs.py index 2edd89a04c..eea4f20dc8 100644 --- a/manila/tests/api/v2/test_share_group_type_specs.py +++ b/manila/tests/api/v2/test_share_group_type_specs.py @@ -10,8 +10,9 @@ # License for the specific language governing permissions and limitations # under the License. +from unittest import mock + import ddt -import mock from oslo_utils import strutils import webob diff --git a/manila/tests/api/v2/test_share_group_types.py b/manila/tests/api/v2/test_share_group_types.py index 0d1d20a18d..02f87d7b5f 100644 --- a/manila/tests/api/v2/test_share_group_types.py +++ b/manila/tests/api/v2/test_share_group_types.py @@ -12,9 +12,9 @@ import copy import datetime +from unittest import mock import ddt -import mock from oslo_config import cfg import webob diff --git a/manila/tests/api/v2/test_share_groups.py b/manila/tests/api/v2/test_share_groups.py index 1d7730eb76..7cefc1efea 100644 --- a/manila/tests/api/v2/test_share_groups.py +++ b/manila/tests/api/v2/test_share_groups.py @@ -15,9 +15,9 @@ import copy import datetime +from unittest import mock import ddt -import mock from oslo_config import cfg from oslo_serialization import jsonutils from oslo_utils import uuidutils diff --git a/manila/tests/api/v2/test_share_instance_export_locations.py b/manila/tests/api/v2/test_share_instance_export_locations.py index 62c72f7fc0..242406c37d 100644 --- a/manila/tests/api/v2/test_share_instance_export_locations.py +++ b/manila/tests/api/v2/test_share_instance_export_locations.py @@ -13,8 +13,9 @@ # License for the specific language governing permissions and limitations # under the License. +from unittest import mock + import ddt -import mock from webob import exc from manila.api.v2 import share_instance_export_locations as export_locations diff --git a/manila/tests/api/v2/test_share_instances.py b/manila/tests/api/v2/test_share_instances.py index b851c6a577..3462944280 100644 --- a/manila/tests/api/v2/test_share_instances.py +++ b/manila/tests/api/v2/test_share_instances.py @@ -10,8 +10,9 @@ # License for the specific language governing permissions and limitations # under the License. +from unittest import mock + import ddt -import mock from oslo_config import cfg from oslo_serialization import jsonutils import six diff --git a/manila/tests/api/v2/test_share_network_subnets.py b/manila/tests/api/v2/test_share_network_subnets.py index 2496ee8c1f..d00ba8927c 100644 --- a/manila/tests/api/v2/test_share_network_subnets.py +++ b/manila/tests/api/v2/test_share_network_subnets.py @@ -14,8 +14,9 @@ # under the License. import copy +from unittest import mock + import ddt -import mock from oslo_db import exception as db_exception from manila.api import common diff --git a/manila/tests/api/v2/test_share_networks.py b/manila/tests/api/v2/test_share_networks.py index c1dce8f771..b4784f58c2 100644 --- a/manila/tests/api/v2/test_share_networks.py +++ b/manila/tests/api/v2/test_share_networks.py @@ -14,14 +14,15 @@ # under the License. import copy +from unittest import mock + import ddt -from manila.api import common -import mock from oslo_db import exception as db_exception from oslo_utils import timeutils from six.moves.urllib import parse from webob import exc as webob_exc +from manila.api import common from manila.api.openstack import api_version_request as api_version from manila.api.v2 import share_networks from manila.db import api as db_api diff --git a/manila/tests/api/v2/test_share_replica_export_locations.py b/manila/tests/api/v2/test_share_replica_export_locations.py index 622b33cd08..e13802b6bd 100644 --- a/manila/tests/api/v2/test_share_replica_export_locations.py +++ b/manila/tests/api/v2/test_share_replica_export_locations.py @@ -12,8 +12,9 @@ # License for the specific language governing permissions and limitations # under the License. +from unittest import mock + import ddt -import mock from webob import exc from manila.api.v2 import share_replica_export_locations as export_locations diff --git a/manila/tests/api/v2/test_share_replicas.py b/manila/tests/api/v2/test_share_replicas.py index 67ccd8a4fc..2936485291 100644 --- a/manila/tests/api/v2/test_share_replicas.py +++ b/manila/tests/api/v2/test_share_replicas.py @@ -13,8 +13,9 @@ # License for the specific language governing permissions and limitations # under the License. +from unittest import mock + import ddt -import mock from oslo_config import cfg from oslo_serialization import jsonutils import six diff --git a/manila/tests/api/v2/test_share_servers.py b/manila/tests/api/v2/test_share_servers.py index 41079e5ec7..8118afb329 100644 --- a/manila/tests/api/v2/test_share_servers.py +++ b/manila/tests/api/v2/test_share_servers.py @@ -13,8 +13,9 @@ # License for the specific language governing permissions and limitations # under the License. +from unittest import mock + import ddt -import mock import webob from manila.api.v2 import share_servers diff --git a/manila/tests/api/v2/test_share_snapshot_export_locations.py b/manila/tests/api/v2/test_share_snapshot_export_locations.py index f9dc81dcf5..ca960e31b4 100644 --- a/manila/tests/api/v2/test_share_snapshot_export_locations.py +++ b/manila/tests/api/v2/test_share_snapshot_export_locations.py @@ -13,8 +13,9 @@ # License for the specific language governing permissions and limitations # under the License. +from unittest import mock + import ddt -import mock from manila.api.v2 import share_snapshot_export_locations as export_locations from manila.common import constants diff --git a/manila/tests/api/v2/test_share_snapshot_instance_export_locations.py b/manila/tests/api/v2/test_share_snapshot_instance_export_locations.py index e7a3958a58..4f6cb295c2 100644 --- a/manila/tests/api/v2/test_share_snapshot_instance_export_locations.py +++ b/manila/tests/api/v2/test_share_snapshot_instance_export_locations.py @@ -13,8 +13,9 @@ # License for the specific language governing permissions and limitations # under the License. +from unittest import mock + import ddt -import mock from manila.api.v2 import share_snapshot_instance_export_locations as exp_loc from manila.common import constants diff --git a/manila/tests/api/v2/test_share_snapshot_instances.py b/manila/tests/api/v2/test_share_snapshot_instances.py index 89f92e1166..928711e1dd 100644 --- a/manila/tests/api/v2/test_share_snapshot_instances.py +++ b/manila/tests/api/v2/test_share_snapshot_instances.py @@ -12,8 +12,9 @@ # License for the specific language governing permissions and limitations # under the License. +from unittest import mock + import ddt -import mock from oslo_config import cfg from oslo_serialization import jsonutils import six diff --git a/manila/tests/api/v2/test_share_snapshots.py b/manila/tests/api/v2/test_share_snapshots.py index c73a3a9235..68eb49659a 100644 --- a/manila/tests/api/v2/test_share_snapshots.py +++ b/manila/tests/api/v2/test_share_snapshots.py @@ -13,8 +13,9 @@ # License for the specific language governing permissions and limitations # under the License. +from unittest import mock + import ddt -import mock from oslo_serialization import jsonutils import six import webob diff --git a/manila/tests/api/v2/test_share_types.py b/manila/tests/api/v2/test_share_types.py index be109fe46b..9240466bc7 100644 --- a/manila/tests/api/v2/test_share_types.py +++ b/manila/tests/api/v2/test_share_types.py @@ -14,12 +14,12 @@ # under the License. import datetime +import random +from unittest import mock import ddt -import mock from oslo_config import cfg from oslo_utils import timeutils -import random import webob from manila.api.v2 import share_types as types diff --git a/manila/tests/api/v2/test_shares.py b/manila/tests/api/v2/test_shares.py index d460f9c99f..eb354063c9 100644 --- a/manila/tests/api/v2/test_shares.py +++ b/manila/tests/api/v2/test_shares.py @@ -16,9 +16,9 @@ import copy import datetime import itertools +from unittest import mock import ddt -import mock from oslo_config import cfg from oslo_serialization import jsonutils from oslo_utils import uuidutils diff --git a/manila/tests/api/views/test_share_accesses.py b/manila/tests/api/views/test_share_accesses.py index 4b32659035..17c6e7c334 100644 --- a/manila/tests/api/views/test_share_accesses.py +++ b/manila/tests/api/views/test_share_accesses.py @@ -13,8 +13,9 @@ # License for the specific language governing permissions and limitations # under the License. +from unittest import mock + import ddt -import mock from manila.api.openstack import api_version_request as api_version from manila.api.views import share_accesses diff --git a/manila/tests/api/views/test_versions.py b/manila/tests/api/views/test_versions.py index dfbbe5535a..8e0ba14ea8 100644 --- a/manila/tests/api/views/test_versions.py +++ b/manila/tests/api/views/test_versions.py @@ -14,9 +14,9 @@ # under the License. import copy +from unittest import mock import ddt -import mock from manila.api.views import versions from manila import test diff --git a/manila/tests/cmd/test_manage.py b/manila/tests/cmd/test_manage.py index b333ac9982..fecc70e45a 100644 --- a/manila/tests/cmd/test_manage.py +++ b/manila/tests/cmd/test_manage.py @@ -16,9 +16,9 @@ import code import readline import sys +from unittest import mock import ddt -import mock from oslo_config import cfg import six diff --git a/manila/tests/cmd/test_share.py b/manila/tests/cmd/test_share.py index 630da9d9ec..e3ed42dcdf 100644 --- a/manila/tests/cmd/test_share.py +++ b/manila/tests/cmd/test_share.py @@ -14,9 +14,9 @@ # under the License. import sys +from unittest import mock import ddt -import mock from manila.cmd import share as manila_share from manila import test diff --git a/manila/tests/common/test_client_auth.py b/manila/tests/common/test_client_auth.py index 57726e0aaa..87ad8f059c 100644 --- a/manila/tests/common/test_client_auth.py +++ b/manila/tests/common/test_client_auth.py @@ -13,11 +13,11 @@ # License for the specific language governing permissions and limitations # under the License. +from unittest import mock + from keystoneauth1 import loading as auth from oslo_config import cfg -import mock - from manila.common import client_auth from manila import exception from manila import test diff --git a/manila/tests/compute/test_nova.py b/manila/tests/compute/test_nova.py index 147c640af1..c535182881 100644 --- a/manila/tests/compute/test_nova.py +++ b/manila/tests/compute/test_nova.py @@ -12,8 +12,9 @@ # License for the specific language governing permissions and limitations # under the License. +from unittest import mock + import ddt -import mock from novaclient import exceptions as nova_exception from novaclient import utils from novaclient.v2 import servers as nova_servers diff --git a/manila/tests/data/test_helper.py b/manila/tests/data/test_helper.py index 6f32f21381..7f3515dad1 100644 --- a/manila/tests/data/test_helper.py +++ b/manila/tests/data/test_helper.py @@ -14,9 +14,9 @@ # under the License. import os +from unittest import mock import ddt -import mock from manila.common import constants from manila import context diff --git a/manila/tests/data/test_manager.py b/manila/tests/data/test_manager.py index d8a226b734..7eeb820bee 100644 --- a/manila/tests/data/test_manager.py +++ b/manila/tests/data/test_manager.py @@ -15,8 +15,10 @@ """ Tests For Data Manager """ + +from unittest import mock + import ddt -import mock from manila.common import constants from manila import context diff --git a/manila/tests/data/test_rpcapi.py b/manila/tests/data/test_rpcapi.py index 59db6ce03c..9bcdd8427f 100644 --- a/manila/tests/data/test_rpcapi.py +++ b/manila/tests/data/test_rpcapi.py @@ -17,8 +17,8 @@ Unit Tests for manila.data.rpcapi """ import copy +from unittest import mock -import mock from oslo_config import cfg from oslo_serialization import jsonutils diff --git a/manila/tests/data/test_utils.py b/manila/tests/data/test_utils.py index 835205193c..de97a34df5 100644 --- a/manila/tests/data/test_utils.py +++ b/manila/tests/data/test_utils.py @@ -15,8 +15,7 @@ import os import time - -import mock +from unittest import mock from manila.data import utils as data_utils from manila import exception diff --git a/manila/tests/db/migrations/alembic/test_migration.py b/manila/tests/db/migrations/alembic/test_migration.py index 29c40f9b07..663485f879 100644 --- a/manila/tests/db/migrations/alembic/test_migration.py +++ b/manila/tests/db/migrations/alembic/test_migration.py @@ -17,8 +17,9 @@ Tests for database migrations. """ +from unittest import mock + from alembic import script -import mock from oslo_db.sqlalchemy import test_base from oslo_db.sqlalchemy import test_migrations from oslo_log import log diff --git a/manila/tests/db/sqlalchemy/test_api.py b/manila/tests/db/sqlalchemy/test_api.py index b972bc036e..2ea768743b 100644 --- a/manila/tests/db/sqlalchemy/test_api.py +++ b/manila/tests/db/sqlalchemy/test_api.py @@ -19,10 +19,10 @@ import copy import datetime -import ddt -import mock import random +from unittest import mock +import ddt from oslo_db import exception as db_exception from oslo_utils import timeutils from oslo_utils import uuidutils diff --git a/manila/tests/db/test_migration.py b/manila/tests/db/test_migration.py index 04a0ce5206..9d553a1d6a 100644 --- a/manila/tests/db/test_migration.py +++ b/manila/tests/db/test_migration.py @@ -13,8 +13,9 @@ # License for the specific language governing permissions and limitations # under the License. +from unittest import mock + import alembic -import mock from manila.db import migration from manila import test diff --git a/manila/tests/fake_service_instance.py b/manila/tests/fake_service_instance.py index be6ffe078e..9911ebcd53 100644 --- a/manila/tests/fake_service_instance.py +++ b/manila/tests/fake_service_instance.py @@ -12,7 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. -import mock +from unittest import mock from manila.tests import fake_compute diff --git a/manila/tests/fake_utils.py b/manila/tests/fake_utils.py index 0c0002c8ed..df660efceb 100644 --- a/manila/tests/fake_utils.py +++ b/manila/tests/fake_utils.py @@ -15,9 +15,9 @@ """This modules stubs out functions in manila.utils.""" import re +from unittest import mock from eventlet import greenthread -import mock from oslo_log import log import six diff --git a/manila/tests/message/test_api.py b/manila/tests/message/test_api.py index 75275bcade..7ea0182a90 100644 --- a/manila/tests/message/test_api.py +++ b/manila/tests/message/test_api.py @@ -9,9 +9,10 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. -import datetime -import mock +import datetime +from unittest import mock + from oslo_config import cfg from oslo_utils import timeutils diff --git a/manila/tests/network/linux/test_interface.py b/manila/tests/network/linux/test_interface.py index 9897cd80a1..7dccda88df 100644 --- a/manila/tests/network/linux/test_interface.py +++ b/manila/tests/network/linux/test_interface.py @@ -13,7 +13,8 @@ # License for the specific language governing permissions and limitations # under the License. -import mock +from unittest import mock + import six from manila.network.linux import interface diff --git a/manila/tests/network/linux/test_ip_lib.py b/manila/tests/network/linux/test_ip_lib.py index faf0ba4d83..6dd7e0280c 100644 --- a/manila/tests/network/linux/test_ip_lib.py +++ b/manila/tests/network/linux/test_ip_lib.py @@ -13,7 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. -import mock +from unittest import mock from manila.network.linux import ip_lib from manila import test diff --git a/manila/tests/network/linux/test_ovs_lib.py b/manila/tests/network/linux/test_ovs_lib.py index e26636b578..89593d1e33 100644 --- a/manila/tests/network/linux/test_ovs_lib.py +++ b/manila/tests/network/linux/test_ovs_lib.py @@ -12,7 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. -import mock +from unittest import mock from manila.network.linux import ovs_lib from manila import test diff --git a/manila/tests/network/neutron/test_neutron_api.py b/manila/tests/network/neutron/test_neutron_api.py index 5bbcb75af7..1ae0d334af 100644 --- a/manila/tests/network/neutron/test_neutron_api.py +++ b/manila/tests/network/neutron/test_neutron_api.py @@ -14,7 +14,8 @@ # License for the specific language governing permissions and limitations # under the License. -import mock +from unittest import mock + from neutronclient.common import exceptions as neutron_client_exc from neutronclient.v2_0 import client as clientv20 from oslo_config import cfg diff --git a/manila/tests/network/neutron/test_neutron_plugin.py b/manila/tests/network/neutron/test_neutron_plugin.py index c14917b625..982c83e750 100644 --- a/manila/tests/network/neutron/test_neutron_plugin.py +++ b/manila/tests/network/neutron/test_neutron_plugin.py @@ -15,10 +15,10 @@ # under the License. import copy -import ddt -import mock import time +from unittest import mock +import ddt from oslo_config import cfg from manila.common import constants diff --git a/manila/tests/network/test_standalone_network_plugin.py b/manila/tests/network/test_standalone_network_plugin.py index b4c98d7f31..e26685d091 100644 --- a/manila/tests/network/test_standalone_network_plugin.py +++ b/manila/tests/network/test_standalone_network_plugin.py @@ -13,8 +13,9 @@ # License for the specific language governing permissions and limitations # under the License. +from unittest import mock + import ddt -import mock import netaddr from oslo_config import cfg import six diff --git a/manila/tests/scheduler/drivers/test_base.py b/manila/tests/scheduler/drivers/test_base.py index a1c38e7ed1..1405d86ad4 100644 --- a/manila/tests/scheduler/drivers/test_base.py +++ b/manila/tests/scheduler/drivers/test_base.py @@ -17,7 +17,8 @@ Tests For Base Scheduler """ -import mock +from unittest import mock + from oslo_config import cfg from oslo_utils import timeutils diff --git a/manila/tests/scheduler/drivers/test_filter.py b/manila/tests/scheduler/drivers/test_filter.py index 0097249bde..365b94c72a 100644 --- a/manila/tests/scheduler/drivers/test_filter.py +++ b/manila/tests/scheduler/drivers/test_filter.py @@ -16,8 +16,9 @@ Tests For Filter Scheduler. """ +from unittest import mock + import ddt -import mock from oslo_utils import strutils from manila.common import constants diff --git a/manila/tests/scheduler/drivers/test_simple.py b/manila/tests/scheduler/drivers/test_simple.py index 488fc51b23..109f438e58 100644 --- a/manila/tests/scheduler/drivers/test_simple.py +++ b/manila/tests/scheduler/drivers/test_simple.py @@ -17,7 +17,8 @@ Tests For Simple Scheduler """ -import mock +from unittest import mock + from oslo_config import cfg from manila import context diff --git a/manila/tests/scheduler/filters/test_base.py b/manila/tests/scheduler/filters/test_base.py index 6cd4e03801..ae3aa56274 100644 --- a/manila/tests/scheduler/filters/test_base.py +++ b/manila/tests/scheduler/filters/test_base.py @@ -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 manila.scheduler.filters import base from manila import test diff --git a/manila/tests/scheduler/test_host_manager.py b/manila/tests/scheduler/test_host_manager.py index 4bdbe19826..ffb7fa790b 100644 --- a/manila/tests/scheduler/test_host_manager.py +++ b/manila/tests/scheduler/test_host_manager.py @@ -19,8 +19,9 @@ Tests For HostManager """ import copy +from unittest import mock + import ddt -import mock from oslo_config import cfg from oslo_utils import timeutils from six import moves diff --git a/manila/tests/scheduler/test_manager.py b/manila/tests/scheduler/test_manager.py index 80d2110469..38919a4682 100644 --- a/manila/tests/scheduler/test_manager.py +++ b/manila/tests/scheduler/test_manager.py @@ -17,14 +17,10 @@ Tests For Scheduler Manager """ -try: - # Python3 variant - from importlib import reload -except ImportError: - pass +from importlib import reload +from unittest import mock import ddt -import mock from oslo_config import cfg from manila.common import constants diff --git a/manila/tests/scheduler/test_rpcapi.py b/manila/tests/scheduler/test_rpcapi.py index effdaf310a..abe33fe090 100644 --- a/manila/tests/scheduler/test_rpcapi.py +++ b/manila/tests/scheduler/test_rpcapi.py @@ -17,8 +17,8 @@ Unit Tests for manila.scheduler.rpcapi """ import copy +from unittest import mock -import mock from oslo_config import cfg from manila import context diff --git a/manila/tests/scheduler/weighers/test_capacity.py b/manila/tests/scheduler/weighers/test_capacity.py index a950da0990..5444180f7f 100644 --- a/manila/tests/scheduler/weighers/test_capacity.py +++ b/manila/tests/scheduler/weighers/test_capacity.py @@ -16,8 +16,9 @@ Tests For Capacity Weigher. """ +from unittest import mock + import ddt -import mock from oslo_config import cfg from manila import context diff --git a/manila/tests/scheduler/weighers/test_host_affinity.py b/manila/tests/scheduler/weighers/test_host_affinity.py index b5778b0a89..6b5d809bf2 100644 --- a/manila/tests/scheduler/weighers/test_host_affinity.py +++ b/manila/tests/scheduler/weighers/test_host_affinity.py @@ -17,7 +17,7 @@ Tests for Host Affinity Weigher. """ -import mock +from unittest import mock from manila.common import constants from manila.db import api as db_api diff --git a/manila/tests/scheduler/weighers/test_pool.py b/manila/tests/scheduler/weighers/test_pool.py index 41ac789278..80c75225fd 100644 --- a/manila/tests/scheduler/weighers/test_pool.py +++ b/manila/tests/scheduler/weighers/test_pool.py @@ -16,7 +16,8 @@ Tests For Pool Weigher. """ -import mock +from unittest import mock + from oslo_config import cfg from oslo_utils import timeutils diff --git a/manila/tests/share/drivers/cephfs/test_driver.py b/manila/tests/share/drivers/cephfs/test_driver.py index 3dcdcecfcc..854cf9686b 100644 --- a/manila/tests/share/drivers/cephfs/test_driver.py +++ b/manila/tests/share/drivers/cephfs/test_driver.py @@ -13,12 +13,11 @@ # License for the specific language governing permissions and limitations # under the License. +from unittest import mock import ddt -import mock from oslo_utils import units - from manila.common import constants from manila import context import manila.exception as exception diff --git a/manila/tests/share/drivers/container/test_container_helper.py b/manila/tests/share/drivers/container/test_container_helper.py index 618f8f8494..2cf7da8b34 100644 --- a/manila/tests/share/drivers/container/test_container_helper.py +++ b/manila/tests/share/drivers/container/test_container_helper.py @@ -14,10 +14,11 @@ # under the License. """Unit tests for the Container helper module.""" -import ddt -import mock +from unittest import mock import uuid +import ddt + from manila import exception from manila.share import configuration from manila.share.drivers.container import container_helper diff --git a/manila/tests/share/drivers/container/test_driver.py b/manila/tests/share/drivers/container/test_driver.py index ebe5d45429..7df359379e 100644 --- a/manila/tests/share/drivers/container/test_driver.py +++ b/manila/tests/share/drivers/container/test_driver.py @@ -14,9 +14,10 @@ # under the License. """Unit tests for the Container driver module.""" -import ddt import functools -import mock +from unittest import mock + +import ddt from oslo_config import cfg from manila.common import constants as const diff --git a/manila/tests/share/drivers/container/test_protocol_helper.py b/manila/tests/share/drivers/container/test_protocol_helper.py index 0896f78e4d..44c8c03abb 100644 --- a/manila/tests/share/drivers/container/test_protocol_helper.py +++ b/manila/tests/share/drivers/container/test_protocol_helper.py @@ -14,9 +14,10 @@ # under the License. """Unit tests for the Protocol helper module.""" -import ddt import functools -import mock +from unittest import mock + +import ddt from manila.common import constants as const from manila import exception diff --git a/manila/tests/share/drivers/container/test_storage_helper.py b/manila/tests/share/drivers/container/test_storage_helper.py index 00fb5b9964..cae63a47dc 100644 --- a/manila/tests/share/drivers/container/test_storage_helper.py +++ b/manila/tests/share/drivers/container/test_storage_helper.py @@ -13,9 +13,11 @@ # License for the specific language governing permissions and limitations # under the License. """Unit tests for the Storage helper module.""" -import ddt + import functools -import mock +from unittest import mock + +import ddt from manila import exception from manila.share import configuration diff --git a/manila/tests/share/drivers/dell_emc/common/enas/fakes.py b/manila/tests/share/drivers/dell_emc/common/enas/fakes.py index 35e1e8c7fd..23f2b07eec 100644 --- a/manila/tests/share/drivers/dell_emc/common/enas/fakes.py +++ b/manila/tests/share/drivers/dell_emc/common/enas/fakes.py @@ -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 units from manila.common import constants as const diff --git a/manila/tests/share/drivers/dell_emc/common/enas/test_connector.py b/manila/tests/share/drivers/dell_emc/common/enas/test_connector.py index 4b1a85827e..bb4d2068c4 100644 --- a/manila/tests/share/drivers/dell_emc/common/enas/test_connector.py +++ b/manila/tests/share/drivers/dell_emc/common/enas/test_connector.py @@ -13,8 +13,9 @@ # License for the specific language governing permissions and limitations # under the License. +from unittest import mock + from eventlet import greenthread -import mock from oslo_concurrency import processutils from six.moves.urllib import error as url_error from six.moves.urllib import request as url_request diff --git a/manila/tests/share/drivers/dell_emc/common/enas/test_utils.py b/manila/tests/share/drivers/dell_emc/common/enas/test_utils.py index a3e20be59d..3f908c0b37 100644 --- a/manila/tests/share/drivers/dell_emc/common/enas/test_utils.py +++ b/manila/tests/share/drivers/dell_emc/common/enas/test_utils.py @@ -13,9 +13,10 @@ # License for the specific language governing permissions and limitations # under the License. -import ddt -import mock import ssl +from unittest import mock + +import ddt from manila.share.drivers.dell_emc.common.enas import utils from manila import test diff --git a/manila/tests/share/drivers/dell_emc/common/enas/utils.py b/manila/tests/share/drivers/dell_emc/common/enas/utils.py index 001fcee91d..246c521b81 100644 --- a/manila/tests/share/drivers/dell_emc/common/enas/utils.py +++ b/manila/tests/share/drivers/dell_emc/common/enas/utils.py @@ -14,9 +14,9 @@ # under the License. import doctest +from unittest import mock from lxml import doctestcompare -import mock import six diff --git a/manila/tests/share/drivers/dell_emc/plugins/isilon/test_isilon.py b/manila/tests/share/drivers/dell_emc/plugins/isilon/test_isilon.py index fffa167e60..acd28f14dd 100644 --- a/manila/tests/share/drivers/dell_emc/plugins/isilon/test_isilon.py +++ b/manila/tests/share/drivers/dell_emc/plugins/isilon/test_isilon.py @@ -13,8 +13,9 @@ # License for the specific language governing permissions and limitations # under the License. +from unittest import mock + import ddt -import mock from oslo_log import log from oslo_utils import units from requests.exceptions import HTTPError diff --git a/manila/tests/share/drivers/dell_emc/plugins/powermax/test_connection.py b/manila/tests/share/drivers/dell_emc/plugins/powermax/test_connection.py index abab23d787..2bc9ee59d1 100644 --- a/manila/tests/share/drivers/dell_emc/plugins/powermax/test_connection.py +++ b/manila/tests/share/drivers/dell_emc/plugins/powermax/test_connection.py @@ -14,9 +14,9 @@ # under the License. import copy +from unittest import mock import ddt -import mock from oslo_log import log from manila import exception diff --git a/manila/tests/share/drivers/dell_emc/plugins/powermax/test_object_manager.py b/manila/tests/share/drivers/dell_emc/plugins/powermax/test_object_manager.py index 312feb1e88..dd910acf5c 100644 --- a/manila/tests/share/drivers/dell_emc/plugins/powermax/test_object_manager.py +++ b/manila/tests/share/drivers/dell_emc/plugins/powermax/test_object_manager.py @@ -14,10 +14,10 @@ # under the License. import copy +from unittest import mock import ddt from lxml import builder -import mock from oslo_concurrency import processutils from manila import exception diff --git a/manila/tests/share/drivers/dell_emc/plugins/unity/__init__.py b/manila/tests/share/drivers/dell_emc/plugins/unity/__init__.py index b7a08a4c8a..36be623d29 100644 --- a/manila/tests/share/drivers/dell_emc/plugins/unity/__init__.py +++ b/manila/tests/share/drivers/dell_emc/plugins/unity/__init__.py @@ -13,8 +13,8 @@ # License for the specific language governing permissions and limitations # under the License. -import mock import sys +from unittest import mock sys.modules['storops'] = mock.Mock() sys.modules['storops.unity'] = mock.Mock() diff --git a/manila/tests/share/drivers/dell_emc/plugins/unity/res_mock.py b/manila/tests/share/drivers/dell_emc/plugins/unity/res_mock.py index 6604bc7696..da45d6a9a3 100644 --- a/manila/tests/share/drivers/dell_emc/plugins/unity/res_mock.py +++ b/manila/tests/share/drivers/dell_emc/plugins/unity/res_mock.py @@ -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 oslo_log import log diff --git a/manila/tests/share/drivers/dell_emc/plugins/unity/test_client.py b/manila/tests/share/drivers/dell_emc/plugins/unity/test_client.py index f8fc90eeda..87f0f13c76 100644 --- a/manila/tests/share/drivers/dell_emc/plugins/unity/test_client.py +++ b/manila/tests/share/drivers/dell_emc/plugins/unity/test_client.py @@ -13,8 +13,9 @@ # License for the specific language governing permissions and limitations # under the License. +from unittest import mock + import ddt -import mock from oslo_utils import units from manila import exception diff --git a/manila/tests/share/drivers/dell_emc/plugins/unity/test_connection.py b/manila/tests/share/drivers/dell_emc/plugins/unity/test_connection.py index d193556b14..1eb2855cde 100644 --- a/manila/tests/share/drivers/dell_emc/plugins/unity/test_connection.py +++ b/manila/tests/share/drivers/dell_emc/plugins/unity/test_connection.py @@ -14,8 +14,9 @@ # under the License. import copy +from unittest import mock + import ddt -import mock from oslo_utils import units import six diff --git a/manila/tests/share/drivers/dell_emc/plugins/unity/utils.py b/manila/tests/share/drivers/dell_emc/plugins/unity/utils.py index d46b1fbeab..6346cc0fdf 100644 --- a/manila/tests/share/drivers/dell_emc/plugins/unity/utils.py +++ b/manila/tests/share/drivers/dell_emc/plugins/unity/utils.py @@ -14,9 +14,9 @@ # under the License. from os import path +from unittest import mock import yaml -import mock from oslo_log import log LOG = log.getLogger(__name__) diff --git a/manila/tests/share/drivers/dell_emc/plugins/vnx/test_connection.py b/manila/tests/share/drivers/dell_emc/plugins/vnx/test_connection.py index f1f00cad61..096c36da79 100644 --- a/manila/tests/share/drivers/dell_emc/plugins/vnx/test_connection.py +++ b/manila/tests/share/drivers/dell_emc/plugins/vnx/test_connection.py @@ -14,9 +14,9 @@ # under the License. import copy +from unittest import mock import ddt -import mock from oslo_log import log from manila import exception diff --git a/manila/tests/share/drivers/dell_emc/plugins/vnx/test_object_manager.py b/manila/tests/share/drivers/dell_emc/plugins/vnx/test_object_manager.py index 8657e8015f..3d09140c7b 100644 --- a/manila/tests/share/drivers/dell_emc/plugins/vnx/test_object_manager.py +++ b/manila/tests/share/drivers/dell_emc/plugins/vnx/test_object_manager.py @@ -15,10 +15,11 @@ import copy import time +from unittest import mock + import ddt from lxml import builder -import mock from oslo_concurrency import processutils diff --git a/manila/tests/share/drivers/dell_emc/test_driver.py b/manila/tests/share/drivers/dell_emc/test_driver.py index 1050be0959..88b2ce8dab 100644 --- a/manila/tests/share/drivers/dell_emc/test_driver.py +++ b/manila/tests/share/drivers/dell_emc/test_driver.py @@ -13,7 +13,8 @@ # License for the specific language governing permissions and limitations # under the License. -import mock +from unittest import mock + from stevedore import extension from manila.share import configuration as conf diff --git a/manila/tests/share/drivers/ganesha/test_manager.py b/manila/tests/share/drivers/ganesha/test_manager.py index e5a809c8b6..5e8c565e01 100644 --- a/manila/tests/share/drivers/ganesha/test_manager.py +++ b/manila/tests/share/drivers/ganesha/test_manager.py @@ -15,9 +15,9 @@ import copy import re +from unittest import mock import ddt -import mock from oslo_serialization import jsonutils import six diff --git a/manila/tests/share/drivers/ganesha/test_utils.py b/manila/tests/share/drivers/ganesha/test_utils.py index 2a28b13397..0c276adfb4 100644 --- a/manila/tests/share/drivers/ganesha/test_utils.py +++ b/manila/tests/share/drivers/ganesha/test_utils.py @@ -14,9 +14,9 @@ # under the License. import os +from unittest import mock import ddt -import mock from manila import exception from manila.share.drivers.ganesha import utils as ganesha_utils diff --git a/manila/tests/share/drivers/glusterfs/test_common.py b/manila/tests/share/drivers/glusterfs/test_common.py index 3f97331949..14a0bf8e2b 100644 --- a/manila/tests/share/drivers/glusterfs/test_common.py +++ b/manila/tests/share/drivers/glusterfs/test_common.py @@ -15,8 +15,9 @@ """Test cases for GlusterFS common routines.""" +from unittest import mock + import ddt -import mock from oslo_config import cfg from manila import exception diff --git a/manila/tests/share/drivers/glusterfs/test_glusterfs_native.py b/manila/tests/share/drivers/glusterfs/test_glusterfs_native.py index 84d7ca8260..f6c90ad1bc 100644 --- a/manila/tests/share/drivers/glusterfs/test_glusterfs_native.py +++ b/manila/tests/share/drivers/glusterfs/test_glusterfs_native.py @@ -18,8 +18,9 @@ Test cases for GlusterFS native protocol driver. """ +from unittest import mock + import ddt -import mock from oslo_config import cfg from manila.common import constants diff --git a/manila/tests/share/drivers/glusterfs/test_layout.py b/manila/tests/share/drivers/glusterfs/test_layout.py index c019153ac0..a82b830ca0 100644 --- a/manila/tests/share/drivers/glusterfs/test_layout.py +++ b/manila/tests/share/drivers/glusterfs/test_layout.py @@ -15,9 +15,9 @@ import errno import os +from unittest import mock import ddt -import mock from oslo_config import cfg from oslo_utils import importutils diff --git a/manila/tests/share/drivers/glusterfs/test_layout_directory.py b/manila/tests/share/drivers/glusterfs/test_layout_directory.py index f4a942b575..a3e1dadc1a 100644 --- a/manila/tests/share/drivers/glusterfs/test_layout_directory.py +++ b/manila/tests/share/drivers/glusterfs/test_layout_directory.py @@ -14,9 +14,9 @@ # under the License. import os +from unittest import mock import ddt -import mock from oslo_config import cfg from manila import context diff --git a/manila/tests/share/drivers/glusterfs/test_layout_volume.py b/manila/tests/share/drivers/glusterfs/test_layout_volume.py index e94a9f394e..ea84af55ad 100644 --- a/manila/tests/share/drivers/glusterfs/test_layout_volume.py +++ b/manila/tests/share/drivers/glusterfs/test_layout_volume.py @@ -19,9 +19,9 @@ import re import shutil import tempfile +from unittest import mock import ddt -import mock from oslo_config import cfg from manila.common import constants diff --git a/manila/tests/share/drivers/hdfs/test_hdfs_native.py b/manila/tests/share/drivers/hdfs/test_hdfs_native.py index 2cd1ebd237..498042ec01 100644 --- a/manila/tests/share/drivers/hdfs/test_hdfs_native.py +++ b/manila/tests/share/drivers/hdfs/test_hdfs_native.py @@ -15,8 +15,8 @@ """Unit tests for HDFS native protocol driver module.""" import socket +from unittest import mock -import mock from oslo_concurrency import processutils from oslo_config import cfg import six diff --git a/manila/tests/share/drivers/hitachi/hnas/test_driver.py b/manila/tests/share/drivers/hitachi/hnas/test_driver.py index b5a524cdd0..931abc49c6 100644 --- a/manila/tests/share/drivers/hitachi/hnas/test_driver.py +++ b/manila/tests/share/drivers/hitachi/hnas/test_driver.py @@ -13,8 +13,9 @@ # License for the specific language governing permissions and limitations # under the License. +from unittest import mock + import ddt -import mock from oslo_config import cfg from manila import exception diff --git a/manila/tests/share/drivers/hitachi/hnas/test_ssh.py b/manila/tests/share/drivers/hitachi/hnas/test_ssh.py index 6889dc06ff..f9706ea92b 100644 --- a/manila/tests/share/drivers/hitachi/hnas/test_ssh.py +++ b/manila/tests/share/drivers/hitachi/hnas/test_ssh.py @@ -14,9 +14,9 @@ # under the License. import time +from unittest import mock import ddt -import mock from oslo_concurrency import processutils as putils from oslo_config import cfg import paramiko diff --git a/manila/tests/share/drivers/hitachi/hsp/test_driver.py b/manila/tests/share/drivers/hitachi/hsp/test_driver.py index 6813c69853..1df887ab18 100644 --- a/manila/tests/share/drivers/hitachi/hsp/test_driver.py +++ b/manila/tests/share/drivers/hitachi/hsp/test_driver.py @@ -13,8 +13,9 @@ # License for the specific language governing permissions and limitations # under the License. +from unittest import mock + import ddt -import mock from oslo_config import cfg from manila import exception diff --git a/manila/tests/share/drivers/hitachi/hsp/test_rest.py b/manila/tests/share/drivers/hitachi/hsp/test_rest.py index 5798957995..db64120e5e 100644 --- a/manila/tests/share/drivers/hitachi/hsp/test_rest.py +++ b/manila/tests/share/drivers/hitachi/hsp/test_rest.py @@ -15,9 +15,9 @@ import ddt import json -import mock import requests import time +from unittest import mock from manila import exception from manila.share.drivers.hitachi.hsp import rest diff --git a/manila/tests/share/drivers/hpe/test_hpe_3par_driver.py b/manila/tests/share/drivers/hpe/test_hpe_3par_driver.py index 55807fc419..88cd7f75de 100644 --- a/manila/tests/share/drivers/hpe/test_hpe_3par_driver.py +++ b/manila/tests/share/drivers/hpe/test_hpe_3par_driver.py @@ -14,9 +14,9 @@ from copy import deepcopy import sys +from unittest import mock import ddt -import mock if 'hpe3parclient' not in sys.modules: sys.modules['hpe3parclient'] = mock.Mock() diff --git a/manila/tests/share/drivers/hpe/test_hpe_3par_mediator.py b/manila/tests/share/drivers/hpe/test_hpe_3par_mediator.py index 9c969dcc03..e0f7e794d5 100644 --- a/manila/tests/share/drivers/hpe/test_hpe_3par_mediator.py +++ b/manila/tests/share/drivers/hpe/test_hpe_3par_mediator.py @@ -13,11 +13,13 @@ # under the License. import sys +from unittest import mock import ddt -import mock if 'hpe3parclient' not in sys.modules: sys.modules['hpe3parclient'] = mock.Mock() +from oslo_utils import units +import six from manila.data import utils as data_utils from manila import exception @@ -26,8 +28,6 @@ from manila import test from manila.tests.share.drivers.hpe import test_hpe_3par_constants as constants from manila import utils -from oslo_utils import units -import six CLIENT_VERSION_MIN_OK = hpe3parmediator.MIN_CLIENT_VERSION TEST_WSAPI_VERSION_STR = '30201292' diff --git a/manila/tests/share/drivers/huawei/test_huawei_nas.py b/manila/tests/share/drivers/huawei/test_huawei_nas.py index 223f5e6516..2dbf44ace1 100644 --- a/manila/tests/share/drivers/huawei/test_huawei_nas.py +++ b/manila/tests/share/drivers/huawei/test_huawei_nas.py @@ -22,10 +22,10 @@ import shutil import six import tempfile import time +from unittest import mock import xml.dom.minidom import ddt -import mock from oslo_serialization import jsonutils from xml.etree import ElementTree as ET diff --git a/manila/tests/share/drivers/ibm/test_gpfs.py b/manila/tests/share/drivers/ibm/test_gpfs.py index 718697562f..57fdd1a36d 100644 --- a/manila/tests/share/drivers/ibm/test_gpfs.py +++ b/manila/tests/share/drivers/ibm/test_gpfs.py @@ -16,9 +16,9 @@ import re import socket +from unittest import mock import ddt -import mock from oslo_config import cfg from manila import context diff --git a/manila/tests/share/drivers/infinidat/test_infinidat.py b/manila/tests/share/drivers/infinidat/test_infinidat.py index 3d58d1c4fe..dd4e634e41 100644 --- a/manila/tests/share/drivers/infinidat/test_infinidat.py +++ b/manila/tests/share/drivers/infinidat/test_infinidat.py @@ -16,7 +16,8 @@ import copy import functools -import mock +from unittest import mock + from oslo_utils import units from manila.common import constants diff --git a/manila/tests/share/drivers/infortrend/test_infortrend_nas.py b/manila/tests/share/drivers/infortrend/test_infortrend_nas.py index e55cc54d2d..7d65248f3f 100644 --- a/manila/tests/share/drivers/infortrend/test_infortrend_nas.py +++ b/manila/tests/share/drivers/infortrend/test_infortrend_nas.py @@ -13,9 +13,9 @@ # License for the specific language governing permissions and limitations # under the License. -import ddt -import mock +from unittest import mock +import ddt from oslo_config import cfg from manila import context diff --git a/manila/tests/share/drivers/inspur/as13000/test_as13000_nas.py b/manila/tests/share/drivers/inspur/as13000/test_as13000_nas.py index 73e5e62ac9..05344e7077 100644 --- a/manila/tests/share/drivers/inspur/as13000/test_as13000_nas.py +++ b/manila/tests/share/drivers/inspur/as13000/test_as13000_nas.py @@ -17,12 +17,13 @@ Share driver test for Inspur AS13000 """ -import ddt import json -import mock +import time +from unittest import mock + +import ddt from oslo_config import cfg import requests -import time from manila import context from manila import exception @@ -1147,8 +1148,8 @@ class AS13000ShareDriverTestCase(test.TestCase): @ddt.data('5000000000', '5000000k', '5000mb', '50G', '5TB') def test__unit_convert(self, capacity): - trans = {'5000000000': '%.0f' % (float(5000000000) / 1024**3), - '5000000k': '%.0f' % (float(5000000) / 1024**2), + trans = {'5000000000': '%.0f' % (float(5000000000) / 1024 ** 3), + '5000000k': '%.0f' % (float(5000000) / 1024 ** 2), '5000mb': '%.0f' % (float(5000) / 1024), '50G': '%.0f' % float(50), '5TB': '%.0f' % (float(5) * 1024)} diff --git a/manila/tests/share/drivers/inspur/instorage/test_instorage.py b/manila/tests/share/drivers/inspur/instorage/test_instorage.py index a2cdf2355c..2fff7fc1f0 100644 --- a/manila/tests/share/drivers/inspur/instorage/test_instorage.py +++ b/manila/tests/share/drivers/inspur/instorage/test_instorage.py @@ -17,14 +17,13 @@ Share driver test for Inspur InStorage """ +from unittest import mock + import ddt -import mock -import paramiko - from eventlet import greenthread - from oslo_concurrency import processutils from oslo_config import cfg +import paramiko from manila import context from manila import exception diff --git a/manila/tests/share/drivers/maprfs/test_maprfs.py b/manila/tests/share/drivers/maprfs/test_maprfs.py index 47514e617e..7e2cd5295a 100644 --- a/manila/tests/share/drivers/maprfs/test_maprfs.py +++ b/manila/tests/share/drivers/maprfs/test_maprfs.py @@ -14,7 +14,8 @@ """Unit tests for MapRFS native protocol driver module.""" -import mock +from unittest import mock + from oslo_concurrency import processutils from oslo_config import cfg import six diff --git a/manila/tests/share/drivers/netapp/dataontap/client/fakes.py b/manila/tests/share/drivers/netapp/dataontap/client/fakes.py index 9cc5e1da8c..2135931c2e 100644 --- a/manila/tests/share/drivers/netapp/dataontap/client/fakes.py +++ b/manila/tests/share/drivers/netapp/dataontap/client/fakes.py @@ -12,8 +12,9 @@ # License for the specific language governing permissions and limitations # under the License. +from unittest import mock + from lxml import etree -import mock from six.moves import urllib from manila.share.drivers.netapp.dataontap.client import api diff --git a/manila/tests/share/drivers/netapp/dataontap/client/test_api.py b/manila/tests/share/drivers/netapp/dataontap/client/test_api.py index 726654793c..eaf88a782a 100644 --- a/manila/tests/share/drivers/netapp/dataontap/client/test_api.py +++ b/manila/tests/share/drivers/netapp/dataontap/client/test_api.py @@ -18,8 +18,10 @@ """ Tests for NetApp API layer """ + +from unittest import mock + import ddt -import mock from six.moves import urllib from manila import exception diff --git a/manila/tests/share/drivers/netapp/dataontap/client/test_client_base.py b/manila/tests/share/drivers/netapp/dataontap/client/test_client_base.py index 382ae22011..10da9f39c5 100644 --- a/manila/tests/share/drivers/netapp/dataontap/client/test_client_base.py +++ b/manila/tests/share/drivers/netapp/dataontap/client/test_client_base.py @@ -13,8 +13,9 @@ # License for the specific language governing permissions and limitations # under the License. +from unittest import mock + import ddt -import mock from oslo_log import log from manila.share.drivers.netapp.dataontap.client import api as netapp_api diff --git a/manila/tests/share/drivers/netapp/dataontap/client/test_client_cmode.py b/manila/tests/share/drivers/netapp/dataontap/client/test_client_cmode.py index 1e5f40e960..337a9b88cd 100644 --- a/manila/tests/share/drivers/netapp/dataontap/client/test_client_cmode.py +++ b/manila/tests/share/drivers/netapp/dataontap/client/test_client_cmode.py @@ -17,9 +17,9 @@ import copy import hashlib import time +from unittest import mock import ddt -import mock from oslo_log import log import six diff --git a/manila/tests/share/drivers/netapp/dataontap/cluster_mode/test_data_motion.py b/manila/tests/share/drivers/netapp/dataontap/cluster_mode/test_data_motion.py index f5d4f2d0ed..872b4f6889 100644 --- a/manila/tests/share/drivers/netapp/dataontap/cluster_mode/test_data_motion.py +++ b/manila/tests/share/drivers/netapp/dataontap/cluster_mode/test_data_motion.py @@ -14,9 +14,9 @@ import copy import time +from unittest import mock import ddt -import mock from oslo_config import cfg from manila import exception diff --git a/manila/tests/share/drivers/netapp/dataontap/cluster_mode/test_driver_interfaces.py b/manila/tests/share/drivers/netapp/dataontap/cluster_mode/test_driver_interfaces.py index adaae7f579..f8a6cdea26 100644 --- a/manila/tests/share/drivers/netapp/dataontap/cluster_mode/test_driver_interfaces.py +++ b/manila/tests/share/drivers/netapp/dataontap/cluster_mode/test_driver_interfaces.py @@ -15,8 +15,7 @@ Mock unit tests for the NetApp file share driver interfaces """ - -import mock +from unittest import mock from manila.share.drivers.netapp.dataontap.cluster_mode import drv_multi_svm from manila.share.drivers.netapp.dataontap.cluster_mode import drv_single_svm diff --git a/manila/tests/share/drivers/netapp/dataontap/cluster_mode/test_lib_base.py b/manila/tests/share/drivers/netapp/dataontap/cluster_mode/test_lib_base.py index 6a64d41192..2ecba4b4df 100644 --- a/manila/tests/share/drivers/netapp/dataontap/cluster_mode/test_lib_base.py +++ b/manila/tests/share/drivers/netapp/dataontap/cluster_mode/test_lib_base.py @@ -21,9 +21,9 @@ import json import math import socket import time +from unittest import mock import ddt -import mock from oslo_log import log from oslo_service import loopingcall from oslo_utils import timeutils diff --git a/manila/tests/share/drivers/netapp/dataontap/cluster_mode/test_lib_multi_svm.py b/manila/tests/share/drivers/netapp/dataontap/cluster_mode/test_lib_multi_svm.py index bbb474adb5..ff3b54a68f 100644 --- a/manila/tests/share/drivers/netapp/dataontap/cluster_mode/test_lib_multi_svm.py +++ b/manila/tests/share/drivers/netapp/dataontap/cluster_mode/test_lib_multi_svm.py @@ -16,9 +16,9 @@ Unit tests for the NetApp Data ONTAP cDOT multi-SVM storage driver library. """ import copy +from unittest import mock import ddt -import mock from oslo_log import log from oslo_serialization import jsonutils diff --git a/manila/tests/share/drivers/netapp/dataontap/cluster_mode/test_lib_single_svm.py b/manila/tests/share/drivers/netapp/dataontap/cluster_mode/test_lib_single_svm.py index 8b641b8b4c..890791a780 100644 --- a/manila/tests/share/drivers/netapp/dataontap/cluster_mode/test_lib_single_svm.py +++ b/manila/tests/share/drivers/netapp/dataontap/cluster_mode/test_lib_single_svm.py @@ -15,8 +15,9 @@ Unit tests for the NetApp Data ONTAP cDOT single-SVM storage driver library. """ +from unittest import mock + import ddt -import mock from oslo_log import log from manila import exception diff --git a/manila/tests/share/drivers/netapp/dataontap/cluster_mode/test_performance.py b/manila/tests/share/drivers/netapp/dataontap/cluster_mode/test_performance.py index d746a3e110..906800039b 100644 --- a/manila/tests/share/drivers/netapp/dataontap/cluster_mode/test_performance.py +++ b/manila/tests/share/drivers/netapp/dataontap/cluster_mode/test_performance.py @@ -13,8 +13,9 @@ # License for the specific language governing permissions and limitations # under the License. +from unittest import mock + import ddt -import mock from manila import exception from manila.share.drivers.netapp.dataontap.client import api as netapp_api diff --git a/manila/tests/share/drivers/netapp/dataontap/protocols/test_cifs_cmode.py b/manila/tests/share/drivers/netapp/dataontap/protocols/test_cifs_cmode.py index ef18c4d688..87af7a716b 100644 --- a/manila/tests/share/drivers/netapp/dataontap/protocols/test_cifs_cmode.py +++ b/manila/tests/share/drivers/netapp/dataontap/protocols/test_cifs_cmode.py @@ -16,9 +16,9 @@ Mock unit tests for the NetApp driver protocols CIFS class module. """ import copy +from unittest import mock import ddt -import mock from manila.common import constants from manila import exception diff --git a/manila/tests/share/drivers/netapp/dataontap/protocols/test_nfs_cmode.py b/manila/tests/share/drivers/netapp/dataontap/protocols/test_nfs_cmode.py index 500b82aede..3ce0240fee 100644 --- a/manila/tests/share/drivers/netapp/dataontap/protocols/test_nfs_cmode.py +++ b/manila/tests/share/drivers/netapp/dataontap/protocols/test_nfs_cmode.py @@ -16,10 +16,10 @@ Mock unit tests for the NetApp driver protocols NFS class module. """ import copy +from unittest import mock import uuid import ddt -import mock from manila import exception from manila.share.drivers.netapp.dataontap.protocols import nfs_cmode diff --git a/manila/tests/share/drivers/netapp/test_common.py b/manila/tests/share/drivers/netapp/test_common.py index 8f9a4fc25f..c6630a3bd7 100644 --- a/manila/tests/share/drivers/netapp/test_common.py +++ b/manila/tests/share/drivers/netapp/test_common.py @@ -12,7 +12,8 @@ # License for the specific language governing permissions and limitations # under the License. -import mock +from unittest import mock + import six from manila import exception diff --git a/manila/tests/share/drivers/netapp/test_utils.py b/manila/tests/share/drivers/netapp/test_utils.py index 8be746d79b..90412a9871 100644 --- a/manila/tests/share/drivers/netapp/test_utils.py +++ b/manila/tests/share/drivers/netapp/test_utils.py @@ -17,9 +17,9 @@ Mock unit tests for the NetApp driver utility module """ import platform +from unittest import mock import ddt -import mock from oslo_concurrency import processutils as putils from oslo_log import log diff --git a/manila/tests/share/drivers/nexenta/ns4/test_jsonrpc.py b/manila/tests/share/drivers/nexenta/ns4/test_jsonrpc.py index 917824e136..be5907376c 100644 --- a/manila/tests/share/drivers/nexenta/ns4/test_jsonrpc.py +++ b/manila/tests/share/drivers/nexenta/ns4/test_jsonrpc.py @@ -13,7 +13,8 @@ # License for the specific language governing permissions and limitations # under the License. -from mock import patch +from unittest import mock + from oslo_serialization import jsonutils import requests @@ -24,7 +25,7 @@ from manila import test class TestNexentaJSONProxy(test.TestCase): - @patch('requests.post') + @mock.patch('requests.post') def test_call(self, post): nms_post = jsonrpc.NexentaJSONProxy( 'http', '1.1.1.1', '8080', 'user', 'pass', diff --git a/manila/tests/share/drivers/nexenta/ns4/test_nexenta_nas.py b/manila/tests/share/drivers/nexenta/ns4/test_nexenta_nas.py index 516dea5843..a37d72f5dd 100644 --- a/manila/tests/share/drivers/nexenta/ns4/test_nexenta_nas.py +++ b/manila/tests/share/drivers/nexenta/ns4/test_nexenta_nas.py @@ -15,9 +15,8 @@ import base64 import json -import mock -from mock import patch -from mock import PropertyMock +from unittest import mock + from oslo_serialization import jsonutils from oslo_utils import units @@ -28,7 +27,7 @@ from manila.share.drivers.nexenta.ns4 import nexenta_nas from manila import test PATH_TO_RPC = 'requests.post' -CODE = PropertyMock(return_value=200) +CODE = mock.PropertyMock(return_value=200) class FakeResponse(object): @@ -120,14 +119,14 @@ class TestNexentaNasDriver(test.TestCase): self.volume = self.cfg.nexenta_volume self.share = self.cfg.nexenta_nfs_share - @patch(PATH_TO_RPC) + @mock.patch(PATH_TO_RPC) def test_check_for_setup_error__volume_doesnt_exist(self, post): post.return_value = FakeResponse() self.assertRaises( exception.NexentaException, self.drv.check_for_setup_error) - @patch(PATH_TO_RPC) + @mock.patch(PATH_TO_RPC) def test_check_for_setup_error__folder_doesnt_exist(self, post): folder = '%s/%s' % (self.volume, self.share) create_folder_props = { @@ -177,7 +176,7 @@ class TestNexentaNasDriver(test.TestCase): 'folder', 'object_exists', folder), headers=self.request_params.headers) - @patch(PATH_TO_RPC) + @mock.patch(PATH_TO_RPC) def test_create_share(self, post): share = { 'name': 'share', @@ -192,7 +191,7 @@ class TestNexentaNasDriver(test.TestCase): self.assertEqual([location], self.drv.create_share(self.ctx, share)) - @patch(PATH_TO_RPC) + @mock.patch(PATH_TO_RPC) def test_create_share__wrong_proto(self, post): share = { 'name': 'share', @@ -204,7 +203,7 @@ class TestNexentaNasDriver(test.TestCase): self.assertRaises(exception.InvalidShare, self.drv.create_share, self.ctx, share) - @patch(PATH_TO_RPC) + @mock.patch(PATH_TO_RPC) def test_create_share__thin_provisioning(self, post): share = {'name': 'share', 'size': 1, 'share_proto': self.cfg.enabled_share_protocols} @@ -229,7 +228,7 @@ class TestNexentaNasDriver(test.TestCase): create_folder_props), headers=self.request_params.headers) - @patch(PATH_TO_RPC) + @mock.patch(PATH_TO_RPC) def test_create_share__thick_provisioning(self, post): share = { 'name': 'share', @@ -259,7 +258,7 @@ class TestNexentaNasDriver(test.TestCase): create_folder_props), headers=self.request_params.headers) - @patch(PATH_TO_RPC) + @mock.patch(PATH_TO_RPC) def test_create_share_from_snapshot(self, post): share = { 'name': 'share', @@ -284,7 +283,7 @@ class TestNexentaNasDriver(test.TestCase): '%s/%s/%s' % (self.volume, self.share, share['name'])), headers=self.request_params.headers) - @patch(PATH_TO_RPC) + @mock.patch(PATH_TO_RPC) def test_delete_share(self, post): share = { 'name': 'share', @@ -305,7 +304,7 @@ class TestNexentaNasDriver(test.TestCase): '-r'), headers=self.request_params.headers) - @patch(PATH_TO_RPC) + @mock.patch(PATH_TO_RPC) def test_delete_share__exists_error(self, post): share = { 'name': 'share', @@ -317,7 +316,7 @@ class TestNexentaNasDriver(test.TestCase): self.drv.delete_share(self.ctx, share) - @patch(PATH_TO_RPC) + @mock.patch(PATH_TO_RPC) def test_delete_share__some_error(self, post): share = { 'name': 'share', @@ -330,7 +329,7 @@ class TestNexentaNasDriver(test.TestCase): self.assertRaises( exception.ManilaException, self.drv.delete_share, self.ctx, share) - @patch(PATH_TO_RPC) + @mock.patch(PATH_TO_RPC) def test_extend_share__thin_provisoning(self, post): share = { 'name': 'share', @@ -353,7 +352,7 @@ class TestNexentaNasDriver(test.TestCase): 'quota', quota), headers=self.request_params.headers) - @patch(PATH_TO_RPC) + @mock.patch(PATH_TO_RPC) def test_extend_share__thick_provisoning(self, post): share = { 'name': 'share', @@ -368,7 +367,7 @@ class TestNexentaNasDriver(test.TestCase): post.assert_not_called() - @patch(PATH_TO_RPC) + @mock.patch(PATH_TO_RPC) def test_create_snapshot(self, post): snapshot = {'share_name': 'share', 'name': 'share@first'} post.return_value = FakeResponse() @@ -381,7 +380,7 @@ class TestNexentaNasDriver(test.TestCase): 'folder', 'create_snapshot', folder, snapshot['name'], '-r'), headers=self.request_params.headers) - @patch(PATH_TO_RPC) + @mock.patch(PATH_TO_RPC) def test_delete_snapshot(self, post): snapshot = {'share_name': 'share', 'name': 'share@first'} post.return_value = FakeResponse() @@ -396,7 +395,7 @@ class TestNexentaNasDriver(test.TestCase): ''), headers=self.request_params.headers) - @patch(PATH_TO_RPC) + @mock.patch(PATH_TO_RPC) def test_delete_snapshot__nexenta_error_1(self, post): snapshot = {'share_name': 'share', 'name': 'share@first'} post.return_value = FakeResponse() @@ -404,7 +403,7 @@ class TestNexentaNasDriver(test.TestCase): self.drv.delete_snapshot(self.ctx, snapshot) - @patch(PATH_TO_RPC) + @mock.patch(PATH_TO_RPC) def test_delete_snapshot__nexenta_error_2(self, post): snapshot = {'share_name': 'share', 'name': 'share@first'} post.return_value = FakeResponse() @@ -412,7 +411,7 @@ class TestNexentaNasDriver(test.TestCase): self.drv.delete_snapshot(self.ctx, snapshot) - @patch(PATH_TO_RPC) + @mock.patch(PATH_TO_RPC) def test_delete_snapshot__some_error(self, post): snapshot = {'share_name': 'share', 'name': 'share@first'} post.return_value = FakeResponse() @@ -421,7 +420,7 @@ class TestNexentaNasDriver(test.TestCase): self.assertRaises(exception.ManilaException, self.drv.delete_snapshot, self.ctx, snapshot) - @patch(PATH_TO_RPC) + @mock.patch(PATH_TO_RPC) def test_update_access__unsupported_access_type(self, post): share = { 'name': 'share', @@ -441,7 +440,7 @@ class TestNexentaNasDriver(test.TestCase): None, None) - @patch(PATH_TO_RPC) + @mock.patch(PATH_TO_RPC) def test_update_access__cidr(self, post): share = { 'name': 'share', @@ -497,7 +496,7 @@ class TestNexentaNasDriver(test.TestCase): 'access_level': 'rw'}], None, None) - @patch(PATH_TO_RPC) + @mock.patch(PATH_TO_RPC) def test_update_access__add_one_ip_to_empty_access_list(self, post): share = {'name': 'share', 'share_proto': self.cfg.enabled_share_protocols} @@ -551,7 +550,7 @@ class TestNexentaNasDriver(test.TestCase): 'access_level': 'rw'}], None, None) - @patch(PATH_TO_RPC) + @mock.patch(PATH_TO_RPC) def test_deny_access__unsupported_access_type(self, post): share = {'name': 'share', 'share_proto': self.cfg.enabled_share_protocols} @@ -567,7 +566,7 @@ class TestNexentaNasDriver(test.TestCase): def test_share_backend_name(self): self.assertEqual('NexentaStor', self.drv.share_backend_name) - @patch(PATH_TO_RPC) + @mock.patch(PATH_TO_RPC) def test_get_capacity_info(self, post): post.return_value = FakeResponse({'result': { 'available': 9 * units.Gi, 'used': 1 * units.Gi}}) @@ -575,9 +574,9 @@ class TestNexentaNasDriver(test.TestCase): self.assertEqual( (10, 9, 1), self.drv.helper._get_capacity_info()) - @patch('manila.share.drivers.nexenta.ns4.nexenta_nfs_helper.NFSHelper.' - '_get_capacity_info') - @patch('manila.share.driver.ShareDriver._update_share_stats') + @mock.patch('manila.share.drivers.nexenta.ns4.nexenta_nfs_helper.' + 'NFSHelper._get_capacity_info') + @mock.patch('manila.share.driver.ShareDriver._update_share_stats') def test_update_share_stats(self, super_stats, info): info.return_value = (100, 90, 10) stats = { diff --git a/manila/tests/share/drivers/nexenta/ns5/test_jsonrpc.py b/manila/tests/share/drivers/nexenta/ns5/test_jsonrpc.py index 01cdfee93a..ce4f14d077 100644 --- a/manila/tests/share/drivers/nexenta/ns5/test_jsonrpc.py +++ b/manila/tests/share/drivers/nexenta/ns5/test_jsonrpc.py @@ -20,9 +20,9 @@ import copy import hashlib import json import posixpath +from unittest import mock import uuid -import mock import requests import six diff --git a/manila/tests/share/drivers/nexenta/ns5/test_nexenta_nas.py b/manila/tests/share/drivers/nexenta/ns5/test_nexenta_nas.py index 6c8a49aae5..0bce1400d9 100644 --- a/manila/tests/share/drivers/nexenta/ns5/test_nexenta_nas.py +++ b/manila/tests/share/drivers/nexenta/ns5/test_nexenta_nas.py @@ -13,9 +13,9 @@ # License for the specific language governing permissions and limitations # under the License. +from unittest import mock + import ddt -import mock -from mock import patch from oslo_utils import units from manila import context @@ -174,7 +174,7 @@ class TestNexentaNasDriver(test.TestCase): self.assertRaises(jsonrpc.NefException, self.drv.check_for_setup_error) - @patch('%s.NefFilesystems.get' % RPC_PATH) + @mock.patch('%s.NefFilesystems.get' % RPC_PATH) def test__get_provisioned_capacity(self, fs_get): fs_get.return_value = { 'path': 'pool1/nfs_share/123', @@ -185,9 +185,9 @@ class TestNexentaNasDriver(test.TestCase): self.assertEqual(1 * units.Gi, self.drv.provisioned_capacity) - @patch('%s._mount_filesystem' % DRV_PATH) - @patch('%s.NefFilesystems.create' % RPC_PATH) - @patch('%s.NefFilesystems.delete' % RPC_PATH) + @mock.patch('%s._mount_filesystem' % DRV_PATH) + @mock.patch('%s.NefFilesystems.create' % RPC_PATH) + @mock.patch('%s.NefFilesystems.delete' % RPC_PATH) def test_create_share(self, delete_fs, create_fs, mount_fs): mount_path = '%s:/%s' % (self.cfg.nexenta_nas_host, SHARE_PATH) mount_fs.return_value = mount_path @@ -216,10 +216,10 @@ class TestNexentaNasDriver(test.TestCase): self.drv.nef.filesystems.delete.assert_called_with( SHARE_PATH, delete_payload) - @patch('%s.NefFilesystems.promote' % RPC_PATH) - @patch('%s.NefSnapshots.get' % RPC_PATH) - @patch('%s.NefSnapshots.list' % RPC_PATH) - @patch('%s.NefFilesystems.delete' % RPC_PATH) + @mock.patch('%s.NefFilesystems.promote' % RPC_PATH) + @mock.patch('%s.NefSnapshots.get' % RPC_PATH) + @mock.patch('%s.NefSnapshots.list' % RPC_PATH) + @mock.patch('%s.NefFilesystems.delete' % RPC_PATH) def test_delete_share(self, fs_delete, snap_list, snap_get, fs_promote): delete_payload = {'force': True, 'snapshots': True} snapshots_payload = {'parent': SHARE_PATH, 'fields': 'path'} @@ -238,8 +238,8 @@ class TestNexentaNasDriver(test.TestCase): snap_get.assert_called_with('%s@snap1' % SHARE_PATH, clones_payload) snap_list.assert_called_with(snapshots_payload) - @patch('%s.NefFilesystems.mount' % RPC_PATH) - @patch('%s.NefFilesystems.get' % RPC_PATH) + @mock.patch('%s.NefFilesystems.mount' % RPC_PATH) + @mock.patch('%s.NefFilesystems.get' % RPC_PATH) def test_mount_filesystem(self, fs_get, fs_mount): mount_path = '%s:/%s' % (self.cfg.nexenta_nas_host, SHARE_PATH) fs_get.return_value = { @@ -247,9 +247,9 @@ class TestNexentaNasDriver(test.TestCase): self.assertEqual(mount_path, self.drv._mount_filesystem(SHARE)) self.drv.nef.filesystems.mount.assert_called_with(SHARE_PATH) - @patch('%s.NefHpr.activate' % RPC_PATH) - @patch('%s.NefFilesystems.mount' % RPC_PATH) - @patch('%s.NefFilesystems.get' % RPC_PATH) + @mock.patch('%s.NefHpr.activate' % RPC_PATH) + @mock.patch('%s.NefFilesystems.mount' % RPC_PATH) + @mock.patch('%s.NefFilesystems.get' % RPC_PATH) def test_mount_filesystem_with_activate( self, fs_get, fs_mount, hpr_activate): mount_path = '%s:/%s' % (self.cfg.nexenta_nas_host, SHARE_PATH) @@ -260,8 +260,8 @@ class TestNexentaNasDriver(test.TestCase): payload = {'datasetName': SHARE_PATH} self.drv.nef.hpr.activate.assert_called_once_with(payload) - @patch('%s.NefFilesystems.mount' % RPC_PATH) - @patch('%s.NefFilesystems.unmount' % RPC_PATH) + @mock.patch('%s.NefFilesystems.mount' % RPC_PATH) + @mock.patch('%s.NefFilesystems.unmount' % RPC_PATH) def test_remount_filesystem(self, fs_unmount, fs_mount): self.drv._remount_filesystem(SHARE_PATH) fs_unmount.assert_called_once_with(SHARE_PATH) @@ -277,9 +277,9 @@ class TestNexentaNasDriver(test.TestCase): return ls @ddt.data({'key': 'value'}, {}) - @patch('%s.NefNfs.list' % RPC_PATH) - @patch('%s.NefNfs.set' % RPC_PATH) - @patch('%s.NefFilesystems.acl' % RPC_PATH) + @mock.patch('%s.NefNfs.list' % RPC_PATH) + @mock.patch('%s.NefNfs.set' % RPC_PATH) + @mock.patch('%s.NefFilesystems.acl' % RPC_PATH) def test_update_nfs_access(self, acl, nfs_set, nfs_list, list_data): security_contexts = {'securityModes': ['sys']} nfs_list.return_value = list_data @@ -327,7 +327,7 @@ class TestNexentaNasDriver(test.TestCase): self.assertRaises(ValueError, self.drv._update_nfs_access, SHARE, rw_list, ro_list) - @patch('%s._update_nfs_access' % DRV_PATH) + @mock.patch('%s._update_nfs_access' % DRV_PATH) def test_update_access__ip_rw(self, update_nfs_access): access = { 'access_type': 'ip', @@ -342,7 +342,7 @@ class TestNexentaNasDriver(test.TestCase): self.ctx, SHARE, [access], None, None)) self.drv._update_nfs_access.assert_called_with(SHARE, ['1.1.1.1'], []) - @patch('%s._update_nfs_access' % DRV_PATH) + @mock.patch('%s._update_nfs_access' % DRV_PATH) def test_update_access__ip_ro(self, update_nfs_access): access = { 'access_type': 'ip', @@ -369,8 +369,8 @@ class TestNexentaNasDriver(test.TestCase): self.assertEqual(expected, self.drv.update_access( self.ctx, SHARE, [access], None, None)) - @patch('%s._get_capacity_info' % DRV_PATH) - @patch('manila.share.driver.ShareDriver._update_share_stats') + @mock.patch('%s._get_capacity_info' % DRV_PATH) + @mock.patch('manila.share.driver.ShareDriver._update_share_stats') def test_update_share_stats(self, super_stats, info): info.return_value = (100, 90, 10) stats = { @@ -405,10 +405,10 @@ class TestNexentaNasDriver(test.TestCase): self.assertEqual((10, 9, 1), self.drv._get_capacity_info()) - @patch('%s._set_reservation' % DRV_PATH) - @patch('%s._set_quota' % DRV_PATH) - @patch('%s.NefFilesystems.rename' % RPC_PATH) - @patch('%s.NefFilesystems.get' % RPC_PATH) + @mock.patch('%s._set_reservation' % DRV_PATH) + @mock.patch('%s._set_quota' % DRV_PATH) + @mock.patch('%s.NefFilesystems.rename' % RPC_PATH) + @mock.patch('%s.NefFilesystems.get' % RPC_PATH) def test_manage_existing(self, fs_get, fs_rename, set_res, set_quota): fs_get.return_value = {'referencedQuotaSize': 1073741824} old_path = '%s:/%s' % (self.cfg.nexenta_nas_host, 'path_to_fs') @@ -422,23 +422,23 @@ class TestNexentaNasDriver(test.TestCase): set_res.assert_called_with(SHARE, 2) set_quota.assert_called_with(SHARE, 2) - @patch('%s.NefSnapshots.create' % RPC_PATH) + @mock.patch('%s.NefSnapshots.create' % RPC_PATH) def test_create_snapshot(self, snap_create): self.assertIsNone(self.drv.create_snapshot(self.ctx, SNAPSHOT)) snap_create.assert_called_once_with({ 'path': SNAPSHOT['snapshot_path']}) - @patch('%s.NefSnapshots.delete' % RPC_PATH) + @mock.patch('%s.NefSnapshots.delete' % RPC_PATH) def test_delete_snapshot(self, snap_delete): self.assertIsNone(self.drv.delete_snapshot(self.ctx, SNAPSHOT)) payload = {'defer': True} snap_delete.assert_called_once_with( SNAPSHOT['snapshot_path'], payload) - @patch('%s._mount_filesystem' % DRV_PATH) - @patch('%s._remount_filesystem' % DRV_PATH) - @patch('%s.NefFilesystems.delete' % RPC_PATH) - @patch('%s.NefSnapshots.clone' % RPC_PATH) + @mock.patch('%s._mount_filesystem' % DRV_PATH) + @mock.patch('%s._remount_filesystem' % DRV_PATH) + @mock.patch('%s.NefFilesystems.delete' % RPC_PATH) + @mock.patch('%s.NefSnapshots.clone' % RPC_PATH) def test_create_share_from_snapshot( self, snap_clone, fs_delete, remount_fs, mount_fs): mount_fs.return_value = 'mount_path' @@ -460,10 +460,10 @@ class TestNexentaNasDriver(test.TestCase): } snap_clone.assert_called_once_with(SNAPSHOT['snapshot_path'], payload) - @patch('%s._mount_filesystem' % DRV_PATH) - @patch('%s._remount_filesystem' % DRV_PATH) - @patch('%s.NefFilesystems.delete' % RPC_PATH) - @patch('%s.NefSnapshots.clone' % RPC_PATH) + @mock.patch('%s._mount_filesystem' % DRV_PATH) + @mock.patch('%s._remount_filesystem' % DRV_PATH) + @mock.patch('%s.NefFilesystems.delete' % RPC_PATH) + @mock.patch('%s.NefSnapshots.clone' % RPC_PATH) def test_create_share_from_snapshot_error( self, snap_clone, fs_delete, remount_fs, mount_fs): fs_delete.side_effect = jsonrpc.NefException('delete error') @@ -485,7 +485,7 @@ class TestNexentaNasDriver(test.TestCase): payload = {'force': True} fs_delete.assert_called_once_with(SHARE2_PATH, payload) - @patch('%s.NefFilesystems.rollback' % RPC_PATH) + @mock.patch('%s.NefFilesystems.rollback' % RPC_PATH) def test_revert_to_snapshot(self, fs_rollback): self.assertIsNone(self.drv.revert_to_snapshot( self.ctx, SNAPSHOT, [], [])) @@ -493,8 +493,8 @@ class TestNexentaNasDriver(test.TestCase): fs_rollback.assert_called_once_with( SHARE_PATH, payload) - @patch('%s._set_reservation' % DRV_PATH) - @patch('%s._set_quota' % DRV_PATH) + @mock.patch('%s._set_reservation' % DRV_PATH) + @mock.patch('%s._set_quota' % DRV_PATH) def test_extend_share(self, set_quota, set_reservation): self.assertIsNone(self.drv.extend_share( SHARE, 2)) @@ -503,9 +503,9 @@ class TestNexentaNasDriver(test.TestCase): set_reservation.assert_called_once_with( SHARE, 2) - @patch('%s.NefFilesystems.get' % RPC_PATH) - @patch('%s._set_reservation' % DRV_PATH) - @patch('%s._set_quota' % DRV_PATH) + @mock.patch('%s.NefFilesystems.get' % RPC_PATH) + @mock.patch('%s._set_reservation' % DRV_PATH) + @mock.patch('%s._set_quota' % DRV_PATH) def test_shrink_share(self, set_quota, set_reservation, fs_get): fs_get.return_value = { 'bytesUsedBySelf': 0.5 * units.Gi @@ -517,7 +517,7 @@ class TestNexentaNasDriver(test.TestCase): set_reservation.assert_called_once_with( SHARE2, 1) - @patch('%s.NefFilesystems.set' % RPC_PATH) + @mock.patch('%s.NefFilesystems.set' % RPC_PATH) def test_set_quota(self, fs_set): quota = int(2 * units.Gi * 1.1) payload = {'referencedQuotaSize': quota} @@ -525,7 +525,7 @@ class TestNexentaNasDriver(test.TestCase): SHARE, 2)) fs_set.assert_called_once_with(SHARE_PATH, payload) - @patch('%s.NefFilesystems.set' % RPC_PATH) + @mock.patch('%s.NefFilesystems.set' % RPC_PATH) def test_set_reservation(self, fs_set): reservation = int(2 * units.Gi * 1.1) payload = {'referencedReservationSize': reservation} diff --git a/manila/tests/share/drivers/qnap/test_api.py b/manila/tests/share/drivers/qnap/test_api.py index 3eea241ae8..6988a02788 100644 --- a/manila/tests/share/drivers/qnap/test_api.py +++ b/manila/tests/share/drivers/qnap/test_api.py @@ -14,12 +14,12 @@ # under the License. import base64 +import time +from unittest import mock import ddt -import mock import six from six.moves import urllib -import time from manila import exception from manila.share.drivers.qnap import qnap diff --git a/manila/tests/share/drivers/qnap/test_qnap.py b/manila/tests/share/drivers/qnap/test_qnap.py index d059e36a49..9258597665 100644 --- a/manila/tests/share/drivers/qnap/test_qnap.py +++ b/manila/tests/share/drivers/qnap/test_qnap.py @@ -13,6 +13,8 @@ # License for the specific language governing permissions and limitations # under the License. +import time +from unittest import mock try: import xml.etree.cElementTree as ET @@ -20,12 +22,10 @@ except ImportError: import xml.etree.ElementTree as ET import ddt -import mock +from eventlet import greenthread from oslo_config import cfg import six -import time -from eventlet import greenthread from manila import exception from manila.share.drivers.qnap import api from manila.share.drivers.qnap import qnap diff --git a/manila/tests/share/drivers/quobyte/test_jsonrpc.py b/manila/tests/share/drivers/quobyte/test_jsonrpc.py index 3e869e5df5..5a87581f7a 100644 --- a/manila/tests/share/drivers/quobyte/test_jsonrpc.py +++ b/manila/tests/share/drivers/quobyte/test_jsonrpc.py @@ -13,13 +13,13 @@ # License for the specific language governing permissions and limitations # under the License. +import tempfile +import time +from unittest import mock + import requests from requests import auth from requests import exceptions -import tempfile -import time - -import mock import six from manila import exception diff --git a/manila/tests/share/drivers/quobyte/test_quobyte.py b/manila/tests/share/drivers/quobyte/test_quobyte.py index 12350bfc88..76b75de57a 100644 --- a/manila/tests/share/drivers/quobyte/test_quobyte.py +++ b/manila/tests/share/drivers/quobyte/test_quobyte.py @@ -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 oslo_utils import units import six diff --git a/manila/tests/share/drivers/tegile/test_tegile.py b/manila/tests/share/drivers/tegile/test_tegile.py index 34a545d6e5..217c4c19ae 100644 --- a/manila/tests/share/drivers/tegile/test_tegile.py +++ b/manila/tests/share/drivers/tegile/test_tegile.py @@ -16,8 +16,9 @@ Share driver Test for Tegile storage. """ +from unittest import mock + import ddt -import mock from oslo_config import cfg import requests import six diff --git a/manila/tests/share/drivers/test_ganesha.py b/manila/tests/share/drivers/test_ganesha.py index 8ac14a311f..39b49807c6 100644 --- a/manila/tests/share/drivers/test_ganesha.py +++ b/manila/tests/share/drivers/test_ganesha.py @@ -16,9 +16,9 @@ import copy import errno import os +from unittest import mock import ddt -import mock from oslo_config import cfg from manila import context diff --git a/manila/tests/share/drivers/test_generic.py b/manila/tests/share/drivers/test_generic.py index a3f3856153..139a77eb0b 100644 --- a/manila/tests/share/drivers/test_generic.py +++ b/manila/tests/share/drivers/test_generic.py @@ -18,9 +18,9 @@ import os import time +from unittest import mock import ddt -import mock from oslo_concurrency import processutils from oslo_config import cfg from six import moves diff --git a/manila/tests/share/drivers/test_glusterfs.py b/manila/tests/share/drivers/test_glusterfs.py index 44438747f5..dcabde3a61 100644 --- a/manila/tests/share/drivers/test_glusterfs.py +++ b/manila/tests/share/drivers/test_glusterfs.py @@ -15,9 +15,9 @@ import copy import socket +from unittest import mock import ddt -import mock from oslo_config import cfg from manila import context diff --git a/manila/tests/share/drivers/test_helpers.py b/manila/tests/share/drivers/test_helpers.py index 9894cf4834..c7f6ad6c12 100644 --- a/manila/tests/share/drivers/test_helpers.py +++ b/manila/tests/share/drivers/test_helpers.py @@ -14,9 +14,9 @@ # under the License. import os +from unittest import mock import ddt -import mock from oslo_config import cfg from manila.common import constants as const diff --git a/manila/tests/share/drivers/test_lvm.py b/manila/tests/share/drivers/test_lvm.py index 99573b94f8..f36d235db4 100644 --- a/manila/tests/share/drivers/test_lvm.py +++ b/manila/tests/share/drivers/test_lvm.py @@ -15,9 +15,9 @@ """Unit tests for the LVM driver module.""" import os +from unittest import mock import ddt -import mock from oslo_concurrency import processutils from oslo_config import cfg from oslo_utils import timeutils diff --git a/manila/tests/share/drivers/test_service_instance.py b/manila/tests/share/drivers/test_service_instance.py index 10426316c5..2220ccbb17 100644 --- a/manila/tests/share/drivers/test_service_instance.py +++ b/manila/tests/share/drivers/test_service_instance.py @@ -18,9 +18,9 @@ import os import time +from unittest import mock import ddt -import mock import netaddr from oslo_config import cfg from oslo_utils import importutils diff --git a/manila/tests/share/drivers/veritas/test_veritas_isa.py b/manila/tests/share/drivers/veritas/test_veritas_isa.py index dd589b3dbf..8522805544 100644 --- a/manila/tests/share/drivers/veritas/test_veritas_isa.py +++ b/manila/tests/share/drivers/veritas/test_veritas_isa.py @@ -16,8 +16,8 @@ Unit tests for Veritas Manila driver. """ import hashlib import json +from unittest import mock -import mock from oslo_config import cfg import requests import six diff --git a/manila/tests/share/drivers/windows/test_service_instance.py b/manila/tests/share/drivers/windows/test_service_instance.py index 17113c5044..e820463248 100644 --- a/manila/tests/share/drivers/windows/test_service_instance.py +++ b/manila/tests/share/drivers/windows/test_service_instance.py @@ -14,9 +14,9 @@ # under the License. import os +from unittest import mock import ddt -import mock from oslo_concurrency import processutils from oslo_config import cfg import six diff --git a/manila/tests/share/drivers/windows/test_windows_smb_driver.py b/manila/tests/share/drivers/windows/test_windows_smb_driver.py index 906dc197ce..986cca2241 100644 --- a/manila/tests/share/drivers/windows/test_windows_smb_driver.py +++ b/manila/tests/share/drivers/windows/test_windows_smb_driver.py @@ -13,10 +13,10 @@ # License for the specific language governing permissions and limitations # under the License. -import ddt -import mock - import os +from unittest import mock + +import ddt from manila.share import configuration from manila.share.drivers import generic diff --git a/manila/tests/share/drivers/windows/test_windows_smb_helper.py b/manila/tests/share/drivers/windows/test_windows_smb_helper.py index c13d737081..87a005352b 100644 --- a/manila/tests/share/drivers/windows/test_windows_smb_helper.py +++ b/manila/tests/share/drivers/windows/test_windows_smb_helper.py @@ -14,9 +14,9 @@ # under the License. import os +from unittest import mock import ddt -import mock from manila.common import constants from manila import exception diff --git a/manila/tests/share/drivers/windows/test_windows_utils.py b/manila/tests/share/drivers/windows/test_windows_utils.py index c7fd206ef5..f88d7a873b 100644 --- a/manila/tests/share/drivers/windows/test_windows_utils.py +++ b/manila/tests/share/drivers/windows/test_windows_utils.py @@ -13,8 +13,9 @@ # License for the specific language governing permissions and limitations # under the License. +from unittest import mock + import ddt -import mock from manila.share.drivers.windows import windows_utils from manila import test diff --git a/manila/tests/share/drivers/windows/test_winrm_helper.py b/manila/tests/share/drivers/windows/test_winrm_helper.py index 7fbdf89a41..3975c56feb 100644 --- a/manila/tests/share/drivers/windows/test_winrm_helper.py +++ b/manila/tests/share/drivers/windows/test_winrm_helper.py @@ -13,8 +13,9 @@ # License for the specific language governing permissions and limitations # under the License. +from unittest import mock + import ddt -import mock from oslo_concurrency import processutils from oslo_utils import importutils from oslo_utils import strutils diff --git a/manila/tests/share/drivers/zfsonlinux/test_driver.py b/manila/tests/share/drivers/zfsonlinux/test_driver.py index 8c756969b1..51a4066941 100644 --- a/manila/tests/share/drivers/zfsonlinux/test_driver.py +++ b/manila/tests/share/drivers/zfsonlinux/test_driver.py @@ -13,9 +13,9 @@ # License for the specific language governing permissions and limitations # under the License. -import ddt -import mock +from unittest import mock +import ddt from oslo_config import cfg from manila import context diff --git a/manila/tests/share/drivers/zfsonlinux/test_utils.py b/manila/tests/share/drivers/zfsonlinux/test_utils.py index 2380546cfa..47e7acba10 100644 --- a/manila/tests/share/drivers/zfsonlinux/test_utils.py +++ b/manila/tests/share/drivers/zfsonlinux/test_utils.py @@ -14,9 +14,9 @@ # under the License. import time +from unittest import mock import ddt -import mock from oslo_config import cfg from manila import exception diff --git a/manila/tests/share/drivers/zfssa/test_zfssarest.py b/manila/tests/share/drivers/zfssa/test_zfssarest.py index 3d6b5ba1a3..92adad5a2c 100644 --- a/manila/tests/share/drivers/zfssa/test_zfssarest.py +++ b/manila/tests/share/drivers/zfssa/test_zfssarest.py @@ -14,7 +14,7 @@ """ Unit tests for Oracle's ZFSSA REST API. """ -import mock +from unittest import mock from manila import exception from manila.share.drivers.zfssa import restclient diff --git a/manila/tests/share/drivers/zfssa/test_zfssashare.py b/manila/tests/share/drivers/zfssa/test_zfssashare.py index 54b33bbdcd..85763f2c9e 100644 --- a/manila/tests/share/drivers/zfssa/test_zfssashare.py +++ b/manila/tests/share/drivers/zfssa/test_zfssashare.py @@ -14,7 +14,8 @@ """ Unit tests for Oracle's ZFSSA Manila driver. """ -import mock +from unittest import mock + from oslo_config import cfg from oslo_utils import units diff --git a/manila/tests/share/test_access.py b/manila/tests/share/test_access.py index bb24e7c9ed..a689323555 100644 --- a/manila/tests/share/test_access.py +++ b/manila/tests/share/test_access.py @@ -13,11 +13,11 @@ # License for the specific language governing permissions and limitations # under the License. -import ddt -import mock -import random - import itertools +import random +from unittest import mock + +import ddt import six from manila.common import constants diff --git a/manila/tests/share/test_api.py b/manila/tests/share/test_api.py index b2cb424c37..e86beb3538 100644 --- a/manila/tests/share/test_api.py +++ b/manila/tests/share/test_api.py @@ -16,9 +16,10 @@ import copy import datetime +from unittest import mock + import ddt -import mock from oslo_config import cfg from oslo_utils import timeutils from oslo_utils import uuidutils diff --git a/manila/tests/share/test_driver.py b/manila/tests/share/test_driver.py index c5c0674bb0..4f25321be6 100644 --- a/manila/tests/share/test_driver.py +++ b/manila/tests/share/test_driver.py @@ -16,10 +16,10 @@ """Unit tests for the Share driver module.""" import time +from unittest import mock + import ddt -import mock -from mock import PropertyMock from manila.common import constants from manila import exception @@ -1210,7 +1210,7 @@ class ShareDriverTestCase(test.TestCase): share_driver = self._instantiate_share_driver(None, True) self.mock_object(share_driver, 'get_configured_ip_versions', mock.Mock(return_value=conf)) - versions = PropertyMock(return_value=user_networks) + versions = mock.PropertyMock(return_value=user_networks) type(share_driver.network_api).enabled_ip_versions = versions data = {'share_backend_name': 'fake_backend'} diff --git a/manila/tests/share/test_drivers_private_data.py b/manila/tests/share/test_drivers_private_data.py index 0c74bf23d0..16fcc369be 100644 --- a/manila/tests/share/test_drivers_private_data.py +++ b/manila/tests/share/test_drivers_private_data.py @@ -13,8 +13,9 @@ # License for the specific language governing permissions and limitations # under the License. +from unittest import mock + import ddt -import mock from oslo_utils import uuidutils from manila.share import drivers_private_data as pd diff --git a/manila/tests/share/test_hook.py b/manila/tests/share/test_hook.py index d136f63cfa..e1c64b7552 100644 --- a/manila/tests/share/test_hook.py +++ b/manila/tests/share/test_hook.py @@ -13,8 +13,9 @@ # License for the specific language governing permissions and limitations # under the License. +from unittest import mock + import ddt -import mock from manila import context from manila.share import hook diff --git a/manila/tests/share/test_manager.py b/manila/tests/share/test_manager.py index 34fff2efb7..ccb973d4bf 100644 --- a/manila/tests/share/test_manager.py +++ b/manila/tests/share/test_manager.py @@ -17,9 +17,9 @@ import datetime import hashlib import random +from unittest import mock import ddt -import mock from oslo_concurrency import lockutils from oslo_serialization import jsonutils from oslo_utils import importutils @@ -109,8 +109,8 @@ class ShareManagerTestCase(test.TestCase): def test_share_manager_instance(self): fake_service_name = "fake_service" - import_mock = mock.Mock() - self.mock_object(importutils, "import_object", import_mock) + importutils_mock = mock.Mock() + self.mock_object(importutils, "import_object", importutils_mock) private_data_mock = mock.Mock() self.mock_object(drivers_private_data, "DriverPrivateData", private_data_mock) @@ -123,26 +123,26 @@ class ShareManagerTestCase(test.TestCase): backend_host=share_manager.host, config_group=fake_service_name ) - self.assertTrue(import_mock.called) + self.assertTrue(importutils_mock.called) self.assertTrue(manager.ShareManager._init_hook_drivers.called) def test__init_hook_drivers(self): fake_service_name = "fake_service" - import_mock = mock.Mock() - self.mock_object(importutils, "import_object", import_mock) + importutils_mock = mock.Mock() + self.mock_object(importutils, "import_object", importutils_mock) self.mock_object(drivers_private_data, "DriverPrivateData") share_manager = manager.ShareManager(service_name=fake_service_name) share_manager.configuration.safe_get = mock.Mock( return_value=["Foo", "Bar"]) self.assertEqual(0, len(share_manager.hooks)) - import_mock.reset() + importutils_mock.reset() share_manager._init_hook_drivers() self.assertEqual( len(share_manager.configuration.safe_get.return_value), len(share_manager.hooks)) - import_mock.assert_has_calls([ + importutils_mock.assert_has_calls([ mock.call( hook, configuration=share_manager.configuration, @@ -1773,7 +1773,9 @@ class ShareManagerTestCase(test.TestCase): elif retval: self.assertEqual(0, mock_warning_log.call_count) self.assertTrue(mock_driver_call.called) + # pylint: disable=unsubscriptable-object snapshot_list_arg = mock_driver_call.call_args[0][4] + # pylint: enable=unsubscriptable-object self.assertIn('active_replica_snapshot', snapshot_list_arg[0]) self.assertIn('share_replica_snapshot', snapshot_list_arg[0]) mock_db_update_call.assert_has_calls(mock_db_update_calls) diff --git a/manila/tests/share/test_migration.py b/manila/tests/share/test_migration.py index 8caa93f980..a5269c919c 100644 --- a/manila/tests/share/test_migration.py +++ b/manila/tests/share/test_migration.py @@ -13,10 +13,10 @@ # License for the specific language governing permissions and limitations # under the License. -import ddt -import mock - import time +from unittest import mock + +import ddt from manila.common import constants from manila import context diff --git a/manila/tests/share/test_share_types.py b/manila/tests/share/test_share_types.py index d8d6b13b9c..c426d8994c 100644 --- a/manila/tests/share/test_share_types.py +++ b/manila/tests/share/test_share_types.py @@ -19,9 +19,10 @@ import copy import datetime import itertools +from unittest import mock + import ddt -import mock from oslo_utils import strutils from manila.common import constants diff --git a/manila/tests/share/test_share_utils.py b/manila/tests/share/test_share_utils.py index cc7f89d2be..59bc161362 100644 --- a/manila/tests/share/test_share_utils.py +++ b/manila/tests/share/test_share_utils.py @@ -16,8 +16,9 @@ """Tests For miscellaneous util methods used with share.""" +from unittest import mock + import ddt -import mock from manila.common import constants from manila.share import utils as share_utils diff --git a/manila/tests/share/test_snapshot_access.py b/manila/tests/share/test_snapshot_access.py index fe3c354a94..06f84fd3c3 100644 --- a/manila/tests/share/test_snapshot_access.py +++ b/manila/tests/share/test_snapshot_access.py @@ -14,8 +14,9 @@ # under the License. import copy +from unittest import mock + import ddt -import mock from manila.common import constants from manila import context diff --git a/manila/tests/share_group/test_api.py b/manila/tests/share_group/test_api.py index 1557e39033..4773a30c47 100644 --- a/manila/tests/share_group/test_api.py +++ b/manila/tests/share_group/test_api.py @@ -16,9 +16,9 @@ import copy import datetime +from unittest import mock import ddt -import mock from oslo_config import cfg from oslo_utils import timeutils @@ -27,7 +27,7 @@ from manila import context from manila import db as db_driver from manila import exception from manila.share import share_types -import manila.share_group.api as share_group_api +from manila.share_group import api as share_group_api from manila import test from manila.tests.api.contrib import stubs from manila.tests import utils as test_utils diff --git a/manila/tests/share_group/test_share_group_types.py b/manila/tests/share_group/test_share_group_types.py index 9915a638f6..fbdec420f1 100644 --- a/manila/tests/share_group/test_share_group_types.py +++ b/manila/tests/share_group/test_share_group_types.py @@ -14,9 +14,9 @@ """Test of Share Type methods for Manila.""" import copy import datetime +from unittest import mock import ddt -import mock from manila.common import constants from manila import context diff --git a/manila/tests/test_coordination.py b/manila/tests/test_coordination.py index 359264703b..843528711a 100644 --- a/manila/tests/test_coordination.py +++ b/manila/tests/test_coordination.py @@ -13,8 +13,9 @@ # License for the specific language governing permissions and limitations # under the License. +from unittest import mock + import ddt -import mock from tooz import coordination as tooz_coordination from tooz import locking as tooz_locking diff --git a/manila/tests/test_hacking.py b/manila/tests/test_hacking.py index 8bc5389d6e..0bc0690dff 100644 --- a/manila/tests/test_hacking.py +++ b/manila/tests/test_hacking.py @@ -15,9 +15,9 @@ import itertools import sys import textwrap +from unittest import mock import ddt -import mock import pycodestyle from manila.hacking import checks @@ -327,6 +327,16 @@ class HackingTestCase(test.TestCase): """ self._assert_has_no_errors(code, checks.check_uuid4) + @ddt.unpack + @ddt.data( + (1, 'import mock'), + (0, 'from unittest import mock'), + (1, 'from mock import patch'), + (0, 'from unittest.mock import patch')) + def test_no_third_party_mock(self, err_count, line): + self.assertEqual(err_count, + len(list(checks.no_third_party_mock(line)))) + def test_no_log_warn_check(self): self.assertEqual(0, len(list(checks.no_log_warn_check( "LOG.warning('This should not trigger LOG.warn " diff --git a/manila/tests/test_manager.py b/manila/tests/test_manager.py index 78a904c03c..422088ee1a 100644 --- a/manila/tests/test_manager.py +++ b/manila/tests/test_manager.py @@ -15,8 +15,9 @@ """Test of Base Manager for Manila.""" +from unittest import mock + import ddt -import mock from oslo_utils import importutils from manila import manager diff --git a/manila/tests/test_quota.py b/manila/tests/test_quota.py index c2918facdf..d2874c5237 100644 --- a/manila/tests/test_quota.py +++ b/manila/tests/test_quota.py @@ -13,8 +13,9 @@ # License for the specific language governing permissions and limitations # under the License. +from unittest import mock + import ddt -import mock from oslo_config import cfg from manila import exception diff --git a/manila/tests/test_rpc.py b/manila/tests/test_rpc.py index 1f3b3ea612..283b7e35b3 100644 --- a/manila/tests/test_rpc.py +++ b/manila/tests/test_rpc.py @@ -11,8 +11,9 @@ # License for the specific language governing permissions and limitations # under the License. +from unittest import mock + import ddt -import mock from manila import rpc from manila import test diff --git a/manila/tests/test_service.py b/manila/tests/test_service.py index 79952b75d6..a542926883 100644 --- a/manila/tests/test_service.py +++ b/manila/tests/test_service.py @@ -21,8 +21,9 @@ Unit Tests for remote procedure calls using queue """ +from unittest import mock + import ddt -import mock from oslo_config import cfg from oslo_service import wsgi diff --git a/manila/tests/test_utils.py b/manila/tests/test_utils.py index ec8f8580e9..11b3c91797 100644 --- a/manila/tests/test_utils.py +++ b/manila/tests/test_utils.py @@ -17,9 +17,9 @@ import datetime import json import time +from unittest import mock import ddt -import mock from oslo_config import cfg from oslo_utils import timeutils from oslo_utils import uuidutils diff --git a/manila/tests/volume/test_cinder.py b/manila/tests/volume/test_cinder.py index f4de6fe17e..89c3dec2e5 100644 --- a/manila/tests/volume/test_cinder.py +++ b/manila/tests/volume/test_cinder.py @@ -12,9 +12,10 @@ # License for the specific language governing permissions and limitations # under the License. +from unittest import mock + from cinderclient import exceptions as cinder_exception import ddt -import mock from manila import context from manila import exception diff --git a/manila/tests/wsgi/test_common.py b/manila/tests/wsgi/test_common.py index 0b9f18be85..3d375fd0f1 100644 --- a/manila/tests/wsgi/test_common.py +++ b/manila/tests/wsgi/test_common.py @@ -13,7 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. -import mock +from unittest import mock from manila import test from manila.wsgi import common diff --git a/manila/tests/wsgi/test_wsgi.py b/manila/tests/wsgi/test_wsgi.py index 335f6b3562..2f887afa0f 100644 --- a/manila/tests/wsgi/test_wsgi.py +++ b/manila/tests/wsgi/test_wsgi.py @@ -13,7 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. -import mock +from unittest import mock from manila import test from manila.wsgi import wsgi diff --git a/test-requirements.txt b/test-requirements.txt index 1506053afc..9fe751f2af 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -9,11 +9,10 @@ bashate>=0.5.1 # Apache-2.0 coverage!=4.4,>=4.0 # Apache-2.0 ddt>=1.0.1 # MIT fixtures>=3.0.0 # Apache-2.0/BSD -mock>=2.0.0 # BSD iso8601>=0.1.11 # MIT oslotest>=3.2.0 # Apache-2.0 -# Do not remove 'PyMySQL' and 'psycopg2' dependencies. They are used +# Do not remove 'PyMySQL' and 'psycopg2-binary' dependencies. They are used # by oslo_db lib for running MySQL and PostgreSQL DB migration tests. # See https://docs.openstack.org/oslo.db/latest/contributor/index.html#how-to-run-unit-tests PyMySQL>=0.7.6 # MIT License diff --git a/tox.ini b/tox.ini index 3b4a7ca10a..f1fb3b9891 100644 --- a/tox.ini +++ b/tox.ini @@ -157,6 +157,7 @@ extension = M336 = checks:dict_constructor_with_list_copy M337 = checks:no_xrange M338 = checks:no_log_warn_check + M339 = checks:no_third_party_mock M354 = checks:check_uuid4 M359 = checks:no_translate_logs paths = ./manila/hacking