Browse Source

Remove six.moves

Replace the following items with Python 3 style code.

- six.moves.configparser
- six.moves.StringIO
- six.moves.cStringIO
- six.moves.urllib
- six.moves.builtins
- six.moves.range
- six.moves.xmlrpc_client
- six.moves.http_client
- six.moves.http_cookies
- six.moves.queue
- six.moves.zip
- six.moves.reload_module
- six.StringIO
- six.BytesIO

Subsequent patches will replace other six usages.

Change-Id: Ib2c406327fef2fb4868d8050fc476a7d17706e23
Implements: blueprint six-removal
Signed-off-by: Takashi Natsume <takanattie@gmail.com>
changes/24/727224/34
Takashi Natsume 1 year ago
parent
commit
1d0a0e8c20
  1. 3
      doc/ext/feature_matrix.py
  2. 1
      nova/api/metadata/password.py
  3. 2
      nova/api/openstack/common.py
  4. 4
      nova/api/openstack/compute/quota_sets.py
  5. 2
      nova/api/openstack/compute/simple_tenant_usage.py
  6. 2
      nova/cmd/manage.py
  7. 1
      nova/compute/api.py
  8. 1
      nova/compute/manager.py
  9. 9
      nova/conductor/manager.py
  10. 3
      nova/console/serial.py
  11. 4
      nova/console/websocketproxy.py
  12. 1
      nova/db/sqlalchemy/api.py
  13. 1
      nova/image/glance.py
  14. 3
      nova/network/security_group_api.py
  15. 3
      nova/objects/cell_mapping.py
  16. 3
      nova/objects/console_auth_token.py
  17. 1
      nova/scheduler/filter_scheduler.py
  18. 2
      nova/scheduler/utils.py
  19. 3
      nova/storage/rbd_utils.py
  20. 6
      nova/test.py
  21. 3
      nova/tests/functional/api/client.py
  22. 3
      nova/tests/functional/api_sample_tests/test_instance_usage_audit_log.py
  23. 2
      nova/tests/functional/api_sample_tests/test_simple_tenant_usage.py
  24. 2
      nova/tests/functional/test_nova_manage.py
  25. 3
      nova/tests/unit/api/openstack/compute/test_flavors.py
  26. 2
      nova/tests/unit/api/openstack/compute/test_images.py
  27. 5
      nova/tests/unit/api/openstack/compute/test_limits.py
  28. 3
      nova/tests/unit/api/openstack/compute/test_servers.py
  29. 1
      nova/tests/unit/api/openstack/compute/test_simple_tenant_usage.py
  30. 2
      nova/tests/unit/api/openstack/compute/test_volumes.py
  31. 1
      nova/tests/unit/api/openstack/fakes.py
  32. 3
      nova/tests/unit/cmd/test_baseproxy.py
  33. 2
      nova/tests/unit/cmd/test_common.py
  34. 2
      nova/tests/unit/cmd/test_manage.py
  35. 3
      nova/tests/unit/cmd/test_policy.py
  36. 7
      nova/tests/unit/cmd/test_status.py
  37. 5
      nova/tests/unit/console/test_serial.py
  38. 1
      nova/tests/unit/db/test_db_api.py
  39. 1
      nova/tests/unit/fake_ldap.py
  40. 27
      nova/tests/unit/image/test_glance.py
  41. 3
      nova/tests/unit/matchers.py
  42. 1
      nova/tests/unit/network/test_neutron.py
  43. 1
      nova/tests/unit/network/test_security_group.py
  44. 2
      nova/tests/unit/objects/test_console_auth_token.py
  45. 10
      nova/tests/unit/pci/test_utils.py
  46. 3
      nova/tests/unit/privsep/test_idmapshift.py
  47. 10
      nova/tests/unit/privsep/test_libvirt.py
  48. 7
      nova/tests/unit/privsep/test_path.py
  49. 2
      nova/tests/unit/scheduler/client/test_report.py
  50. 1
      nova/tests/unit/scheduler/test_filters.py
  51. 4
      nova/tests/unit/test_crypto.py
  52. 10
      nova/tests/unit/test_json_ref.py
  53. 6
      nova/tests/unit/test_profiler.py
  54. 1
      nova/tests/unit/test_quota.py
  55. 3
      nova/tests/unit/test_test_utils.py
  56. 2
      nova/tests/unit/test_utils.py
  57. 1
      nova/tests/unit/utils.py
  58. 5
      nova/tests/unit/virt/hyperv/test_base.py
  59. 5
      nova/tests/unit/virt/hyperv/test_pathutils.py
  60. 3
      nova/tests/unit/virt/hyperv/test_serialconsoleops.py
  61. 9
      nova/tests/unit/virt/libvirt/test_driver.py
  62. 24
      nova/tests/unit/virt/libvirt/test_host.py
  63. 4
      nova/tests/unit/virt/libvirt/test_imagecache.py
  64. 7
      nova/tests/unit/virt/libvirt/test_utils.py
  65. 4
      nova/tests/unit/virt/powervm/test_image.py
  66. 6
      nova/tests/unit/virt/test_virt.py
  67. 5
      nova/tests/unit/virt/zvm/test_driver.py
  68. 1
      nova/utils.py
  69. 2
      nova/version.py
  70. 2
      nova/virt/ironic/driver.py
  71. 7
      nova/virt/libvirt/driver.py
  72. 3
      nova/virt/zvm/utils.py
  73. 2
      nova/volume/cinder.py

3
doc/ext/feature_matrix.py

@ -20,11 +20,10 @@ It is used via a single directive in the .rst file
"""
import configparser
import re
import sys
from six.moves import configparser
from docutils import nodes
from docutils.parsers import rst

1
nova/api/metadata/password.py

@ -13,7 +13,6 @@
# License for the specific language governing permissions and limitations
# under the License.
from six.moves import range
from webob import exc
import nova.conf

2
nova/api/openstack/common.py

@ -16,11 +16,11 @@
import collections
import itertools
import re
from urllib import parse as urlparse
from oslo_log import log as logging
from oslo_utils import strutils
import six
import six.moves.urllib.parse as urlparse
import webob
from webob import exc

4
nova/api/openstack/compute/quota_sets.py

@ -13,9 +13,9 @@
# License for the specific language governing permissions and limitations
# under the License.
from oslo_utils import strutils
from urllib import parse as urlparse
import six.moves.urllib.parse as urlparse
from oslo_utils import strutils
import webob
from nova.api.openstack.api_version_request \

2
nova/api/openstack/compute/simple_tenant_usage.py

@ -15,11 +15,11 @@
import collections
import datetime
from urllib import parse as urlparse
import iso8601
from oslo_utils import timeutils
import six
import six.moves.urllib.parse as urlparse
from webob import exc
from nova.api.openstack import common

2
nova/cmd/manage.py

@ -26,6 +26,7 @@ import functools
import re
import sys
import traceback
from urllib import parse as urlparse
from dateutil import parser as dateutil_parser
from keystoneauth1 import exceptions as ks_exc
@ -40,7 +41,6 @@ from oslo_utils import encodeutils
from oslo_utils import uuidutils
import prettytable
import six
import six.moves.urllib.parse as urlparse
from sqlalchemy.engine import url as sqla_url
from nova.cmd import common as cmd_common

1
nova/compute/api.py

@ -35,7 +35,6 @@ from oslo_utils import timeutils
from oslo_utils import units
from oslo_utils import uuidutils
import six
from six.moves import range
from nova.accelerator import cyborg
from nova import availability_zones

1
nova/compute/manager.py

@ -55,7 +55,6 @@ from oslo_utils import strutils
from oslo_utils import timeutils
from oslo_utils import units
import six
from six.moves import range
from nova.accelerator import cyborg
from nova import block_device

9
nova/conductor/manager.py

@ -702,7 +702,7 @@ class ComputeTaskManager(base.Base):
return
elevated = context.elevated()
for (instance, host_list) in six.moves.zip(instances, host_lists):
for (instance, host_list) in zip(instances, host_lists):
host = host_list.pop(0)
if is_reschedule:
# If this runs in the superconductor, the first instance will
@ -1523,7 +1523,7 @@ class ComputeTaskManager(base.Base):
instances = []
host_az = {} # host=az cache to optimize multi-create
for (build_request, request_spec, host_list) in six.moves.zip(
for (build_request, request_spec, host_list) in zip(
build_requests, request_specs, host_lists):
instance = build_request.get_new_instance(context)
# host_list is a list of one or more Selection objects, the first
@ -1605,8 +1605,7 @@ class ComputeTaskManager(base.Base):
block_device_mapping, tags,
cell_mapping_cache)
zipped = six.moves.zip(build_requests, request_specs, host_lists,
instances)
zipped = zip(build_requests, request_specs, host_lists, instances)
for (build_request, request_spec, host_list, instance) in zipped:
if instance is None:
# Skip placeholders that were buried in cell0 or had their
@ -1758,7 +1757,7 @@ class ComputeTaskManager(base.Base):
def _cleanup_build_artifacts(self, context, exc, instances, build_requests,
request_specs, block_device_mappings, tags,
cell_mapping_cache):
for (instance, build_request, request_spec) in six.moves.zip(
for (instance, build_request, request_spec) in zip(
instances, build_requests, request_specs):
# Skip placeholders that were buried in cell0 or had their
# build requests deleted by the user before instance create.

3
nova/console/serial.py

@ -17,7 +17,6 @@
import socket
from oslo_log import log as logging
import six.moves
import nova.conf
from nova import exception
@ -45,7 +44,7 @@ def acquire_port(host):
start, stop = _get_port_range()
for port in six.moves.range(start, stop):
for port in range(start, stop):
if (host, port) in ALLOCATED_PORTS:
continue
try:

4
nova/console/websocketproxy.py

@ -19,15 +19,15 @@ Leverages websockify.py by Joel Martin
'''
import copy
from http import cookies as Cookie
import socket
import sys
from urllib import parse as urlparse
from oslo_log import log as logging
from oslo_utils import encodeutils
from oslo_utils import importutils
import six
from six.moves import http_cookies as Cookie
import six.moves.urllib.parse as urlparse
import websockify
from nova.compute import rpcapi as compute_rpcapi

1
nova/db/sqlalchemy/api.py

@ -35,7 +35,6 @@ from oslo_utils import importutils
from oslo_utils import timeutils
from oslo_utils import uuidutils
import six
from six.moves import range
import sqlalchemy as sa
from sqlalchemy import and_
from sqlalchemy import Boolean

1
nova/image/glance.py

@ -40,7 +40,6 @@ from oslo_serialization import jsonutils
from oslo_utils import excutils
from oslo_utils import timeutils
import six
from six.moves import range
import nova.conf
from nova import exception

3
nova/network/security_group_api.py

@ -17,6 +17,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import urllib
import netaddr
from neutronclient.common import exceptions as n_exc
from neutronclient.neutron import v2_0 as neutronv20
@ -26,7 +28,6 @@ from oslo_utils import excutils
from oslo_utils import netutils
from oslo_utils import uuidutils
import six
from six.moves import urllib
from webob import exc
from nova import context as nova_context

3
nova/objects/cell_mapping.py

@ -10,9 +10,10 @@
# License for the specific language governing permissions and limitations
# under the License.
from urllib import parse as urlparse
from oslo_log import log as logging
from oslo_utils import versionutils
import six.moves.urllib.parse as urlparse
from sqlalchemy.sql.expression import asc
from sqlalchemy.sql import false
from sqlalchemy.sql import true

3
nova/objects/console_auth_token.py

@ -13,12 +13,13 @@
# License for the specific language governing permissions and limitations
# under the License.
from urllib import parse as urlparse
from oslo_db.exception import DBDuplicateEntry
from oslo_log import log as logging
from oslo_utils import strutils
from oslo_utils import timeutils
from oslo_utils import uuidutils
import six.moves.urllib.parse as urlparse
from nova.db import api as db
from nova import exception

1
nova/scheduler/filter_scheduler.py

@ -22,7 +22,6 @@ Weighing Functions.
import random
from oslo_log import log as logging
from six.moves import range
from nova.compute import utils as compute_utils
import nova.conf

2
nova/scheduler/utils.py

@ -17,12 +17,12 @@
import collections
import re
import sys
from urllib import parse
import os_resource_classes as orc
import os_traits
from oslo_log import log as logging
from oslo_serialization import jsonutils
from six.moves.urllib import parse
from nova.compute import flavors
from nova.compute import utils as compute_utils

3
nova/storage/rbd_utils.py

@ -14,8 +14,9 @@
# License for the specific language governing permissions and limitations
# under the License.
import urllib
from eventlet import tpool
from six.moves import urllib
from oslo_concurrency import processutils
from oslo_log import log as logging

6
nova/test.py

@ -24,6 +24,7 @@ inline callbacks.
import nova.monkey_patch # noqa
import abc
import builtins
import collections
import contextlib
import copy
@ -50,7 +51,6 @@ from oslo_versionedobjects import fixture as ovo_fixture
from oslotest import base
from oslotest import mock_fixture
import six
from six.moves import builtins
import testtools
from nova.compute import rpcapi as compute_rpcapi
@ -903,7 +903,7 @@ def patch_open(patched_path, read_data):
selective patching based on the path. In this case something like
like this may be more appropriate:
@mock.patch(six.moves.builtins, 'open')
@mock.patch('builtins.open')
def test_my_code(self, mock_open):
...
mock_open.assert_called_once_with(path)
@ -916,6 +916,6 @@ def patch_open(patched_path, read_data):
return m(patched_path)
return real_open(path, *args, **kwargs)
with mock.patch.object(builtins, 'open') as mock_open:
with mock.patch('builtins.open') as mock_open:
mock_open.side_effect = selective_fake_open
yield m

3
nova/tests/functional/api/client.py

@ -12,10 +12,11 @@
# License for the specific language governing permissions and limitations
# under the License.
from urllib import parse
from oslo_log import log as logging
from oslo_serialization import jsonutils
import requests
from six.moves.urllib import parse
LOG = logging.getLogger(__name__)

3
nova/tests/functional/api_sample_tests/test_instance_usage_audit_log.py

@ -14,8 +14,7 @@
# under the License.
from datetime import datetime
from six.moves import urllib
import urllib
from nova import context
from nova import objects

2
nova/tests/functional/api_sample_tests/test_simple_tenant_usage.py

@ -13,10 +13,10 @@
# under the License.
import datetime
from urllib import parse
import mock
from oslo_utils import timeutils
from six.moves.urllib import parse
from nova.tests.functional.api_sample_tests import test_servers
import nova.tests.functional.api_samples_test_base as astb

2
nova/tests/functional/test_nova_manage.py

@ -10,13 +10,13 @@
# License for the specific language governing permissions and limitations
# under the License.
import collections
from io import StringIO
import mock
import fixtures
from neutronclient.common import exceptions as neutron_client_exc
import os_resource_classes as orc
from oslo_utils.fixture import uuidsentinel
from six.moves import StringIO
from nova.cmd import manage
from nova import config

3
nova/tests/unit/api/openstack/compute/test_flavors.py

@ -13,8 +13,9 @@
# License for the specific language governing permissions and limitations
# under the License.
from urllib import parse as urlparse
import mock
import six.moves.urllib.parse as urlparse
import webob
from nova.api.openstack import common

2
nova/tests/unit/api/openstack/compute/test_images.py

@ -19,9 +19,9 @@ and as a WSGI layer
"""
import copy
from urllib import parse as urlparse
import mock
import six.moves.urllib.parse as urlparse
import webob
from nova.api.openstack.compute import images as images_v21

5
nova/tests/unit/api/openstack/compute/test_limits.py

@ -17,11 +17,12 @@
Tests dealing with HTTP rate-limiting.
"""
from http import client as httplib
from io import StringIO
import mock
from oslo_serialization import jsonutils
from oslo_utils import encodeutils
from six.moves import http_client as httplib
from six.moves import StringIO
from nova.api.openstack.compute import limits as limits_v21
from nova.api.openstack.compute import views

3
nova/tests/unit/api/openstack/compute/test_servers.py

@ -19,6 +19,7 @@ import copy
import datetime
import ddt
import functools
from urllib import parse as urlparse
import fixtures
import iso8601
@ -32,8 +33,6 @@ from oslo_utils.fixture import uuidsentinel as uuids
from oslo_utils import timeutils
from oslo_utils import uuidutils
import six
from six.moves import range
import six.moves.urllib.parse as urlparse
import testtools
import webob

1
nova/tests/unit/api/openstack/compute/test_simple_tenant_usage.py

@ -19,7 +19,6 @@ import mock
from oslo_policy import policy as oslo_policy
from oslo_utils.fixture import uuidsentinel as uuids
from oslo_utils import timeutils
from six.moves import range
import webob
from nova.api.openstack.compute import simple_tenant_usage as \

2
nova/tests/unit/api/openstack/compute/test_volumes.py

@ -15,6 +15,7 @@
# under the License.
import datetime
import urllib
import fixtures
import mock
@ -22,7 +23,6 @@ from oslo_serialization import jsonutils
from oslo_utils import encodeutils
from oslo_utils.fixture import uuidsentinel as uuids
import six
from six.moves import urllib
import webob
from webob import exc

1
nova/tests/unit/api/openstack/fakes.py

@ -20,7 +20,6 @@ from oslo_utils import timeutils
from oslo_utils import uuidutils
import routes
import six
from six.moves import range
import webob.dec
from nova.api import auth as api_auth

3
nova/tests/unit/cmd/test_baseproxy.py

@ -12,11 +12,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from io import StringIO
import fixtures
import mock
from oslo_log import log as logging
from oslo_reports import guru_meditation_report as gmr
from six.moves import StringIO
from nova.cmd import baseproxy
from nova import config

2
nova/tests/unit/cmd/test_common.py

@ -17,11 +17,11 @@
Unit tests for the common functions used by different CLI interfaces.
"""
from io import StringIO
import sys
import fixtures
import mock
from six.moves import StringIO
from nova.cmd import common as cmd_common
from nova.db import api

2
nova/tests/unit/cmd/test_manage.py

@ -14,6 +14,7 @@
# under the License.
import datetime
from io import StringIO
import sys
import warnings
@ -24,7 +25,6 @@ from oslo_db import exception as db_exc
from oslo_serialization import jsonutils
from oslo_utils.fixture import uuidsentinel
from oslo_utils import uuidutils
from six.moves import StringIO
from nova.cmd import manage
from nova import conf

3
nova/tests/unit/cmd/test_policy.py

@ -17,9 +17,10 @@
Unit tests for the nova-policy-check CLI interfaces.
"""
from io import StringIO
import fixtures
import mock
from six.moves import StringIO
from nova.cmd import policy
import nova.conf

7
nova/tests/unit/cmd/test_status.py

@ -20,11 +20,12 @@ Unit tests for the nova-status CLI interfaces.
# nova/tests/functional/test_nova_status.py. Those tests use the external
# PlacementFixture, which is only available in functioanl tests.
import fixtures
import mock
from io import StringIO
import os
from six.moves import StringIO
import tempfile
import fixtures
import mock
import yaml
from keystoneauth1 import exceptions as ks_exc

5
nova/tests/unit/console/test_serial.py

@ -17,7 +17,6 @@
import socket
import mock
import six.moves
from nova.console import serial
from nova import exception
@ -74,10 +73,10 @@ class SerialTestCase(test.NoDBTestCase):
port_range='%d:%d' % (start, stop),
group='serial_console')
for port in six.moves.range(start, stop):
for port in range(start, stop):
self.assertEqual(port, serial.acquire_port('127.0.0.1'))
for port in six.moves.range(start, stop):
for port in range(start, stop):
self.assertEqual(port, serial.acquire_port('127.0.0.2'))
self.assertEqual(10, len(serial.ALLOCATED_PORTS))

1
nova/tests/unit/db/test_db_api.py

@ -37,7 +37,6 @@ from oslo_utils.fixture import uuidsentinel
from oslo_utils import timeutils
from oslo_utils import uuidutils
import six
from six.moves import range
from sqlalchemy import Column
from sqlalchemy.dialects import sqlite
from sqlalchemy.exc import OperationalError

1
nova/tests/unit/fake_ldap.py

@ -24,7 +24,6 @@ library to work with nova.
import fnmatch
from oslo_serialization import jsonutils
from six.moves import range
class Store(object):

27
nova/tests/unit/image/test_glance.py

@ -16,6 +16,7 @@
import copy
import datetime
from io import StringIO
import urllib.parse as urlparse
import cryptography
@ -27,8 +28,6 @@ from glanceclient.v2 import schemas
from keystoneauth1 import loading as ks_loading
import mock
from oslo_utils.fixture import uuidsentinel as uuids
import six
from six.moves import StringIO
import testtools
import nova.conf
@ -556,7 +555,7 @@ class TestDownloadNoDirectUri(test.NoDBTestCase):
default of not allowing direct URI transfers is set.
"""
@mock.patch.object(six.moves.builtins, 'open')
@mock.patch('builtins.open')
@mock.patch('nova.image.glance.GlanceImageServiceV2.show')
def test_download_no_data_no_dest_path_v2(self, show_mock, open_mock):
client = mock.MagicMock()
@ -572,7 +571,7 @@ class TestDownloadNoDirectUri(test.NoDBTestCase):
ctx, 2, 'data', args=(mock.sentinel.image_id,))
self.assertEqual(mock.sentinel.image_chunks, res)
@mock.patch.object(six.moves.builtins, 'open')
@mock.patch('builtins.open')
@mock.patch('nova.image.glance.GlanceImageServiceV2.show')
def test_download_data_no_dest_path_v2(self, show_mock, open_mock):
client = mock.MagicMock()
@ -596,7 +595,7 @@ class TestDownloadNoDirectUri(test.NoDBTestCase):
)
self.assertFalse(data.close.called)
@mock.patch.object(six.moves.builtins, 'open')
@mock.patch('builtins.open')
@mock.patch('nova.image.glance.GlanceImageServiceV2.show')
@mock.patch('nova.image.glance.GlanceImageServiceV2._safe_fsync')
def test_download_no_data_dest_path_v2(self, fsync_mock, show_mock,
@ -625,7 +624,7 @@ class TestDownloadNoDirectUri(test.NoDBTestCase):
)
writer.close.assert_called_once_with()
@mock.patch.object(six.moves.builtins, 'open')
@mock.patch('builtins.open')
@mock.patch('nova.image.glance.GlanceImageServiceV2.show')
def test_download_data_dest_path_v2(self, show_mock, open_mock):
# NOTE(jaypipes): This really shouldn't be allowed, but because of the
@ -654,7 +653,7 @@ class TestDownloadNoDirectUri(test.NoDBTestCase):
)
self.assertFalse(data.close.called)
@mock.patch.object(six.moves.builtins, 'open')
@mock.patch('builtins.open')
@mock.patch('nova.image.glance.GlanceImageServiceV2.show')
def test_download_data_dest_path_write_fails_v2(
self, show_mock, open_mock):
@ -675,7 +674,7 @@ class TestDownloadNoDirectUri(test.NoDBTestCase):
self.assertRaises(FakeDiskException, service.download, ctx,
mock.sentinel.image_id, data=Exceptionator())
@mock.patch.object(six.moves.builtins, 'open')
@mock.patch('builtins.open')
@mock.patch('nova.image.glance.GlanceImageServiceV2.show')
def test_download_no_returned_image_data_v2(
self, show_mock, open_mock):
@ -691,7 +690,7 @@ class TestDownloadNoDirectUri(test.NoDBTestCase):
# TODO(stephenfin): Drop this test since it's not possible to run in
# production
@mock.patch('os.path.getsize', return_value=1)
@mock.patch.object(six.moves.builtins, 'open')
@mock.patch('builtins.open')
@mock.patch('nova.image.glance.GlanceImageServiceV2._get_transfer_method')
@mock.patch('nova.image.glance.GlanceImageServiceV2.show')
def test_download_direct_file_uri_v2(
@ -727,7 +726,7 @@ class TestDownloadNoDirectUri(test.NoDBTestCase):
@mock.patch('glanceclient.common.utils.IterableWithLength')
@mock.patch('os.path.getsize', return_value=1)
@mock.patch.object(six.moves.builtins, 'open')
@mock.patch('builtins.open')
@mock.patch('nova.image.glance.LOG')
@mock.patch('nova.image.glance.GlanceImageServiceV2._get_verifier')
@mock.patch('nova.image.glance.GlanceImageServiceV2._get_transfer_method')
@ -820,7 +819,7 @@ class TestDownloadNoDirectUri(test.NoDBTestCase):
ctx = mock.sentinel.ctx
writer = mock.MagicMock()
with mock.patch.object(six.moves.builtins, 'open') as open_mock:
with mock.patch('builtins.open') as open_mock:
open_mock.return_value = writer
service = glance.GlanceImageServiceV2(client)
res = service.download(ctx, mock.sentinel.image_id,
@ -873,7 +872,7 @@ class TestDownloadNoDirectUri(test.NoDBTestCase):
ctx = mock.sentinel.ctx
writer = mock.MagicMock()
with mock.patch.object(six.moves.builtins, 'open') as open_mock:
with mock.patch('builtins.open') as open_mock:
open_mock.return_value = writer
service = glance.GlanceImageServiceV2(client)
res = service.download(ctx, mock.sentinel.image_id,
@ -966,7 +965,7 @@ class TestDownloadSignatureVerification(test.NoDBTestCase):
msg = ('Image signature verification succeeded for image %s')
mock_log.info.assert_called_once_with(msg, image_id)
@mock.patch.object(six.moves.builtins, 'open')
@mock.patch('builtins.open')
@mock.patch('nova.image.glance.LOG')
@mock.patch('nova.image.glance.GlanceImageServiceV2.show')
@mock.patch('cursive.signature_utils.get_verifier')
@ -1051,7 +1050,7 @@ class TestDownloadSignatureVerification(test.NoDBTestCase):
context=None, image_id=None,
data=None, dst_path=None)
@mock.patch.object(six.moves.builtins, 'open')
@mock.patch('builtins.open')
@mock.patch('cursive.signature_utils.get_verifier')
@mock.patch('nova.image.glance.LOG')
@mock.patch('nova.image.glance.GlanceImageServiceV2.show')

3
nova/tests/unit/matchers.py

@ -17,6 +17,7 @@
"""Matcher classes to be used inside of the testtools assertThat framework."""
import copy
import io
import pprint
from lxml import etree
@ -411,7 +412,7 @@ class XMLMatches(object):
if isinstance(text_or_bytes, six.text_type):
text_or_bytes = text_or_bytes.encode("utf-8")
parser = etree.XMLParser(encoding="UTF-8")
return etree.parse(six.BytesIO(text_or_bytes), parser)
return etree.parse(io.BytesIO(text_or_bytes), parser)
def __init__(self, expected, allow_mixed_nodes=False,
skip_empty_text_nodes=True, skip_values=('DONTCARE',)):

1
nova/tests/unit/network/test_neutron.py

@ -32,7 +32,6 @@ from oslo_utils import timeutils
from oslo_utils import uuidutils
import requests_mock
import six
from six.moves import range
from nova import context
from nova.db.sqlalchemy import api as db_api

1
nova/tests/unit/network/test_security_group.py

@ -18,7 +18,6 @@ from neutronclient.common import exceptions as n_exc
from neutronclient.neutron import v2_0 as neutronv20
from neutronclient.v2_0 import client
from oslo_utils.fixture import uuidsentinel as uuids
from six.moves import range
from nova import context
from nova import exception

2
nova/tests/unit/objects/test_console_auth_token.py

@ -15,11 +15,11 @@
import copy
import mock
import urllib.parse as urlparse
from oslo_db.exception import DBDuplicateEntry
from oslo_utils.fixture import uuidsentinel
from oslo_utils import timeutils
import six.moves.urllib.parse as urlparse
from nova import exception
from nova.objects import console_auth_token as token_obj

10
nova/tests/unit/pci/test_utils.py

@ -19,7 +19,6 @@ import os
import fixtures
import mock
from six.moves import builtins
from nova import exception
from nova.pci import utils
@ -95,8 +94,7 @@ class GetFunctionByIfnameTestCase(test.NoDBTestCase):
@mock.patch.object(os, 'readlink')
def test_virtual_function(self, mock_readlink, *args):
mock_readlink.return_value = '../../../0000.00.00.1'
with mock.patch.object(
builtins, 'open', side_effect=IOError()):
with mock.patch('builtins.open', side_effect=IOError()):
address, physical_function = utils.get_function_by_ifname('eth0')
self.assertEqual(address, '0000.00.00.1')
self.assertFalse(physical_function)
@ -129,14 +127,12 @@ class IsPhysicalFunctionTestCase(test.NoDBTestCase):
@mock.patch('os.path.isdir', return_value=True)
def test_virtual_function(self, *args):
with mock.patch.object(
builtins, 'open', side_effect=IOError()):
with mock.patch('builtins.open', side_effect=IOError()):
self.assertFalse(utils.is_physical_function(*self.pci_args))
@mock.patch('os.path.isdir', return_value=True)
def test_physical_function(self, *args):
with mock.patch.object(
builtins, 'open', mock.mock_open(read_data='4')):
with mock.patch('builtins.open', mock.mock_open(read_data='4')):
self.assertTrue(utils.is_physical_function(*self.pci_args))
@mock.patch('os.path.isdir', return_value=False)

3
nova/tests/unit/privsep/test_idmapshift.py

@ -12,9 +12,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from io import StringIO
import fixtures
import mock
from six.moves import StringIO
import nova.privsep.idmapshift
from nova import test

10
nova/tests/unit/privsep/test_libvirt.py

@ -18,7 +18,6 @@ import binascii
import ddt
import mock
import os
import six
import nova.privsep.libvirt
from nova import test
@ -134,10 +133,8 @@ class LibvirtTestCase(test.NoDBTestCase):
return orig_import(module, *args)
with test.nested(
mock.patch.object(six.moves.builtins, 'open',
new=mock.mock_open()),
mock.patch.object(six.moves.builtins, '__import__',
side_effect=fake_import),
mock.patch('builtins.open', new=mock.mock_open()),
mock.patch('builtins.__import__', side_effect=fake_import),
) as (mock_open, mock_import):
nova.privsep.libvirt.readpty('/fake/path')
@ -158,8 +155,7 @@ class LibvirtTestCase(test.NoDBTestCase):
def test_create_nmdev(self):
mock_open = mock.mock_open()
with mock.patch.object(six.moves.builtins, 'open',
new=mock_open) as mock_open:
with mock.patch('builtins.open', new=mock_open) as mock_open:
nova.privsep.libvirt.create_mdev('phys', 'mdevtype',
uuid='fakeuuid')

7
nova/tests/unit/privsep/test_path.py

@ -16,7 +16,6 @@
import mock
import os
import six
import tempfile
from nova import exception
@ -35,8 +34,7 @@ class FileTestCase(test.NoDBTestCase):
@mock.patch('os.path.exists', return_value=True)
def test_readfile(self, mock_exists):
mock_open = mock.mock_open(read_data='hello world')
with mock.patch.object(six.moves.builtins, 'open',
new=mock_open):
with mock.patch('builtins.open', new=mock_open):
self.assertEqual('hello world',
nova.privsep.path.readfile('/fake/path'))
@ -49,8 +47,7 @@ class FileTestCase(test.NoDBTestCase):
@mock.patch('os.path.exists', return_value=True)
def test_write(self, mock_exists):
mock_open = mock.mock_open()
with mock.patch.object(six.moves.builtins, 'open',
new=mock_open):
with mock.patch('builtins.open', new=mock_open):
nova.privsep.path.writefile('/fake/path/file', 'w', 'foo')
handle = mock_open()

2
nova/tests/unit/scheduler/client/test_report.py

@ -11,6 +11,7 @@
# under the License.
import copy
import time
from urllib import parse
import fixtures
from keystoneauth1 import exceptions as ks_exc
@ -19,7 +20,6 @@ import os_resource_classes as orc
from oslo_serialization import jsonutils
from oslo_utils.fixture import uuidsentinel as uuids
import six
from six.moves.urllib import parse
import nova.conf
from nova import context

1
nova/tests/unit/scheduler/test_filters.py

@ -19,7 +19,6 @@ import inspect
import mock
from oslo_utils.fixture import uuidsentinel as uuids
from six.moves import range
from nova import filters
from nova import loadables

4
nova/tests/unit/test_crypto.py

@ -16,6 +16,7 @@
Tests for Crypto module.
"""
import io
import os
from castellan.common import exception as castellan_exception
@ -25,7 +26,6 @@ import mock
from oslo_concurrency import processutils
from oslo_utils.fixture import uuidsentinel as uuids
import paramiko
import six
from nova import context as nova_context
from nova import crypto
@ -210,7 +210,7 @@ class KeyPairTest(test.NoDBTestCase):
self.assertEqual(bits, pkey.key_size)
def test_generate_key_pair_mocked_private_key(self):
keyin = six.StringIO()
keyin = io.StringIO()
keyin.write(self.rsa_prv)
keyin.seek(0)
key = paramiko.RSAKey.from_private_key(keyin)

10
nova/tests/unit/test_json_ref.py

@ -55,7 +55,7 @@ class TestJsonRef(test.NoDBTestCase):
d = copy.deepcopy(input)
@mock.patch('oslo_serialization.jsonutils.load')
@mock.patch('six.moves.builtins.open', new_callable=mock.mock_open())
@mock.patch('builtins.open', new_callable=mock.mock_open())
def test_resolve_ref(self, mock_open, mock_json_load):
mock_json_load.return_value = {'baz': 13}
@ -70,7 +70,7 @@ class TestJsonRef(test.NoDBTestCase):
mock_open.assert_called_once_with('some/base/path/another.json', 'r+b')
@mock.patch('oslo_serialization.jsonutils.load')
@mock.patch('six.moves.builtins.open', new_callable=mock.mock_open())
@mock.patch('builtins.open', new_callable=mock.mock_open())
def test_resolve_ref_recursively(self, mock_open, mock_json_load):
mock_json_load.side_effect = [
# this is the content of direct_ref.json
@ -94,7 +94,7 @@ class TestJsonRef(test.NoDBTestCase):
'r+b')
@mock.patch('oslo_serialization.jsonutils.load')
@mock.patch('six.moves.builtins.open', new_callable=mock.mock_open())
@mock.patch('builtins.open', new_callable=mock.mock_open())
def test_resolve_ref_with_override(self, mock_open, mock_json_load):
mock_json_load.return_value = {'baz': 13,
'boo': 42}
@ -112,7 +112,7 @@ class TestJsonRef(test.NoDBTestCase):
mock_open.assert_called_once_with('some/base/path/another.json', 'r+b')
@mock.patch('oslo_serialization.jsonutils.load')
@mock.patch('six.moves.builtins.open', new_callable=mock.mock_open())
@mock.patch('builtins.open', new_callable=mock.mock_open())
def test_resolve_ref_with_nested_override(self, mock_open, mock_json_load):
mock_json_load.return_value = {'baz': 13,
'boo': {'a': 1,
@ -134,7 +134,7 @@ class TestJsonRef(test.NoDBTestCase):
mock_open.assert_called_once_with('some/base/path/another.json', 'r+b')
@mock.patch('oslo_serialization.jsonutils.load')
@mock.patch('six.moves.builtins.open', new_callable=mock.mock_open())
@mock.patch('builtins.open', new_callable=mock.mock_open())
def test_resolve_ref_with_override_having_refs(self, mock_open,
mock_json_load):
mock_json_load.side_effect = [

6
nova/tests/unit/test_profiler.py

@ -13,12 +13,12 @@
# License for the specific language governing permissions and limitations
# under the License.
import importlib
import inspect
import os
from oslo_utils import importutils
import osprofiler.opts as profiler
import six.moves as six
from nova import conf
from nova import test
@ -44,7 +44,7 @@ class TestProfiler(test.NoDBTestCase):
# reinitialize the metaclass after enabling osprofiler
profiler.set_defaults(conf.CONF)
self.flags(enabled=True, group='profiler')
six.reload_module(importutils.import_module('nova.manager'))
importlib.reload(importutils.import_module('nova.manager'))
classes = [
'nova.compute.api.API',
@ -64,7 +64,7 @@ class TestProfiler(test.NoDBTestCase):
for clsname in classes:
# give the metaclass and trace_cls() decorator a chance to patch
# methods of the classes above
six.reload_module(
importlib.reload(
importutils.import_module(clsname.rsplit('.', 1)[0]))
cls = importutils.import_class(clsname)

1
nova/tests/unit/test_quota.py

@ -17,7 +17,6 @@
import ddt
import mock
from oslo_db.sqlalchemy import enginefacade
from six.moves import range
from nova.compute import api as compute
import nova.conf

3
nova/tests/unit/test_test_utils.py

@ -60,6 +60,5 @@ class TestUtilsTestCase(test.TestCase):
self.assertTrue(test_utils.is_ipv6_supported())
with fixtures.MonkeyPatch('sys.platform', 'linux2'):
with fixtures.MonkeyPatch('six.moves.builtins.open',
fake_open):
with fixtures.MonkeyPatch('builtins.open', fake_open):
self.assertFalse(test_utils.is_ipv6_supported())

2
nova/tests/unit/test_utils.py

@ -260,7 +260,7 @@ class TestCachedFile(test.NoDBTestCase):
fake_contents = "lorem ipsum"
with mock.patch('six.moves.builtins.open',
with mock.patch('builtins.open',
mock.mock_open(read_data=fake_contents)):
fresh, data = utils.read_cached_file("/this/is/a/fake")

1
nova/tests/unit/utils.py

@ -19,7 +19,6 @@ import socket
import sys
import mock
from six.moves import range
from nova.compute import flavors
import nova.conf

5
nova/tests/unit/virt/hyperv/test_base.py

@ -16,7 +16,6 @@
import mock
from os_win import utilsfactory
from six.moves import builtins
from nova import test
@ -26,8 +25,8 @@ class HyperVBaseTestCase(test.NoDBTestCase):
super(HyperVBaseTestCase, self).setUp()
self._mock_wmi = mock.MagicMock()
wmi_patcher = mock.patch.object(builtins, 'wmi', create=True,
new=self._mock_wmi)
wmi_patcher = mock.patch('builtins.wmi', create=True,
new=self._mock_wmi)
platform_patcher = mock.patch('sys.platform', 'win32')
utilsfactory_patcher = mock.patch.object(utilsfactory, '_get_class')

5
nova/tests/unit/virt/hyperv/test_pathutils.py

@ -16,7 +16,6 @@ import os
import time
import mock
from six.moves import builtins
from nova import exception
from nova.tests.unit.virt.hyperv import test_base
@ -121,8 +120,8 @@ class PathUtilsTestCase(test_base.HyperVBaseTestCase):
fake_windows_error = WindowsError
self._pathutils.check_create_dir = mock.MagicMock(
side_effect=WindowsError(pathutils.ERROR_INVALID_NAME))
with mock.patch.object(builtins, 'WindowsError',
fake_windows_error, create=True):
with mock.patch('builtins.WindowsError',
fake_windows_error, create=True):
self.assertRaises(exception.AdminRequired,
self._pathutils._get_instances_sub_dir,
fake_dir_name)

3
nova/tests/unit/virt/hyperv/test_serialconsoleops.py

@ -14,7 +14,6 @@
# under the License.
import mock
from six.moves import builtins
from nova import exception
from nova.tests.unit.virt.hyperv import test_base
@ -89,7 +88,7 @@ class SerialConsoleOpsTestCase(test_base.HyperVBaseTestCase):
self._serialops.get_serial_console,
mock.sentinel.instance_name)
@mock.patch.object(builtins, 'open')
@mock.patch('builtins.open')
@mock.patch("os.path.exists")
def test_get_console_output_exception(self, fake_path_exists, fake_open):
self._serialops._pathutils.get_vm_console_log_paths.return_value = [

9
nova/tests/unit/virt/libvirt/test_driver.py

@ -60,7 +60,6 @@ from oslo_utils import units
from oslo_utils import uuidutils
from oslo_utils import versionutils
import six
from six.moves import range
from nova.api.metadata import base as instance_metadata
from nova.compute import manager
@ -15739,8 +15738,7 @@ class LibvirtConnTestCase(test.NoDBTestCase,
with test.nested(
mock.patch('os.path.exists',
side_effect=mock_path_exists),
mock.patch.object(six.moves.builtins, 'open',
fake_open)):
mock.patch('builtins.open', fake_open)):
log_data = drvr.get_console_output(self.context,
instance)
finally:
@ -20764,7 +20762,7 @@ class TestGuestConfigSysinfoSerialOS(test.NoDBTestCase):
self.flags(sysinfo_serial="os", group="libvirt")
theuuid = "56b40135-a973-4eb3-87bb-a2382a3e6dbc"
with test.nested(
mock.patch.object(six.moves.builtins, "open",
mock.patch('builtins.open',
mock.mock_open(read_data=theuuid)),
self.patch_exists("/etc/machine-id", True)):
self._test_get_guest_config_sysinfo_serial(theuuid)
@ -20772,8 +20770,7 @@ class TestGuestConfigSysinfoSerialOS(test.NoDBTestCase):
def test_get_guest_config_sysinfo_serial_os_empty_machine_id(self):
self.flags(sysinfo_serial="os", group="libvirt")
with test.nested(
mock.patch.object(six.moves.builtins, "open",
mock.mock_open(read_data="")),
mock.patch('builtins.open', mock.mock_open(read_data="")),
self.patch_exists("/etc/machine-id", True)):
self.assertRaises(exception.NovaException,
self._test_get_guest_config_sysinfo_serial,

24
nova/tests/unit/virt/libvirt/test_host.py

@ -23,10 +23,8 @@ import mock
from oslo_utils.fixture import uuidsentinel as uuids
from oslo_utils import uuidutils