From 2c9d1db276499d860e951c4b10bf4e59d8cf6be9 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 9 Jun 2015 15:32:32 +0200 Subject: [PATCH] Get StringIO from six for Python 3 compatibility Get StringIO and cStringIO classes and modules from the six module to make cinder compatible with Python 2 and Python 3. This patch was generated by the stringio operation of the sixer tool version 0.4: https://pypi.python.org/pypi/sixer Blueprint cinder-python3 Change-Id: Ia8a58f83a504f2d2930bf5a0dc2cbaa482c29784 --- cinder/tests/unit/targets/test_cxt_driver.py | 4 ++-- cinder/tests/unit/targets/test_iet_driver.py | 12 +++++------- cinder/tests/unit/test_hds_iscsi.py | 8 ++++---- cinder/tests/unit/test_hds_nfs.py | 8 ++++---- cinder/tests/unit/test_quobyte.py | 9 ++++----- cinder/volume/drivers/zfssa/restclient.py | 4 ++-- 6 files changed, 21 insertions(+), 24 deletions(-) diff --git a/cinder/tests/unit/targets/test_cxt_driver.py b/cinder/tests/unit/targets/test_cxt_driver.py index 9134fc3fe..6a7034e76 100644 --- a/cinder/tests/unit/targets/test_cxt_driver.py +++ b/cinder/tests/unit/targets/test_cxt_driver.py @@ -15,9 +15,9 @@ import contextlib import os -import StringIO import mock +import six from cinder import context from cinder.tests.unit.targets import targets_fixture as tf @@ -50,7 +50,7 @@ class TestCxtAdmDriver(tf.TargetDriverFixture): self.assertTrue(m_exec.called) def test_get_target_chap_auth(self): - tmp_file = StringIO.StringIO() + tmp_file = six.StringIO() tmp_file.write( 'target:\n' ' TargetName=iqn.2010-10.org.openstack:volume-83c2e877-feed-46be-8435-77884fe55b45\n' # noqa diff --git a/cinder/tests/unit/targets/test_iet_driver.py b/cinder/tests/unit/targets/test_iet_driver.py index c9b8ade3b..9f6921bbe 100644 --- a/cinder/tests/unit/targets/test_iet_driver.py +++ b/cinder/tests/unit/targets/test_iet_driver.py @@ -12,11 +12,9 @@ import contextlib -import StringIO - - import mock from oslo_concurrency import processutils as putils +import six from cinder import context from cinder import exception @@ -34,7 +32,7 @@ class TestIetAdmDriver(tf.TargetDriverFixture): configuration=self.configuration) def test_get_target(self): - tmp_file = StringIO.StringIO() + tmp_file = six.StringIO() tmp_file.write( 'tid:1 name:iqn.2010-10.org.openstack:volume-83c2e877-feed-46be-8435-77884fe55b45\n' # noqa ' sid:844427031282176 initiator:iqn.1994-05.com.redhat:5a6894679665\n' # noqa @@ -56,7 +54,7 @@ class TestIetAdmDriver(tf.TargetDriverFixture): @mock.patch('os.path.exists', return_value=True) @mock.patch('cinder.utils.temporary_chown') def test_get_target_chap_auth(self, mock_chown, mock_exists): - tmp_file = StringIO.StringIO() + tmp_file = six.StringIO() tmp_file.write( 'Target iqn.2010-10.org.openstack:volume-83c2e877-feed-46be-8435-77884fe55b45\n' # noqa ' IncomingUser otzLy2UYbYfnP4zXLG5z 234Zweo38VGBBvrpK9nt\n' @@ -87,7 +85,7 @@ class TestIetAdmDriver(tf.TargetDriverFixture): def test_create_iscsi_target(self, mock_chown, mock_exists, mock_execute, mock_get_targ): mock_execute.return_value = ('', '') - tmp_file = StringIO.StringIO() + tmp_file = six.StringIO() with mock.patch('__builtin__.open') as mock_open: mock_open.return_value = contextlib.closing(tmp_file) self.assertEqual( @@ -175,7 +173,7 @@ class TestIetAdmDriver(tf.TargetDriverFixture): self.testvol['name']) def test_find_sid_cid_for_target(self): - tmp_file = StringIO.StringIO() + tmp_file = six.StringIO() tmp_file.write( 'tid:1 name:iqn.2010-10.org.openstack:volume-83c2e877-feed-46be-8435-77884fe55b45\n' # noqa ' sid:844427031282176 initiator:iqn.1994-05.com.redhat:5a6894679665\n' # noqa diff --git a/cinder/tests/unit/test_hds_iscsi.py b/cinder/tests/unit/test_hds_iscsi.py index 7377e4b44..1e6cb85a1 100644 --- a/cinder/tests/unit/test_hds_iscsi.py +++ b/cinder/tests/unit/test_hds_iscsi.py @@ -19,11 +19,11 @@ Self test for Hitachi Unified Storage (HUS-HNAS) platform. """ import os -import StringIO import tempfile import mock from oslo_log import log as logging +import six from cinder import exception from cinder import test @@ -329,18 +329,18 @@ class HNASiSCSIDriverTest(test.TestCase): def test_read_config(self, m_access, m_open): # Test exception when file is not found m_access.return_value = False - m_open.return_value = StringIO.StringIO(HNASCONF) + m_open.return_value = six.StringIO(HNASCONF) self.assertRaises(exception.NotFound, iscsi._read_config, '') # Test exception when config file has parsing errors # due to missing tag m_access.return_value = True - m_open.return_value = StringIO.StringIO(HNAS_WRONG_CONF1) + m_open.return_value = six.StringIO(HNAS_WRONG_CONF1) self.assertRaises(exception.ConfigNotFound, iscsi._read_config, '') # Test exception when config file has parsing errors # due to missing tag - m_open.return_value = StringIO.StringIO(HNAS_WRONG_CONF2) + m_open.return_value = six.StringIO(HNAS_WRONG_CONF2) self.configuration.hds_hnas_iscsi_config_file = '' self.assertRaises(exception.ParameterNotFound, iscsi._read_config, '') diff --git a/cinder/tests/unit/test_hds_nfs.py b/cinder/tests/unit/test_hds_nfs.py index 8785591c4..756d58ed5 100644 --- a/cinder/tests/unit/test_hds_nfs.py +++ b/cinder/tests/unit/test_hds_nfs.py @@ -15,11 +15,11 @@ # import os -import StringIO import tempfile import mock from oslo_log import log as logging +import six from cinder import exception from cinder import test @@ -191,18 +191,18 @@ class HDSNFSDriverTest(test.TestCase): def test_read_config(self, m_access, m_open): # Test exception when file is not found m_access.return_value = False - m_open.return_value = StringIO.StringIO(HNASCONF) + m_open.return_value = six.StringIO(HNASCONF) self.assertRaises(exception.NotFound, nfs._read_config, '') # Test exception when config file has parsing errors # due to missing tag m_access.return_value = True - m_open.return_value = StringIO.StringIO(HNAS_WRONG_CONF1) + m_open.return_value = six.StringIO(HNAS_WRONG_CONF1) self.assertRaises(exception.ConfigNotFound, nfs._read_config, '') # Test exception when config file has parsing errors # due to missing tag - m_open.return_value = StringIO.StringIO(HNAS_WRONG_CONF2) + m_open.return_value = six.StringIO(HNAS_WRONG_CONF2) self.configuration.hds_hnas_iscsi_config_file = '' self.assertRaises(exception.ParameterNotFound, nfs._read_config, '') diff --git a/cinder/tests/unit/test_quobyte.py b/cinder/tests/unit/test_quobyte.py index cdd4f005b..9635cf91a 100644 --- a/cinder/tests/unit/test_quobyte.py +++ b/cinder/tests/unit/test_quobyte.py @@ -18,7 +18,6 @@ import errno import os import six -import StringIO import traceback import mock @@ -130,7 +129,7 @@ class QuobyteDriverTestCase(test.TestCase): mock.patch('cinder.volume.drivers.quobyte.QuobyteDriver' '.read_proc_mount') as mock_open: # Content of /proc/mount (not mounted yet). - mock_open.return_value = StringIO.StringIO( + mock_open.return_value = six.StringIO( "/dev/sda5 / ext4 rw,relatime,data=ordered 0 0") self._driver._mount_quobyte(self.TEST_QUOBYTE_VOLUME, @@ -154,7 +153,7 @@ class QuobyteDriverTestCase(test.TestCase): mock.patch('cinder.volume.drivers.quobyte.QuobyteDriver' '.read_proc_mount') as mock_open: # Content of /proc/mount (already mounted). - mock_open.return_value = StringIO.StringIO( + mock_open.return_value = six.StringIO( "quobyte@%s %s fuse rw,nosuid,nodev,noatime,user_id=1000" ",group_id=100,default_permissions,allow_other 0 0" % (self.TEST_QUOBYTE_VOLUME, self.TEST_MNT_POINT)) @@ -180,7 +179,7 @@ class QuobyteDriverTestCase(test.TestCase): '.read_proc_mount') as mock_open, \ mock.patch('cinder.volume.drivers.quobyte.LOG') as mock_LOG: # Content of /proc/mount (empty). - mock_open.return_value = StringIO.StringIO() + mock_open.return_value = six.StringIO() mock_execute.side_effect = [None, putils.ProcessExecutionError( stderr='is busy or already mounted')] @@ -206,7 +205,7 @@ class QuobyteDriverTestCase(test.TestCase): with mock.patch.object(self._driver, '_execute') as mock_execute, \ mock.patch('cinder.volume.drivers.quobyte.QuobyteDriver' '.read_proc_mount') as mock_open: - mock_open.return_value = StringIO.StringIO() + mock_open.return_value = six.StringIO() mock_execute.side_effect = [ None, # mkdir putils.ProcessExecutionError( # mount diff --git a/cinder/volume/drivers/zfssa/restclient.py b/cinder/volume/drivers/zfssa/restclient.py index 8e90cd390..d8286a188 100644 --- a/cinder/volume/drivers/zfssa/restclient.py +++ b/cinder/volume/drivers/zfssa/restclient.py @@ -16,10 +16,10 @@ ZFS Storage Appliance REST API Client Programmatic Interface """ import json -import StringIO import time from oslo_log import log +import six from six.moves import http_client from six.moves import urllib @@ -226,7 +226,7 @@ class RestClientURL(object): :cmd_params args: The path part :cmd_params kwargs: The query part """ - buf = StringIO.StringIO() + buf = six.StringIO() query = "?" for arg in args: buf.write("/") -- 2.45.2