Merge "Get StringIO from six for Python 3 compatibility"

This commit is contained in:
Jenkins 2015-06-15 23:32:31 +00:00 committed by Gerrit Code Review
commit eebc694df2
6 changed files with 21 additions and 24 deletions

View File

@ -15,9 +15,9 @@
import contextlib import contextlib
import os import os
import StringIO
import mock import mock
import six
from cinder import context from cinder import context
from cinder.tests.unit.targets import targets_fixture as tf from cinder.tests.unit.targets import targets_fixture as tf
@ -50,7 +50,7 @@ class TestCxtAdmDriver(tf.TargetDriverFixture):
self.assertTrue(m_exec.called) self.assertTrue(m_exec.called)
def test_get_target_chap_auth(self): def test_get_target_chap_auth(self):
tmp_file = StringIO.StringIO() tmp_file = six.StringIO()
tmp_file.write( tmp_file.write(
'target:\n' 'target:\n'
' TargetName=iqn.2010-10.org.openstack:volume-83c2e877-feed-46be-8435-77884fe55b45\n' # noqa ' TargetName=iqn.2010-10.org.openstack:volume-83c2e877-feed-46be-8435-77884fe55b45\n' # noqa

View File

@ -12,11 +12,9 @@
import contextlib import contextlib
import StringIO
import mock import mock
from oslo_concurrency import processutils as putils from oslo_concurrency import processutils as putils
import six
from cinder import context from cinder import context
from cinder import exception from cinder import exception
@ -34,7 +32,7 @@ class TestIetAdmDriver(tf.TargetDriverFixture):
configuration=self.configuration) configuration=self.configuration)
def test_get_target(self): def test_get_target(self):
tmp_file = StringIO.StringIO() tmp_file = six.StringIO()
tmp_file.write( tmp_file.write(
'tid:1 name:iqn.2010-10.org.openstack:volume-83c2e877-feed-46be-8435-77884fe55b45\n' # noqa '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 ' 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('os.path.exists', return_value=True)
@mock.patch('cinder.utils.temporary_chown') @mock.patch('cinder.utils.temporary_chown')
def test_get_target_chap_auth(self, mock_chown, mock_exists): def test_get_target_chap_auth(self, mock_chown, mock_exists):
tmp_file = StringIO.StringIO() tmp_file = six.StringIO()
tmp_file.write( tmp_file.write(
'Target iqn.2010-10.org.openstack:volume-83c2e877-feed-46be-8435-77884fe55b45\n' # noqa 'Target iqn.2010-10.org.openstack:volume-83c2e877-feed-46be-8435-77884fe55b45\n' # noqa
' IncomingUser otzLy2UYbYfnP4zXLG5z 234Zweo38VGBBvrpK9nt\n' ' IncomingUser otzLy2UYbYfnP4zXLG5z 234Zweo38VGBBvrpK9nt\n'
@ -87,7 +85,7 @@ class TestIetAdmDriver(tf.TargetDriverFixture):
def test_create_iscsi_target(self, mock_chown, mock_exists, def test_create_iscsi_target(self, mock_chown, mock_exists,
mock_execute, mock_get_targ): mock_execute, mock_get_targ):
mock_execute.return_value = ('', '') mock_execute.return_value = ('', '')
tmp_file = StringIO.StringIO() tmp_file = six.StringIO()
with mock.patch('__builtin__.open') as mock_open: with mock.patch('__builtin__.open') as mock_open:
mock_open.return_value = contextlib.closing(tmp_file) mock_open.return_value = contextlib.closing(tmp_file)
self.assertEqual( self.assertEqual(
@ -175,7 +173,7 @@ class TestIetAdmDriver(tf.TargetDriverFixture):
self.testvol['name']) self.testvol['name'])
def test_find_sid_cid_for_target(self): def test_find_sid_cid_for_target(self):
tmp_file = StringIO.StringIO() tmp_file = six.StringIO()
tmp_file.write( tmp_file.write(
'tid:1 name:iqn.2010-10.org.openstack:volume-83c2e877-feed-46be-8435-77884fe55b45\n' # noqa '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 ' sid:844427031282176 initiator:iqn.1994-05.com.redhat:5a6894679665\n' # noqa

View File

@ -19,11 +19,11 @@ Self test for Hitachi Unified Storage (HUS-HNAS) platform.
""" """
import os import os
import StringIO
import tempfile import tempfile
import mock import mock
from oslo_log import log as logging from oslo_log import log as logging
import six
from cinder import exception from cinder import exception
from cinder import test from cinder import test
@ -329,18 +329,18 @@ class HNASiSCSIDriverTest(test.TestCase):
def test_read_config(self, m_access, m_open): def test_read_config(self, m_access, m_open):
# Test exception when file is not found # Test exception when file is not found
m_access.return_value = False 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, '') self.assertRaises(exception.NotFound, iscsi._read_config, '')
# Test exception when config file has parsing errors # Test exception when config file has parsing errors
# due to missing <svc> tag # due to missing <svc> tag
m_access.return_value = True 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, '') self.assertRaises(exception.ConfigNotFound, iscsi._read_config, '')
# Test exception when config file has parsing errors # Test exception when config file has parsing errors
# due to missing <hdp> tag # due to missing <hdp> 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.configuration.hds_hnas_iscsi_config_file = ''
self.assertRaises(exception.ParameterNotFound, iscsi._read_config, '') self.assertRaises(exception.ParameterNotFound, iscsi._read_config, '')

View File

@ -15,11 +15,11 @@
# #
import os import os
import StringIO
import tempfile import tempfile
import mock import mock
from oslo_log import log as logging from oslo_log import log as logging
import six
from cinder import exception from cinder import exception
from cinder import test from cinder import test
@ -191,18 +191,18 @@ class HDSNFSDriverTest(test.TestCase):
def test_read_config(self, m_access, m_open): def test_read_config(self, m_access, m_open):
# Test exception when file is not found # Test exception when file is not found
m_access.return_value = False 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, '') self.assertRaises(exception.NotFound, nfs._read_config, '')
# Test exception when config file has parsing errors # Test exception when config file has parsing errors
# due to missing <svc> tag # due to missing <svc> tag
m_access.return_value = True 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, '') self.assertRaises(exception.ConfigNotFound, nfs._read_config, '')
# Test exception when config file has parsing errors # Test exception when config file has parsing errors
# due to missing <hdp> tag # due to missing <hdp> 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.configuration.hds_hnas_iscsi_config_file = ''
self.assertRaises(exception.ParameterNotFound, nfs._read_config, '') self.assertRaises(exception.ParameterNotFound, nfs._read_config, '')

View File

@ -18,7 +18,6 @@
import errno import errno
import os import os
import six import six
import StringIO
import traceback import traceback
import mock import mock
@ -130,7 +129,7 @@ class QuobyteDriverTestCase(test.TestCase):
mock.patch('cinder.volume.drivers.quobyte.QuobyteDriver' mock.patch('cinder.volume.drivers.quobyte.QuobyteDriver'
'.read_proc_mount') as mock_open: '.read_proc_mount') as mock_open:
# Content of /proc/mount (not mounted yet). # 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") "/dev/sda5 / ext4 rw,relatime,data=ordered 0 0")
self._driver._mount_quobyte(self.TEST_QUOBYTE_VOLUME, self._driver._mount_quobyte(self.TEST_QUOBYTE_VOLUME,
@ -154,7 +153,7 @@ class QuobyteDriverTestCase(test.TestCase):
mock.patch('cinder.volume.drivers.quobyte.QuobyteDriver' mock.patch('cinder.volume.drivers.quobyte.QuobyteDriver'
'.read_proc_mount') as mock_open: '.read_proc_mount') as mock_open:
# Content of /proc/mount (already mounted). # 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" "quobyte@%s %s fuse rw,nosuid,nodev,noatime,user_id=1000"
",group_id=100,default_permissions,allow_other 0 0" ",group_id=100,default_permissions,allow_other 0 0"
% (self.TEST_QUOBYTE_VOLUME, self.TEST_MNT_POINT)) % (self.TEST_QUOBYTE_VOLUME, self.TEST_MNT_POINT))
@ -180,7 +179,7 @@ class QuobyteDriverTestCase(test.TestCase):
'.read_proc_mount') as mock_open, \ '.read_proc_mount') as mock_open, \
mock.patch('cinder.volume.drivers.quobyte.LOG') as mock_LOG: mock.patch('cinder.volume.drivers.quobyte.LOG') as mock_LOG:
# Content of /proc/mount (empty). # Content of /proc/mount (empty).
mock_open.return_value = StringIO.StringIO() mock_open.return_value = six.StringIO()
mock_execute.side_effect = [None, putils.ProcessExecutionError( mock_execute.side_effect = [None, putils.ProcessExecutionError(
stderr='is busy or already mounted')] stderr='is busy or already mounted')]
@ -206,7 +205,7 @@ class QuobyteDriverTestCase(test.TestCase):
with mock.patch.object(self._driver, '_execute') as mock_execute, \ with mock.patch.object(self._driver, '_execute') as mock_execute, \
mock.patch('cinder.volume.drivers.quobyte.QuobyteDriver' mock.patch('cinder.volume.drivers.quobyte.QuobyteDriver'
'.read_proc_mount') as mock_open: '.read_proc_mount') as mock_open:
mock_open.return_value = StringIO.StringIO() mock_open.return_value = six.StringIO()
mock_execute.side_effect = [ mock_execute.side_effect = [
None, # mkdir None, # mkdir
putils.ProcessExecutionError( # mount putils.ProcessExecutionError( # mount

View File

@ -16,10 +16,10 @@ ZFS Storage Appliance REST API Client Programmatic Interface
""" """
import json import json
import StringIO
import time import time
from oslo_log import log from oslo_log import log
import six
from six.moves import http_client from six.moves import http_client
from six.moves import urllib from six.moves import urllib
@ -226,7 +226,7 @@ class RestClientURL(object):
:cmd_params args: The path part :cmd_params args: The path part
:cmd_params kwargs: The query part :cmd_params kwargs: The query part
""" """
buf = StringIO.StringIO() buf = six.StringIO()
query = "?" query = "?"
for arg in args: for arg in args:
buf.write("/") buf.write("/")