Remove six
Mostly a find-replace job. Let's do this now so we don't have to carry it for the next decade. Change-Id: I7bef9fb7c6895f746cee1aca6522786f38b9857c Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
This commit is contained in:
parent
9dee28ae6c
commit
c4c44bcb2d
@ -91,7 +91,6 @@ requestsexceptions==1.2.0
|
||||
rfc3986==0.3.1
|
||||
Routes==2.3.1
|
||||
simplejson==3.5.1
|
||||
six==1.10.0
|
||||
smmap==0.9.0
|
||||
statsd==3.2.1
|
||||
stevedore==1.20.0
|
||||
|
@ -29,7 +29,6 @@ import threading
|
||||
from oslo_utils import reflection
|
||||
from oslo_utils import strutils
|
||||
import requests
|
||||
import six
|
||||
|
||||
from novaclient import exceptions
|
||||
from novaclient import utils
|
||||
@ -388,12 +387,9 @@ class Manager(HookableMixin):
|
||||
return StrWithMeta(body, resp)
|
||||
|
||||
def convert_into_with_meta(self, item, resp):
|
||||
if isinstance(item, six.string_types):
|
||||
if six.PY2 and isinstance(item, six.text_type):
|
||||
return UnicodeWithMeta(item, resp)
|
||||
else:
|
||||
return StrWithMeta(item, resp)
|
||||
elif isinstance(item, six.binary_type):
|
||||
if isinstance(item, str):
|
||||
return StrWithMeta(item, resp)
|
||||
elif isinstance(item, bytes):
|
||||
return BytesWithMeta(item, resp)
|
||||
elif isinstance(item, list):
|
||||
return ListWithMeta(item, resp)
|
||||
@ -405,8 +401,7 @@ class Manager(HookableMixin):
|
||||
return DictWithMeta(item, resp)
|
||||
|
||||
|
||||
@six.add_metaclass(abc.ABCMeta)
|
||||
class ManagerWithFind(Manager):
|
||||
class ManagerWithFind(Manager, metaclass=abc.ABCMeta):
|
||||
"""Like a `Manager`, but with additional `find()`/`findall()` methods."""
|
||||
|
||||
@abc.abstractmethod
|
||||
@ -560,20 +555,10 @@ class StrWithMeta(str, RequestIdMixin):
|
||||
self.append_request_ids(resp)
|
||||
|
||||
|
||||
class BytesWithMeta(six.binary_type, RequestIdMixin):
|
||||
class BytesWithMeta(bytes, RequestIdMixin):
|
||||
def __new__(cls, value, resp):
|
||||
return super(BytesWithMeta, cls).__new__(cls, value)
|
||||
|
||||
def __init__(self, values, resp):
|
||||
self.request_ids_setup()
|
||||
self.append_request_ids(resp)
|
||||
|
||||
|
||||
if six.PY2:
|
||||
class UnicodeWithMeta(six.text_type, RequestIdMixin):
|
||||
def __new__(cls, value, resp):
|
||||
return super(UnicodeWithMeta, cls).__new__(cls, value)
|
||||
|
||||
def __init__(self, values, resp):
|
||||
self.request_ids_setup()
|
||||
self.append_request_ids(resp)
|
||||
|
@ -16,8 +16,6 @@
|
||||
import base64
|
||||
import subprocess
|
||||
|
||||
import six
|
||||
|
||||
|
||||
class DecryptionFailure(Exception):
|
||||
pass
|
||||
@ -38,6 +36,6 @@ def decrypt_password(private_key, password):
|
||||
if proc.returncode:
|
||||
raise DecryptionFailure(err)
|
||||
|
||||
if not six.PY2 and isinstance(out, bytes):
|
||||
if isinstance(out, bytes):
|
||||
return out.decode('utf-8')
|
||||
return out
|
||||
|
@ -27,7 +27,6 @@ from keystoneauth1 import loading
|
||||
from oslo_utils import encodeutils
|
||||
from oslo_utils import importutils
|
||||
from oslo_utils import strutils
|
||||
import six
|
||||
|
||||
import novaclient
|
||||
from novaclient import api_versions
|
||||
@ -123,7 +122,7 @@ class DeprecatedAction(argparse.Action):
|
||||
# option
|
||||
self.real_action_args = False
|
||||
self.real_action = None
|
||||
elif real_action is None or isinstance(real_action, six.string_types):
|
||||
elif real_action is None or isinstance(real_action, str):
|
||||
# Specified by string (or None); we have to have a parser
|
||||
# to look up the actual action, so defer to later
|
||||
self.real_action_args = (option_strings, dest, help, kwargs)
|
||||
@ -810,10 +809,7 @@ def main():
|
||||
OpenStackComputeShell().main(argv)
|
||||
except Exception as exc:
|
||||
logger.debug(exc, exc_info=1)
|
||||
if six.PY2:
|
||||
message = encodeutils.safe_encode(six.text_type(exc))
|
||||
else:
|
||||
message = encodeutils.exception_to_unicode(exc)
|
||||
message = encodeutils.exception_to_unicode(exc)
|
||||
print("ERROR (%(type)s): %(msg)s" % {
|
||||
'type': exc.__class__.__name__,
|
||||
'msg': message},
|
||||
|
@ -10,7 +10,8 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from six.moves.urllib import parse
|
||||
from urllib import parse
|
||||
|
||||
import tempest.lib.cli.base
|
||||
|
||||
from novaclient import client
|
||||
|
@ -10,8 +10,6 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import six
|
||||
|
||||
from novaclient.tests.functional import base
|
||||
from novaclient import utils
|
||||
|
||||
@ -41,4 +39,4 @@ class TestHypervisors(base.ClientTestBase):
|
||||
'Expected hypervisor.service.id to be an integer.')
|
||||
|
||||
def test_list(self):
|
||||
self._test_list(six.text_type)
|
||||
self._test_list(str)
|
||||
|
@ -12,7 +12,6 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import six
|
||||
from tempest.lib import exceptions
|
||||
|
||||
from novaclient.tests.functional import base
|
||||
@ -40,7 +39,7 @@ class TestBlockDeviceTaggingCLIError(base.ClientTestBase):
|
||||
self.assertIn("ERROR (CommandError): "
|
||||
"'tag' in block device mapping is not supported "
|
||||
"in API version %s." % self.COMPUTE_API_VERSION,
|
||||
six.text_type(e))
|
||||
str(e))
|
||||
else:
|
||||
server_id = self._get_value_from_the_table(output, 'id')
|
||||
self.client.servers.delete(server_id)
|
||||
@ -67,7 +66,7 @@ class TestNICDeviceTaggingCLIError(base.ClientTestBase):
|
||||
'net-uuid': self.network.id,
|
||||
'image': self.image.id}))
|
||||
except exceptions.CommandFailed as e:
|
||||
self.assertIn("Invalid nic argument", six.text_type(e))
|
||||
self.assertIn('Invalid nic argument', str(e))
|
||||
else:
|
||||
server_id = self._get_value_from_the_table(output, 'id')
|
||||
self.client.servers.delete(server_id)
|
||||
|
@ -14,7 +14,6 @@ import time
|
||||
|
||||
from oslo_utils import timeutils
|
||||
from oslo_utils import uuidutils
|
||||
import six
|
||||
from tempest.lib import exceptions
|
||||
|
||||
from novaclient.tests.functional import base
|
||||
@ -28,7 +27,7 @@ class TestInstanceActionCLI(base.ClientTestBase):
|
||||
try:
|
||||
self.nova("%s %s" % (cmd, args))
|
||||
except exceptions.CommandFailed as e:
|
||||
self.assertIn("ERROR (NotFound):", six.text_type(e))
|
||||
self.assertIn("ERROR (NotFound):", str(e))
|
||||
else:
|
||||
self.fail("%s is not failed on non existing instance." % cmd)
|
||||
|
||||
|
@ -10,8 +10,9 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from urllib import parse
|
||||
|
||||
import fixtures
|
||||
from six.moves.urllib import parse
|
||||
|
||||
from novaclient.tests.unit.v2 import fakes
|
||||
|
||||
|
@ -10,8 +10,9 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from urllib import parse
|
||||
|
||||
from oslo_utils import encodeutils
|
||||
from six.moves.urllib import parse
|
||||
|
||||
from novaclient import api_versions
|
||||
from novaclient.tests.unit.fixture_data import base
|
||||
|
@ -12,7 +12,6 @@
|
||||
# under the License.
|
||||
|
||||
import requests
|
||||
import six
|
||||
|
||||
from novaclient import api_versions
|
||||
from novaclient import base
|
||||
@ -148,14 +147,3 @@ class BytesWithMetaTest(utils.TestCase):
|
||||
# Check request_ids attribute is added to obj
|
||||
self.assertTrue(hasattr(obj, 'request_ids'))
|
||||
self.assertEqual(fakes.FAKE_REQUEST_ID_LIST, obj.request_ids)
|
||||
|
||||
|
||||
if six.PY2:
|
||||
class UnicodeWithMetaTest(utils.TestCase):
|
||||
def test_unicode_with_meta(self):
|
||||
resp = create_response_obj_with_header()
|
||||
obj = base.UnicodeWithMeta(u'test-unicode', resp)
|
||||
self.assertEqual(u'test-unicode', obj)
|
||||
# Check request_ids attribute is added to obj
|
||||
self.assertTrue(hasattr(obj, 'request_ids'))
|
||||
self.assertEqual(fakes.FAKE_REQUEST_ID_LIST, obj.request_ids)
|
||||
|
@ -13,6 +13,7 @@
|
||||
|
||||
import argparse
|
||||
import distutils.version as dist_version
|
||||
import io
|
||||
import re
|
||||
import sys
|
||||
|
||||
@ -22,7 +23,6 @@ from keystoneauth1 import fixture
|
||||
import mock
|
||||
import prettytable
|
||||
import requests_mock
|
||||
import six
|
||||
from testtools import matchers
|
||||
|
||||
from novaclient import api_versions
|
||||
@ -212,7 +212,7 @@ class DeprecatedActionTest(utils.TestCase):
|
||||
action.assert_called_once_with(
|
||||
'option_strings', 'dest', help='Deprecated', a=1, b=2, c=3)
|
||||
|
||||
@mock.patch.object(sys, 'stderr', six.StringIO())
|
||||
@mock.patch.object(sys, 'stderr', io.StringIO())
|
||||
def test_get_action_nolookup(self):
|
||||
action_class = mock.Mock()
|
||||
parser = mock.Mock(**{
|
||||
@ -230,7 +230,7 @@ class DeprecatedActionTest(utils.TestCase):
|
||||
self.assertFalse(action_class.called)
|
||||
self.assertEqual(sys.stderr.getvalue(), '')
|
||||
|
||||
@mock.patch.object(sys, 'stderr', six.StringIO())
|
||||
@mock.patch.object(sys, 'stderr', io.StringIO())
|
||||
def test_get_action_lookup_noresult(self):
|
||||
parser = mock.Mock(**{
|
||||
'_registry_get.return_value': None,
|
||||
@ -248,7 +248,7 @@ class DeprecatedActionTest(utils.TestCase):
|
||||
'WARNING: Programming error: Unknown real action '
|
||||
'"store"\n')
|
||||
|
||||
@mock.patch.object(sys, 'stderr', six.StringIO())
|
||||
@mock.patch.object(sys, 'stderr', io.StringIO())
|
||||
def test_get_action_lookup_withresult(self):
|
||||
action_class = mock.Mock()
|
||||
parser = mock.Mock(**{
|
||||
@ -267,7 +267,7 @@ class DeprecatedActionTest(utils.TestCase):
|
||||
'option_strings', 'dest', help='Deprecated', const=1)
|
||||
self.assertEqual(sys.stderr.getvalue(), '')
|
||||
|
||||
@mock.patch.object(sys, 'stderr', six.StringIO())
|
||||
@mock.patch.object(sys, 'stderr', io.StringIO())
|
||||
@mock.patch.object(novaclient.shell.DeprecatedAction, '_get_action')
|
||||
def test_call_unemitted_nouse(self, mock_get_action):
|
||||
obj = novaclient.shell.DeprecatedAction(
|
||||
@ -282,7 +282,7 @@ class DeprecatedActionTest(utils.TestCase):
|
||||
self.assertEqual(sys.stderr.getvalue(),
|
||||
'WARNING: Option "option_string" is deprecated\n')
|
||||
|
||||
@mock.patch.object(sys, 'stderr', six.StringIO())
|
||||
@mock.patch.object(sys, 'stderr', io.StringIO())
|
||||
@mock.patch.object(novaclient.shell.DeprecatedAction, '_get_action')
|
||||
def test_call_unemitted_withuse(self, mock_get_action):
|
||||
obj = novaclient.shell.DeprecatedAction(
|
||||
@ -298,7 +298,7 @@ class DeprecatedActionTest(utils.TestCase):
|
||||
'WARNING: Option "option_string" is deprecated; '
|
||||
'use this instead\n')
|
||||
|
||||
@mock.patch.object(sys, 'stderr', six.StringIO())
|
||||
@mock.patch.object(sys, 'stderr', io.StringIO())
|
||||
@mock.patch.object(novaclient.shell.DeprecatedAction, '_get_action')
|
||||
def test_call_emitted_nouse(self, mock_get_action):
|
||||
obj = novaclient.shell.DeprecatedAction(
|
||||
@ -313,7 +313,7 @@ class DeprecatedActionTest(utils.TestCase):
|
||||
'parser', 'namespace', 'values', 'option_string')
|
||||
self.assertEqual(sys.stderr.getvalue(), '')
|
||||
|
||||
@mock.patch.object(sys, 'stderr', six.StringIO())
|
||||
@mock.patch.object(sys, 'stderr', io.StringIO())
|
||||
@mock.patch.object(novaclient.shell.DeprecatedAction, '_get_action')
|
||||
def test_call_emitted_withuse(self, mock_get_action):
|
||||
obj = novaclient.shell.DeprecatedAction(
|
||||
@ -393,8 +393,8 @@ class ShellTest(utils.TestCase):
|
||||
orig = sys.stdout
|
||||
orig_stderr = sys.stderr
|
||||
try:
|
||||
sys.stdout = six.StringIO()
|
||||
sys.stderr = six.StringIO()
|
||||
sys.stdout = io.StringIO()
|
||||
sys.stderr = io.StringIO()
|
||||
_shell = novaclient.shell.OpenStackComputeShell()
|
||||
_shell.main(argstr.split())
|
||||
except SystemExit:
|
||||
@ -622,8 +622,8 @@ class ShellTest(utils.TestCase):
|
||||
'unknown', 'compute', self.mock_client)
|
||||
|
||||
@mock.patch('sys.argv', ['nova'])
|
||||
@mock.patch('sys.stdout', six.StringIO())
|
||||
@mock.patch('sys.stderr', six.StringIO())
|
||||
@mock.patch('sys.stdout', io.StringIO())
|
||||
@mock.patch('sys.stderr', io.StringIO())
|
||||
def test_main_noargs(self):
|
||||
# Ensure that main works with no command-line arguments
|
||||
try:
|
||||
@ -761,7 +761,7 @@ class ShellTest(utils.TestCase):
|
||||
def test_main_error_handling(self, mock_compute_shell):
|
||||
class MyException(Exception):
|
||||
pass
|
||||
with mock.patch('sys.stderr', six.StringIO()):
|
||||
with mock.patch('sys.stderr', io.StringIO()):
|
||||
mock_compute_shell.side_effect = MyException('message')
|
||||
self.assertRaises(SystemExit, novaclient.shell.main)
|
||||
err = sys.stderr.getvalue()
|
||||
|
@ -11,12 +11,11 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import io
|
||||
import sys
|
||||
from urllib import parse
|
||||
|
||||
import mock
|
||||
from oslo_utils import encodeutils
|
||||
import six
|
||||
from six.moves.urllib import parse
|
||||
|
||||
from novaclient import base
|
||||
from novaclient import exceptions
|
||||
@ -177,7 +176,7 @@ class _FakeResult(object):
|
||||
|
||||
|
||||
class PrintResultTestCase(test_utils.TestCase):
|
||||
@mock.patch('sys.stdout', six.StringIO())
|
||||
@mock.patch('sys.stdout', io.StringIO())
|
||||
def test_print_dict(self):
|
||||
dict = {'key': 'value'}
|
||||
utils.print_dict(dict)
|
||||
@ -188,7 +187,7 @@ class PrintResultTestCase(test_utils.TestCase):
|
||||
'+----------+-------+\n',
|
||||
sys.stdout.getvalue())
|
||||
|
||||
@mock.patch('sys.stdout', six.StringIO())
|
||||
@mock.patch('sys.stdout', io.StringIO())
|
||||
def test_print_dict_wrap(self):
|
||||
dict = {'key1': 'not wrapped',
|
||||
'key2': 'this will be wrapped'}
|
||||
@ -202,7 +201,7 @@ class PrintResultTestCase(test_utils.TestCase):
|
||||
'+----------+--------------+\n',
|
||||
sys.stdout.getvalue())
|
||||
|
||||
@mock.patch('sys.stdout', six.StringIO())
|
||||
@mock.patch('sys.stdout', io.StringIO())
|
||||
def test_print_list_sort_by_str(self):
|
||||
objs = [_FakeResult("k1", 1),
|
||||
_FakeResult("k3", 2),
|
||||
@ -219,7 +218,7 @@ class PrintResultTestCase(test_utils.TestCase):
|
||||
'+------+-------+\n',
|
||||
sys.stdout.getvalue())
|
||||
|
||||
@mock.patch('sys.stdout', six.StringIO())
|
||||
@mock.patch('sys.stdout', io.StringIO())
|
||||
def test_print_list_sort_by_integer(self):
|
||||
objs = [_FakeResult("k1", 1),
|
||||
_FakeResult("k3", 2),
|
||||
@ -236,14 +235,11 @@ class PrintResultTestCase(test_utils.TestCase):
|
||||
'+------+-------+\n',
|
||||
sys.stdout.getvalue())
|
||||
|
||||
@mock.patch('sys.stdout', six.StringIO())
|
||||
@mock.patch('sys.stdout', io.StringIO())
|
||||
def test_print_unicode_list(self):
|
||||
objs = [_FakeResult("k", u'\u2026')]
|
||||
utils.print_list(objs, ["Name", "Value"])
|
||||
if six.PY3:
|
||||
s = u'\u2026'
|
||||
else:
|
||||
s = encodeutils.safe_encode(u'\u2026')
|
||||
s = u'\u2026'
|
||||
self.assertEqual('+------+-------+\n'
|
||||
'| Name | Value |\n'
|
||||
'+------+-------+\n'
|
||||
@ -252,7 +248,7 @@ class PrintResultTestCase(test_utils.TestCase):
|
||||
sys.stdout.getvalue())
|
||||
|
||||
# without sorting
|
||||
@mock.patch('sys.stdout', six.StringIO())
|
||||
@mock.patch('sys.stdout', io.StringIO())
|
||||
def test_print_list_sort_by_none(self):
|
||||
objs = [_FakeResult("k1", 1),
|
||||
_FakeResult("k3", 3),
|
||||
@ -269,7 +265,7 @@ class PrintResultTestCase(test_utils.TestCase):
|
||||
'+------+-------+\n',
|
||||
sys.stdout.getvalue())
|
||||
|
||||
@mock.patch('sys.stdout', six.StringIO())
|
||||
@mock.patch('sys.stdout', io.StringIO())
|
||||
def test_print_dict_dictionary(self):
|
||||
dict = {'k': {'foo': 'bar'}}
|
||||
utils.print_dict(dict)
|
||||
@ -280,7 +276,7 @@ class PrintResultTestCase(test_utils.TestCase):
|
||||
'+----------+----------------+\n',
|
||||
sys.stdout.getvalue())
|
||||
|
||||
@mock.patch('sys.stdout', six.StringIO())
|
||||
@mock.patch('sys.stdout', io.StringIO())
|
||||
def test_print_dict_list_dictionary(self):
|
||||
dict = {'k': [{'foo': 'bar'}]}
|
||||
utils.print_dict(dict)
|
||||
@ -291,7 +287,7 @@ class PrintResultTestCase(test_utils.TestCase):
|
||||
'+----------+------------------+\n',
|
||||
sys.stdout.getvalue())
|
||||
|
||||
@mock.patch('sys.stdout', six.StringIO())
|
||||
@mock.patch('sys.stdout', io.StringIO())
|
||||
def test_print_dict_list(self):
|
||||
dict = {'k': ['foo', 'bar']}
|
||||
utils.print_dict(dict)
|
||||
@ -302,7 +298,7 @@ class PrintResultTestCase(test_utils.TestCase):
|
||||
'+----------+----------------+\n',
|
||||
sys.stdout.getvalue())
|
||||
|
||||
@mock.patch('sys.stdout', six.StringIO())
|
||||
@mock.patch('sys.stdout', io.StringIO())
|
||||
def test_print_large_dict_list(self):
|
||||
dict = {'k': ['foo1', 'bar1', 'foo2', 'bar2',
|
||||
'foo3', 'bar3', 'foo4', 'bar4']}
|
||||
@ -316,14 +312,11 @@ class PrintResultTestCase(test_utils.TestCase):
|
||||
'+----------+------------------------------------------+\n',
|
||||
sys.stdout.getvalue())
|
||||
|
||||
@mock.patch('sys.stdout', six.StringIO())
|
||||
@mock.patch('sys.stdout', io.StringIO())
|
||||
def test_print_unicode_dict(self):
|
||||
dict = {'k': u'\u2026'}
|
||||
utils.print_dict(dict)
|
||||
if six.PY3:
|
||||
s = u'\u2026'
|
||||
else:
|
||||
s = encodeutils.safe_encode(u'\u2026')
|
||||
s = u'\u2026'
|
||||
self.assertEqual('+----------+-------+\n'
|
||||
'| Property | Value |\n'
|
||||
'+----------+-------+\n'
|
||||
@ -403,7 +396,7 @@ class DoActionOnManyTestCase(test_utils.TestCase):
|
||||
def test_do_action_on_many_last_fails(self):
|
||||
self._test_do_action_on_many([None, Exception()], fail=True)
|
||||
|
||||
@mock.patch('sys.stdout', new_callable=six.StringIO)
|
||||
@mock.patch('sys.stdout', new_callable=io.StringIO)
|
||||
def _test_do_action_on_many_resource_string(
|
||||
self, resource, expected_string, mock_stdout):
|
||||
utils.do_action_on_many(mock.Mock(), [resource], 'success with %s',
|
||||
@ -452,9 +445,8 @@ class PrepareQueryStringTestCase(test_utils.TestCase):
|
||||
def setUp(self):
|
||||
super(PrepareQueryStringTestCase, self).setUp()
|
||||
self.ustr = b'?\xd0\xbf=1&\xd1\x80=2'
|
||||
if six.PY3:
|
||||
# in py3 real unicode symbols will be urlencoded
|
||||
self.ustr = self.ustr.decode('utf8')
|
||||
# in py3 real unicode symbols will be urlencoded
|
||||
self.ustr = self.ustr.decode('utf8')
|
||||
self.cases = (
|
||||
({}, ''),
|
||||
(None, ''),
|
||||
|
@ -18,7 +18,6 @@ import mock
|
||||
from oslo_serialization import jsonutils
|
||||
import requests
|
||||
from requests_mock.contrib import fixture as requests_mock_fixture
|
||||
import six
|
||||
import testscenarios
|
||||
import testtools
|
||||
|
||||
@ -99,9 +98,9 @@ class FixturedTestCase(testscenarios.TestWithScenarios, TestCase):
|
||||
|
||||
if body:
|
||||
req_data = self.requests_mock.last_request.body
|
||||
if isinstance(req_data, six.binary_type):
|
||||
if isinstance(req_data, bytes):
|
||||
req_data = req_data.decode('utf-8')
|
||||
if not isinstance(body, six.string_types):
|
||||
if not isinstance(body, str):
|
||||
# json load if the input body to match against is not a string
|
||||
req_data = jsonutils.loads(req_data)
|
||||
self.assertEqual(body, req_data)
|
||||
|
@ -17,11 +17,10 @@
|
||||
import copy
|
||||
import datetime
|
||||
import re
|
||||
from urllib import parse
|
||||
|
||||
import mock
|
||||
from oslo_utils import strutils
|
||||
import six
|
||||
from six.moves.urllib import parse
|
||||
|
||||
import novaclient
|
||||
from novaclient import api_versions
|
||||
@ -1528,158 +1527,146 @@ class FakeSessionClient(base_client.SessionClient):
|
||||
# Tenant Usage
|
||||
#
|
||||
def get_os_simple_tenant_usage(self, **kw):
|
||||
return (200, FAKE_RESPONSE_HEADERS,
|
||||
{six.u('tenant_usages'): [{
|
||||
six.u('total_memory_mb_usage'): 25451.762807466665,
|
||||
six.u('total_vcpus_usage'): 49.71047423333333,
|
||||
six.u('total_hours'): 49.71047423333333,
|
||||
six.u('tenant_id'):
|
||||
six.u('7b0a1d73f8fb41718f3343c207597869'),
|
||||
six.u('stop'): six.u('2012-01-22 19:48:41.750722'),
|
||||
six.u('server_usages'): [{
|
||||
six.u('hours'): 49.71047423333333,
|
||||
six.u('uptime'): 27035,
|
||||
six.u('local_gb'): 0,
|
||||
six.u('ended_at'): None,
|
||||
six.u('name'): six.u('f15image1'),
|
||||
six.u('tenant_id'):
|
||||
six.u('7b0a1d73f8fb41718f3343c207597869'),
|
||||
six.u('instance_id'):
|
||||
six.u('f079e394-1111-457b-b350-bb5ecc685cdd'),
|
||||
six.u('vcpus'): 1,
|
||||
six.u('memory_mb'): 512,
|
||||
six.u('state'): six.u('active'),
|
||||
six.u('flavor'): six.u('m1.tiny'),
|
||||
six.u('started_at'):
|
||||
six.u('2012-01-20 18:06:06.479998')}],
|
||||
six.u('start'): six.u('2011-12-25 19:48:41.750687'),
|
||||
six.u('total_local_gb_usage'): 0.0}]})
|
||||
return (200, FAKE_RESPONSE_HEADERS, {'tenant_usages': [{
|
||||
'total_memory_mb_usage': 25451.762807466665,
|
||||
'total_vcpus_usage': 49.71047423333333,
|
||||
'total_hours': 49.71047423333333,
|
||||
'tenant_id': '7b0a1d73f8fb41718f3343c207597869',
|
||||
'stop': '2012-01-22 19:48:41.750722',
|
||||
'server_usages': [{
|
||||
'hours': 49.71047423333333,
|
||||
'uptime': 27035,
|
||||
'local_gb': 0,
|
||||
'ended_at': None,
|
||||
'name': 'f15image1',
|
||||
'tenant_id': '7b0a1d73f8fb41718f3343c207597869',
|
||||
'instance_id': 'f079e394-1111-457b-b350-bb5ecc685cdd',
|
||||
'vcpus': 1,
|
||||
'memory_mb': 512,
|
||||
'state': 'active',
|
||||
'flavor': 'm1.tiny',
|
||||
'started_at': '2012-01-20 18:06:06.479998',
|
||||
}],
|
||||
'start': '2011-12-25 19:48:41.750687',
|
||||
'total_local_gb_usage': 0.0}]})
|
||||
|
||||
def get_os_simple_tenant_usage_next(self, **kw):
|
||||
return (200, FAKE_RESPONSE_HEADERS,
|
||||
{six.u('tenant_usages'): [{
|
||||
six.u('total_memory_mb_usage'): 25451.762807466665,
|
||||
six.u('total_vcpus_usage'): 49.71047423333333,
|
||||
six.u('total_hours'): 49.71047423333333,
|
||||
six.u('tenant_id'):
|
||||
six.u('7b0a1d73f8fb41718f3343c207597869'),
|
||||
six.u('stop'): six.u('2012-01-22 19:48:41.750722'),
|
||||
six.u('server_usages'): [{
|
||||
six.u('hours'): 49.71047423333333,
|
||||
six.u('uptime'): 27035,
|
||||
six.u('local_gb'): 0,
|
||||
six.u('ended_at'): None,
|
||||
six.u('name'): six.u('f15image1'),
|
||||
six.u('tenant_id'):
|
||||
six.u('7b0a1d73f8fb41718f3343c207597869'),
|
||||
six.u('instance_id'):
|
||||
six.u('f079e394-2222-457b-b350-bb5ecc685cdd'),
|
||||
six.u('vcpus'): 1,
|
||||
six.u('memory_mb'): 512,
|
||||
six.u('state'): six.u('active'),
|
||||
six.u('flavor'): six.u('m1.tiny'),
|
||||
six.u('started_at'):
|
||||
six.u('2012-01-20 18:06:06.479998')}],
|
||||
six.u('start'): six.u('2011-12-25 19:48:41.750687'),
|
||||
six.u('total_local_gb_usage'): 0.0}]})
|
||||
return (200, FAKE_RESPONSE_HEADERS, {'tenant_usages': [{
|
||||
'total_memory_mb_usage': 25451.762807466665,
|
||||
'total_vcpus_usage': 49.71047423333333,
|
||||
'total_hours': 49.71047423333333,
|
||||
'tenant_id': '7b0a1d73f8fb41718f3343c207597869',
|
||||
'stop': '2012-01-22 19:48:41.750722',
|
||||
'server_usages': [{
|
||||
'hours': 49.71047423333333,
|
||||
'uptime': 27035,
|
||||
'local_gb': 0,
|
||||
'ended_at': None,
|
||||
'name': 'f15image1',
|
||||
'tenant_id': '7b0a1d73f8fb41718f3343c207597869',
|
||||
'instance_id': 'f079e394-2222-457b-b350-bb5ecc685cdd',
|
||||
'vcpus': 1,
|
||||
'memory_mb': 512,
|
||||
'state': 'active',
|
||||
'flavor': 'm1.tiny',
|
||||
'started_at': '2012-01-20 18:06:06.479998',
|
||||
}],
|
||||
'start': '2011-12-25 19:48:41.750687',
|
||||
'total_local_gb_usage': 0.0}]})
|
||||
|
||||
def get_os_simple_tenant_usage_next_next(self, **kw):
|
||||
return (200, FAKE_RESPONSE_HEADERS, {six.u('tenant_usages'): []})
|
||||
return (200, FAKE_RESPONSE_HEADERS, {'tenant_usages': []})
|
||||
|
||||
def get_os_simple_tenant_usage_tenantfoo(self, **kw):
|
||||
return (200, FAKE_RESPONSE_HEADERS,
|
||||
{six.u('tenant_usage'): {
|
||||
six.u('total_memory_mb_usage'): 25451.762807466665,
|
||||
six.u('total_vcpus_usage'): 49.71047423333333,
|
||||
six.u('total_hours'): 49.71047423333333,
|
||||
six.u('tenant_id'):
|
||||
six.u('7b0a1d73f8fb41718f3343c207597869'),
|
||||
six.u('stop'): six.u('2012-01-22 19:48:41.750722'),
|
||||
six.u('server_usages'): [{
|
||||
six.u('hours'): 49.71047423333333,
|
||||
six.u('uptime'): 27035, six.u('local_gb'): 0,
|
||||
six.u('ended_at'): None,
|
||||
six.u('name'): six.u('f15image1'),
|
||||
six.u('tenant_id'):
|
||||
six.u('7b0a1d73f8fb41718f3343c207597869'),
|
||||
six.u('instance_id'):
|
||||
six.u('f079e394-1111-457b-b350-bb5ecc685cdd'),
|
||||
six.u('vcpus'): 1, six.u('memory_mb'): 512,
|
||||
six.u('state'): six.u('active'),
|
||||
six.u('flavor'): six.u('m1.tiny'),
|
||||
six.u('started_at'):
|
||||
six.u('2012-01-20 18:06:06.479998')}],
|
||||
six.u('start'): six.u('2011-12-25 19:48:41.750687'),
|
||||
six.u('total_local_gb_usage'): 0.0}})
|
||||
return (200, FAKE_RESPONSE_HEADERS, {'tenant_usage': {
|
||||
'total_memory_mb_usage': 25451.762807466665,
|
||||
'total_vcpus_usage': 49.71047423333333,
|
||||
'total_hours': 49.71047423333333,
|
||||
'tenant_id': '7b0a1d73f8fb41718f3343c207597869',
|
||||
'stop': '2012-01-22 19:48:41.750722',
|
||||
'server_usages': [{
|
||||
'hours': 49.71047423333333,
|
||||
'uptime': 27035, 'local_gb': 0,
|
||||
'ended_at': None,
|
||||
'name': 'f15image1',
|
||||
'tenant_id': '7b0a1d73f8fb41718f3343c207597869',
|
||||
'instance_id': 'f079e394-1111-457b-b350-bb5ecc685cdd',
|
||||
'vcpus': 1, 'memory_mb': 512,
|
||||
'state': 'active',
|
||||
'flavor': 'm1.tiny',
|
||||
'started_at': '2012-01-20 18:06:06.479998',
|
||||
}],
|
||||
'start': '2011-12-25 19:48:41.750687',
|
||||
'total_local_gb_usage': 0.0}})
|
||||
|
||||
def get_os_simple_tenant_usage_test(self, **kw):
|
||||
return (200, {}, {six.u('tenant_usage'): {
|
||||
six.u('total_memory_mb_usage'): 25451.762807466665,
|
||||
six.u('total_vcpus_usage'): 49.71047423333333,
|
||||
six.u('total_hours'): 49.71047423333333,
|
||||
six.u('tenant_id'): six.u('7b0a1d73f8fb41718f3343c207597869'),
|
||||
six.u('stop'): six.u('2012-01-22 19:48:41.750722'),
|
||||
six.u('server_usages'): [{
|
||||
six.u('hours'): 49.71047423333333,
|
||||
six.u('uptime'): 27035, six.u('local_gb'): 0,
|
||||
six.u('ended_at'): None,
|
||||
six.u('name'): six.u('f15image1'),
|
||||
six.u('tenant_id'): six.u('7b0a1d73f8fb41718f3343c207597869'),
|
||||
six.u('instance_id'):
|
||||
six.u('f079e394-1111-457b-b350-bb5ecc685cdd'),
|
||||
six.u('vcpus'): 1, six.u('memory_mb'): 512,
|
||||
six.u('state'): six.u('active'),
|
||||
six.u('flavor'): six.u('m1.tiny'),
|
||||
six.u('started_at'): six.u('2012-01-20 18:06:06.479998')}],
|
||||
six.u('start'): six.u('2011-12-25 19:48:41.750687'),
|
||||
six.u('total_local_gb_usage'): 0.0}})
|
||||
return (200, {}, {'tenant_usage': {
|
||||
'total_memory_mb_usage': 25451.762807466665,
|
||||
'total_vcpus_usage': 49.71047423333333,
|
||||
'total_hours': 49.71047423333333,
|
||||
'tenant_id': '7b0a1d73f8fb41718f3343c207597869',
|
||||
'stop': '2012-01-22 19:48:41.750722',
|
||||
'server_usages': [{
|
||||
'hours': 49.71047423333333,
|
||||
'uptime': 27035, 'local_gb': 0,
|
||||
'ended_at': None,
|
||||
'name': 'f15image1',
|
||||
'tenant_id': '7b0a1d73f8fb41718f3343c207597869',
|
||||
'instance_id': 'f079e394-1111-457b-b350-bb5ecc685cdd',
|
||||
'vcpus': 1, 'memory_mb': 512,
|
||||
'state': 'active',
|
||||
'flavor': 'm1.tiny',
|
||||
'started_at': '2012-01-20 18:06:06.479998',
|
||||
}],
|
||||
'start': '2011-12-25 19:48:41.750687',
|
||||
'total_local_gb_usage': 0.0}})
|
||||
|
||||
def get_os_simple_tenant_usage_tenant_id(self, **kw):
|
||||
return (200, {}, {six.u('tenant_usage'): {
|
||||
six.u('total_memory_mb_usage'): 25451.762807466665,
|
||||
six.u('total_vcpus_usage'): 49.71047423333333,
|
||||
six.u('total_hours'): 49.71047423333333,
|
||||
six.u('tenant_id'): six.u('7b0a1d73f8fb41718f3343c207597869'),
|
||||
six.u('stop'): six.u('2012-01-22 19:48:41.750722'),
|
||||
six.u('server_usages'): [{
|
||||
six.u('hours'): 49.71047423333333,
|
||||
six.u('uptime'): 27035, six.u('local_gb'): 0,
|
||||
six.u('ended_at'): None,
|
||||
six.u('name'): six.u('f15image1'),
|
||||
six.u('tenant_id'): six.u('7b0a1d73f8fb41718f3343c207597869'),
|
||||
six.u('instance_id'):
|
||||
six.u('f079e394-1111-457b-b350-bb5ecc685cdd'),
|
||||
six.u('vcpus'): 1, six.u('memory_mb'): 512,
|
||||
six.u('state'): six.u('active'),
|
||||
six.u('flavor'): six.u('m1.tiny'),
|
||||
six.u('started_at'): six.u('2012-01-20 18:06:06.479998')}],
|
||||
six.u('start'): six.u('2011-12-25 19:48:41.750687'),
|
||||
six.u('total_local_gb_usage'): 0.0}})
|
||||
return (200, {}, {'tenant_usage': {
|
||||
'total_memory_mb_usage': 25451.762807466665,
|
||||
'total_vcpus_usage': 49.71047423333333,
|
||||
'total_hours': 49.71047423333333,
|
||||
'tenant_id': '7b0a1d73f8fb41718f3343c207597869',
|
||||
'stop': '2012-01-22 19:48:41.750722',
|
||||
'server_usages': [{
|
||||
'hours': 49.71047423333333,
|
||||
'uptime': 27035, 'local_gb': 0,
|
||||
'ended_at': None,
|
||||
'name': 'f15image1',
|
||||
'tenant_id': '7b0a1d73f8fb41718f3343c207597869',
|
||||
'instance_id': 'f079e394-1111-457b-b350-bb5ecc685cdd',
|
||||
'vcpus': 1, 'memory_mb': 512,
|
||||
'state': 'active',
|
||||
'flavor': 'm1.tiny',
|
||||
'started_at': '2012-01-20 18:06:06.479998',
|
||||
}],
|
||||
'start': '2011-12-25 19:48:41.750687',
|
||||
'total_local_gb_usage': 0.0}})
|
||||
|
||||
def get_os_simple_tenant_usage_tenant_id_next(self, **kw):
|
||||
return (200, {}, {six.u('tenant_usage'): {
|
||||
six.u('total_memory_mb_usage'): 25451.762807466665,
|
||||
six.u('total_vcpus_usage'): 49.71047423333333,
|
||||
six.u('total_hours'): 49.71047423333333,
|
||||
six.u('tenant_id'): six.u('7b0a1d73f8fb41718f3343c207597869'),
|
||||
six.u('stop'): six.u('2012-01-22 19:48:41.750722'),
|
||||
six.u('server_usages'): [{
|
||||
six.u('hours'): 49.71047423333333,
|
||||
six.u('uptime'): 27035, six.u('local_gb'): 0,
|
||||
six.u('ended_at'): None,
|
||||
six.u('name'): six.u('f15image1'),
|
||||
six.u('tenant_id'): six.u('7b0a1d73f8fb41718f3343c207597869'),
|
||||
six.u('instance_id'):
|
||||
six.u('f079e394-2222-457b-b350-bb5ecc685cdd'),
|
||||
six.u('vcpus'): 1, six.u('memory_mb'): 512,
|
||||
six.u('state'): six.u('active'),
|
||||
six.u('flavor'): six.u('m1.tiny'),
|
||||
six.u('started_at'): six.u('2012-01-20 18:06:06.479998')}],
|
||||
six.u('start'): six.u('2011-12-25 19:48:41.750687'),
|
||||
six.u('total_local_gb_usage'): 0.0}})
|
||||
return (200, {}, {'tenant_usage': {
|
||||
'total_memory_mb_usage': 25451.762807466665,
|
||||
'total_vcpus_usage': 49.71047423333333,
|
||||
'total_hours': 49.71047423333333,
|
||||
'tenant_id': '7b0a1d73f8fb41718f3343c207597869',
|
||||
'stop': '2012-01-22 19:48:41.750722',
|
||||
'server_usages': [{
|
||||
'hours': 49.71047423333333,
|
||||
'uptime': 27035, 'local_gb': 0,
|
||||
'ended_at': None,
|
||||
'name': 'f15image1',
|
||||
'tenant_id': '7b0a1d73f8fb41718f3343c207597869',
|
||||
'instance_id': 'f079e394-2222-457b-b350-bb5ecc685cdd',
|
||||
'vcpus': 1, 'memory_mb': 512,
|
||||
'state': 'active',
|
||||
'flavor': 'm1.tiny',
|
||||
'started_at': '2012-01-20 18:06:06.479998',
|
||||
}],
|
||||
'start': '2011-12-25 19:48:41.750687',
|
||||
'total_local_gb_usage': 0.0}})
|
||||
|
||||
def get_os_simple_tenant_usage_tenant_id_next_next(self, **kw):
|
||||
return (200, {}, {six.u('tenant_usage'): {}})
|
||||
return (200, {}, {'tenant_usage': {}})
|
||||
|
||||
#
|
||||
# Aggregates
|
||||
|
@ -14,8 +14,6 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import six
|
||||
|
||||
from novaclient.tests.unit.fixture_data import availability_zones as data
|
||||
from novaclient.tests.unit.fixture_data import client
|
||||
from novaclient.tests.unit import utils
|
||||
@ -54,8 +52,8 @@ class AvailabilityZoneTest(utils.FixturedTestCase):
|
||||
|
||||
self.assertEqual(2, len(zones))
|
||||
|
||||
l0 = [six.u('zone-1'), six.u('available')]
|
||||
l1 = [six.u('zone-2'), six.u('not available')]
|
||||
l0 = ['zone-1', 'available']
|
||||
l1 = ['zone-2', 'not available']
|
||||
|
||||
z0 = self.shell._treeizeAvailabilityZone(zones[0])
|
||||
z1 = self.shell._treeizeAvailabilityZone(zones[1])
|
||||
@ -75,18 +73,15 @@ class AvailabilityZoneTest(utils.FixturedTestCase):
|
||||
|
||||
self.assertEqual(3, len(zones))
|
||||
|
||||
l0 = [six.u('zone-1'), six.u('available')]
|
||||
l1 = [six.u('|- fake_host-1'), six.u('')]
|
||||
l2 = [six.u('| |- nova-compute'),
|
||||
six.u('enabled :-) 2012-12-26 14:45:25')]
|
||||
l3 = [six.u('internal'), six.u('available')]
|
||||
l4 = [six.u('|- fake_host-1'), six.u('')]
|
||||
l5 = [six.u('| |- nova-sched'),
|
||||
six.u('enabled :-) 2012-12-26 14:45:25')]
|
||||
l6 = [six.u('|- fake_host-2'), six.u('')]
|
||||
l7 = [six.u('| |- nova-network'),
|
||||
six.u('enabled XXX 2012-12-26 14:45:24')]
|
||||
l8 = [six.u('zone-2'), six.u('not available')]
|
||||
l0 = ['zone-1', 'available']
|
||||
l1 = ['|- fake_host-1', '']
|
||||
l2 = ['| |- nova-compute', 'enabled :-) 2012-12-26 14:45:25']
|
||||
l3 = ['internal', 'available']
|
||||
l4 = ['|- fake_host-1', '']
|
||||
l5 = ['| |- nova-sched', 'enabled :-) 2012-12-26 14:45:25']
|
||||
l6 = ['|- fake_host-2', '']
|
||||
l7 = ['| |- nova-network', 'enabled XXX 2012-12-26 14:45:24']
|
||||
l8 = ['zone-2', 'not available']
|
||||
|
||||
z0 = self.shell._treeizeAvailabilityZone(zones[0])
|
||||
z1 = self.shell._treeizeAvailabilityZone(zones[1])
|
||||
|
@ -13,8 +13,6 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import six
|
||||
|
||||
from novaclient import api_versions
|
||||
from novaclient import exceptions
|
||||
from novaclient.tests.unit.fixture_data import client
|
||||
@ -127,7 +125,7 @@ class HypervisorsTest(utils.FixturedTestCase):
|
||||
self.cs.hypervisors.search, 'hyper',
|
||||
detailed=True)
|
||||
self.assertIn('Parameter "detailed" requires API version 2.53 or '
|
||||
'greater.', six.text_type(ex))
|
||||
'greater.', str(ex))
|
||||
|
||||
def test_hypervisor_servers(self):
|
||||
expected = [
|
||||
|
@ -10,8 +10,6 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import six
|
||||
|
||||
from novaclient import api_versions
|
||||
from novaclient.tests.unit import utils
|
||||
from novaclient.tests.unit.v2 import fakes
|
||||
@ -158,8 +156,7 @@ class MigrationsV280Test(MigrationsV266Test):
|
||||
ex = self.assertRaises(TypeError,
|
||||
self.cs.migrations.list,
|
||||
user_id=user_id)
|
||||
self.assertIn("unexpected keyword argument 'user_id'",
|
||||
six.text_type(ex))
|
||||
self.assertIn("unexpected keyword argument 'user_id'", str(ex))
|
||||
|
||||
def test_list_migrations_with_project_id_pre_v280(self):
|
||||
self.cs.api_version = api_versions.APIVersion('2.79')
|
||||
@ -167,5 +164,4 @@ class MigrationsV280Test(MigrationsV266Test):
|
||||
ex = self.assertRaises(TypeError,
|
||||
self.cs.migrations.list,
|
||||
project_id=project_id)
|
||||
self.assertIn("unexpected keyword argument 'project_id'",
|
||||
six.text_type(ex))
|
||||
self.assertIn("unexpected keyword argument 'project_id'", str(ex))
|
||||
|
@ -13,11 +13,11 @@
|
||||
# under the License.
|
||||
|
||||
import base64
|
||||
import io
|
||||
import os
|
||||
import tempfile
|
||||
|
||||
import mock
|
||||
import six
|
||||
|
||||
from novaclient import api_versions
|
||||
from novaclient import exceptions
|
||||
@ -83,7 +83,7 @@ class ServersTest(utils.FixturedTestCase):
|
||||
self.cs.servers.list,
|
||||
search_opts={'locked': False})
|
||||
self.assertIn("'locked' argument is only allowed since "
|
||||
"microversion 2.73.", six.text_type(e))
|
||||
"microversion 2.73.", str(e))
|
||||
|
||||
def test_list_servers_undetailed(self):
|
||||
sl = self.cs.servers.list(detailed=False)
|
||||
@ -140,7 +140,7 @@ class ServersTest(utils.FixturedTestCase):
|
||||
if self.supports_files:
|
||||
kwargs['files'] = {
|
||||
'/etc/passwd': 'some data', # a file
|
||||
'/tmp/foo.txt': six.StringIO('data'), # a stream
|
||||
'/tmp/foo.txt': io.StringIO('data'), # a stream
|
||||
}
|
||||
s = self.cs.servers.create(
|
||||
name="My server",
|
||||
@ -270,14 +270,14 @@ class ServersTest(utils.FixturedTestCase):
|
||||
if self.supports_files:
|
||||
kwargs['files'] = {
|
||||
'/etc/passwd': 'some data', # a file
|
||||
'/tmp/foo.txt': six.StringIO('data'), # a stream
|
||||
'/tmp/foo.txt': io.StringIO('data'), # a stream
|
||||
}
|
||||
s = self.cs.servers.create(
|
||||
name="My server",
|
||||
image=1,
|
||||
flavor=1,
|
||||
meta={'foo': 'bar'},
|
||||
userdata=six.StringIO('hello moto'),
|
||||
userdata=io.StringIO('hello moto'),
|
||||
nics=self._get_server_create_default_nics(),
|
||||
**kwargs
|
||||
)
|
||||
@ -290,14 +290,14 @@ class ServersTest(utils.FixturedTestCase):
|
||||
if self.supports_files:
|
||||
kwargs['files'] = {
|
||||
'/etc/passwd': 'some data', # a file
|
||||
'/tmp/foo.txt': six.StringIO('data'), # a stream
|
||||
'/tmp/foo.txt': io.StringIO('data'), # a stream
|
||||
}
|
||||
s = self.cs.servers.create(
|
||||
name="My server",
|
||||
image=1,
|
||||
flavor=1,
|
||||
meta={'foo': 'bar'},
|
||||
userdata=six.u('こんにちは'),
|
||||
userdata='こんにちは',
|
||||
key_name="fakekey",
|
||||
nics=self._get_server_create_default_nics(),
|
||||
**kwargs
|
||||
@ -311,7 +311,7 @@ class ServersTest(utils.FixturedTestCase):
|
||||
if self.supports_files:
|
||||
kwargs['files'] = {
|
||||
'/etc/passwd': 'some data', # a file
|
||||
'/tmp/foo.txt': six.StringIO('data'), # a stream
|
||||
'/tmp/foo.txt': io.StringIO('data'), # a stream
|
||||
}
|
||||
s = self.cs.servers.create(
|
||||
name="My server",
|
||||
@ -349,7 +349,7 @@ class ServersTest(utils.FixturedTestCase):
|
||||
if self.supports_files:
|
||||
kwargs['files'] = {
|
||||
'/etc/passwd': 'some data', # a file
|
||||
'/tmp/foo.txt': six.StringIO('data'), # a stream
|
||||
'/tmp/foo.txt': io.StringIO('data'), # a stream
|
||||
}
|
||||
with tempfile.TemporaryFile(mode='wb+') as bin_file:
|
||||
original_data = os.urandom(1024)
|
||||
@ -1510,7 +1510,7 @@ class ServersV254Test(ServersV252Test):
|
||||
self.cs.servers.rebuild,
|
||||
'1234', fakes.FAKE_IMAGE_UUID_1,
|
||||
key_name='test_keypair')
|
||||
self.assertIn('key_name', six.text_type(ex.message))
|
||||
self.assertIn('key_name', str(ex.message))
|
||||
|
||||
|
||||
class ServersV256Test(ServersV254Test):
|
||||
@ -1533,7 +1533,7 @@ class ServersV256Test(ServersV254Test):
|
||||
s = self.cs.servers.get(1234)
|
||||
ex = self.assertRaises(TypeError,
|
||||
s.migrate, host='target-host')
|
||||
self.assertIn('host', six.text_type(ex))
|
||||
self.assertIn('host', str(ex))
|
||||
|
||||
|
||||
class ServersV257Test(ServersV256Test):
|
||||
@ -1549,9 +1549,9 @@ class ServersV257Test(ServersV256Test):
|
||||
name="My server", image=1, flavor=1,
|
||||
files={
|
||||
'/etc/passwd': 'some data', # a file
|
||||
'/tmp/foo.txt': six.StringIO('data'), # a stream
|
||||
'/tmp/foo.txt': io.StringIO('data'), # a stream
|
||||
}, nics='auto')
|
||||
self.assertIn('files', six.text_type(ex))
|
||||
self.assertIn('files', str(ex))
|
||||
|
||||
def test_rebuild_server_name_meta_files(self):
|
||||
files = {'/etc/passwd': 'some data'}
|
||||
@ -1559,7 +1559,7 @@ class ServersV257Test(ServersV256Test):
|
||||
ex = self.assertRaises(
|
||||
exceptions.UnsupportedAttribute, s.rebuild, image=1, name='new',
|
||||
meta={'foo': 'bar'}, files=files)
|
||||
self.assertIn('files', six.text_type(ex))
|
||||
self.assertIn('files', str(ex))
|
||||
|
||||
|
||||
class ServersV263Test(ServersV257Test):
|
||||
@ -1600,7 +1600,7 @@ class ServersV263Test(ServersV257Test):
|
||||
userdata="hello moto", key_name="fakekey",
|
||||
nics=self._get_server_create_default_nics(),
|
||||
trusted_image_certificates=['id1', 'id2'])
|
||||
self.assertIn('trusted_image_certificates', six.text_type(ex))
|
||||
self.assertIn('trusted_image_certificates', str(ex))
|
||||
|
||||
def test_rebuild_server_with_trusted_image_certificates(self):
|
||||
s = self.cs.servers.get(1234)
|
||||
@ -1626,7 +1626,7 @@ class ServersV263Test(ServersV257Test):
|
||||
self.cs.servers.rebuild,
|
||||
'1234', fakes.FAKE_IMAGE_UUID_1,
|
||||
trusted_image_certificates=['id1', 'id2'])
|
||||
self.assertIn('trusted_image_certificates', six.text_type(ex))
|
||||
self.assertIn('trusted_image_certificates', str(ex))
|
||||
|
||||
|
||||
class ServersV267Test(ServersV263Test):
|
||||
@ -1671,7 +1671,7 @@ class ServersV267Test(ServersV263Test):
|
||||
name="bfv server", image='', flavor=1,
|
||||
nics='none', block_device_mapping_v2=bdm)
|
||||
self.assertIn("Block device volume_type is not supported before "
|
||||
"microversion 2.67", six.text_type(ex))
|
||||
"microversion 2.67", str(ex))
|
||||
|
||||
|
||||
class ServersV268Test(ServersV267Test):
|
||||
@ -1692,7 +1692,7 @@ class ServersV268Test(ServersV267Test):
|
||||
|
||||
ex = self.assertRaises(TypeError, self.cs.servers.evacuate,
|
||||
'fake_target_host', force=True)
|
||||
self.assertIn('force', six.text_type(ex))
|
||||
self.assertIn('force', str(ex))
|
||||
|
||||
def test_live_migrate_server(self):
|
||||
s = self.cs.servers.get(1234)
|
||||
@ -1711,7 +1711,7 @@ class ServersV268Test(ServersV267Test):
|
||||
|
||||
ex = self.assertRaises(TypeError, self.cs.servers.live_migrate,
|
||||
host='hostname', force=True)
|
||||
self.assertIn('force', six.text_type(ex))
|
||||
self.assertIn('force', str(ex))
|
||||
|
||||
|
||||
class ServersV273Test(ServersV268Test):
|
||||
@ -1734,7 +1734,7 @@ class ServersV273Test(ServersV268Test):
|
||||
s = self.cs.servers.get(1234)
|
||||
e = self.assertRaises(TypeError,
|
||||
s.lock, reason='blah')
|
||||
self.assertIn("unexpected keyword argument 'reason'", six.text_type(e))
|
||||
self.assertIn("unexpected keyword argument 'reason'", str(e))
|
||||
|
||||
def test_filter_servers_unlocked(self):
|
||||
# support locked=False
|
||||
@ -1818,7 +1818,7 @@ class ServersV274Test(ServersV273Test):
|
||||
name="My server", image=1, flavor=1,
|
||||
nics='auto', host="new-host")
|
||||
self.assertIn("'host' argument is only allowed since microversion "
|
||||
"2.74", six.text_type(ex))
|
||||
"2.74", str(ex))
|
||||
|
||||
def test_create_server_with_hypervisor_hostname_pre_274_fails(self):
|
||||
self.cs.api_version = api_versions.APIVersion('2.73')
|
||||
@ -1827,7 +1827,7 @@ class ServersV274Test(ServersV273Test):
|
||||
name="My server", image=1, flavor=1,
|
||||
nics='auto', hypervisor_hostname="new-host")
|
||||
self.assertIn("'hypervisor_hostname' argument is only allowed since "
|
||||
"microversion 2.74", six.text_type(ex))
|
||||
"microversion 2.74", str(ex))
|
||||
|
||||
def test_create_server_with_host_and_hypervisor_hostname_pre_274_fails(
|
||||
self):
|
||||
@ -1838,7 +1838,7 @@ class ServersV274Test(ServersV273Test):
|
||||
nics='auto', host="new-host",
|
||||
hypervisor_hostname="new-host")
|
||||
self.assertIn("'host' argument is only allowed since microversion "
|
||||
"2.74", six.text_type(ex))
|
||||
"2.74", str(ex))
|
||||
|
||||
|
||||
class ServersV277Test(ServersV274Test):
|
||||
@ -1868,13 +1868,13 @@ class ServersV277Test(ServersV274Test):
|
||||
s.unshelve,
|
||||
availability_zone='foo-az')
|
||||
self.assertIn("unexpected keyword argument 'availability_zone'",
|
||||
six.text_type(ex))
|
||||
str(ex))
|
||||
# Test going through the ServerManager directly.
|
||||
ex = self.assertRaises(TypeError,
|
||||
self.cs.servers.unshelve,
|
||||
s, availability_zone='foo-az')
|
||||
self.assertIn("unexpected keyword argument 'availability_zone'",
|
||||
six.text_type(ex))
|
||||
str(ex))
|
||||
|
||||
|
||||
class ServersV278Test(ServersV273Test):
|
||||
|
@ -18,15 +18,15 @@
|
||||
|
||||
import argparse
|
||||
import base64
|
||||
import builtins
|
||||
import collections
|
||||
import datetime
|
||||
import io
|
||||
import os
|
||||
|
||||
import fixtures
|
||||
import mock
|
||||
from oslo_utils import timeutils
|
||||
import six
|
||||
from six.moves import builtins
|
||||
import testtools
|
||||
|
||||
import novaclient
|
||||
@ -88,8 +88,8 @@ class ShellTest(utils.TestCase):
|
||||
# TODO(stephenfin): We should migrate most of the existing assertRaises
|
||||
# calls to simply pass expected_error to this instead so we can easily
|
||||
# capture and compare output
|
||||
@mock.patch('sys.stdout', new_callable=six.StringIO)
|
||||
@mock.patch('sys.stderr', new_callable=six.StringIO)
|
||||
@mock.patch('sys.stdout', new_callable=io.StringIO)
|
||||
@mock.patch('sys.stderr', new_callable=io.StringIO)
|
||||
def run_command(self, cmd, mock_stderr, mock_stdout, api_version=None,
|
||||
expected_error=None):
|
||||
version_options = []
|
||||
@ -304,7 +304,7 @@ class ShellTest(utils.TestCase):
|
||||
'boot --flavor 1 --image %s --config-drive /dev/hda some-server' %
|
||||
FAKE_UUID_1)
|
||||
self.assertIn("The value of the '--config-drive' option must be "
|
||||
"a boolean value.", six.text_type(ex))
|
||||
"a boolean value.", str(ex))
|
||||
|
||||
def test_boot_invalid_user_data(self):
|
||||
invalid_file = os.path.join(os.path.dirname(__file__),
|
||||
@ -676,7 +676,7 @@ class ShellTest(utils.TestCase):
|
||||
'size=1,bootindex=0,shutdown=remove,tag=foo,volume_type=lvm '
|
||||
'bfv-server' % FAKE_UUID_1, api_version='2.66')
|
||||
self.assertIn("'volume_type' in block device mapping is not supported "
|
||||
"in API version", six.text_type(ex))
|
||||
"in API version", str(ex))
|
||||
|
||||
def test_boot_from_volume_with_volume_type(self):
|
||||
"""Tests creating a volume-backed server from a source image and
|
||||
@ -895,7 +895,7 @@ class ShellTest(utils.TestCase):
|
||||
'--nic net-id=1,port-id=2 some-server' % FAKE_UUID_1)
|
||||
ex = self.assertRaises(exceptions.CommandError, self.run_command,
|
||||
cmd, api_version='2.1')
|
||||
self.assertNotIn('tag=tag', six.text_type(ex))
|
||||
self.assertNotIn('tag=tag', str(ex))
|
||||
|
||||
def test_boot_invalid_nics_v2_32(self):
|
||||
# This is a negative test to make sure we fail with the correct message
|
||||
@ -903,7 +903,7 @@ class ShellTest(utils.TestCase):
|
||||
'--nic net-id=1,port-id=2 some-server' % FAKE_UUID_1)
|
||||
ex = self.assertRaises(exceptions.CommandError, self.run_command,
|
||||
cmd, api_version='2.32')
|
||||
self.assertIn('tag=tag', six.text_type(ex))
|
||||
self.assertIn('tag=tag', str(ex))
|
||||
|
||||
def test_boot_invalid_nics_v2_36_auto(self):
|
||||
"""This is a negative test to make sure we fail with the correct
|
||||
@ -912,7 +912,7 @@ class ShellTest(utils.TestCase):
|
||||
cmd = ('boot --image %s --flavor 1 --nic auto test' % FAKE_UUID_1)
|
||||
ex = self.assertRaises(exceptions.CommandError, self.run_command,
|
||||
cmd, api_version='2.36')
|
||||
self.assertNotIn('auto,none', six.text_type(ex))
|
||||
self.assertNotIn('auto,none', str(ex))
|
||||
|
||||
def test_boot_invalid_nics_v2_37(self):
|
||||
"""This is a negative test to make sure we fail with the correct
|
||||
@ -922,7 +922,7 @@ class ShellTest(utils.TestCase):
|
||||
'--nic net-id=1 --nic auto some-server' % FAKE_UUID_1)
|
||||
ex = self.assertRaises(exceptions.CommandError, self.run_command,
|
||||
cmd, api_version='2.37')
|
||||
self.assertIn('auto,none', six.text_type(ex))
|
||||
self.assertIn('auto,none', str(ex))
|
||||
|
||||
def test_boot_nics_auto_allocate_default(self):
|
||||
"""Tests that if microversion>=2.37 is specified and no --nics are
|
||||
@ -1407,7 +1407,7 @@ class ShellTest(utils.TestCase):
|
||||
exceptions.CommandError, self.run_command,
|
||||
'boot --flavor 1 --image %s some-server' % FAKE_UUID_2)
|
||||
self.assertIn('Instance %s could not be found.' % FAKE_UUID_1,
|
||||
six.text_type(ex))
|
||||
str(ex))
|
||||
|
||||
def test_boot_with_host_v274(self):
|
||||
self.run_command('boot --flavor 1 --image %s '
|
||||
@ -1831,7 +1831,7 @@ class ShellTest(utils.TestCase):
|
||||
ex = self.assertRaises(exceptions.CommandError, self.run_command,
|
||||
'list --changes-before 0123456789',
|
||||
api_version='2.66')
|
||||
self.assertIn('Invalid changes-before value', six.text_type(ex))
|
||||
self.assertIn('Invalid changes-before value', str(ex))
|
||||
|
||||
def test_list_with_changes_before_pre_v266_not_allowed(self):
|
||||
self.assertRaises(SystemExit, self.run_command,
|
||||
@ -1947,7 +1947,7 @@ class ShellTest(utils.TestCase):
|
||||
'rebuild sample-server %s --key-unset --key-name test_keypair' %
|
||||
FAKE_UUID_1, api_version='2.54')
|
||||
self.assertIn("Cannot specify '--key-unset' with '--key-name'.",
|
||||
six.text_type(ex))
|
||||
str(ex))
|
||||
|
||||
def test_rebuild_with_incorrect_metadata(self):
|
||||
cmd = 'rebuild sample-server %s --name asdf --meta foo' % FAKE_UUID_1
|
||||
@ -2001,7 +2001,7 @@ class ShellTest(utils.TestCase):
|
||||
api_version='2.57')
|
||||
self.assertIn("Can't open '%(user_data)s': "
|
||||
"[Errno 2] No such file or directory: '%(user_data)s'" %
|
||||
{'user_data': invalid_file}, six.text_type(ex))
|
||||
{'user_data': invalid_file}, str(ex))
|
||||
|
||||
def test_rebuild_unset_user_data(self):
|
||||
self.run_command('rebuild sample-server %s --user-data-unset' %
|
||||
@ -2024,7 +2024,7 @@ class ShellTest(utils.TestCase):
|
||||
ex = self.assertRaises(exceptions.CommandError, self.run_command, cmd,
|
||||
api_version='2.57')
|
||||
self.assertIn("Cannot specify '--user-data-unset' with "
|
||||
"'--user-data'.", six.text_type(ex))
|
||||
"'--user-data'.", str(ex))
|
||||
|
||||
def test_rebuild_with_single_trusted_image_certificates(self):
|
||||
self.run_command('rebuild sample-server %s '
|
||||
@ -2132,7 +2132,7 @@ class ShellTest(utils.TestCase):
|
||||
api_version='2.63')
|
||||
self.assertIn("Cannot specify '--trusted-image-certificates-unset' "
|
||||
"with '--trusted-image-certificate-id'",
|
||||
six.text_type(ex))
|
||||
str(ex))
|
||||
|
||||
def test_rebuild_with_trusted_image_certificates_unset_env_conflict(self):
|
||||
"""Tests the error condition that trusted image certs are both unset
|
||||
@ -2146,7 +2146,7 @@ class ShellTest(utils.TestCase):
|
||||
FAKE_UUID_1, api_version='2.63')
|
||||
self.assertIn("Cannot specify '--trusted-image-certificates-unset' "
|
||||
"with '--trusted-image-certificate-id'",
|
||||
six.text_type(ex))
|
||||
str(ex))
|
||||
|
||||
def test_rebuild_with_trusted_image_certificates_arg_and_envar(self):
|
||||
"""Tests that if both the environment variable and argument are
|
||||
@ -2237,7 +2237,7 @@ class ShellTest(utils.TestCase):
|
||||
self.run_command,
|
||||
'lock sample-server --reason zombies',
|
||||
api_version='2.72')
|
||||
self.assertIn('2', six.text_type(exp))
|
||||
self.assertIn('2', str(exp))
|
||||
|
||||
def test_lock_v273(self):
|
||||
self.run_command('lock sample-server',
|
||||
@ -2509,7 +2509,7 @@ class ShellTest(utils.TestCase):
|
||||
self.run_command,
|
||||
'server-topology 1234',
|
||||
api_version='2.77')
|
||||
self.assertIn('2', six.text_type(exp))
|
||||
self.assertIn('2', str(exp))
|
||||
|
||||
def test_refresh_network(self):
|
||||
self.run_command('refresh-network 1234')
|
||||
@ -2787,7 +2787,7 @@ class ShellTest(utils.TestCase):
|
||||
'aggregate-update test')
|
||||
self.assertIn("Either '--name <name>' or '--availability-zone "
|
||||
"<availability-zone>' must be specified.",
|
||||
six.text_type(ex))
|
||||
str(ex))
|
||||
|
||||
def test_aggregate_set_metadata_add_by_id(self):
|
||||
out, err = self.run_command('aggregate-set-metadata 3 foo=bar')
|
||||
@ -4009,7 +4009,7 @@ class ShellTest(utils.TestCase):
|
||||
exceptions.CommandError, self.run_command,
|
||||
'instance-action-list sample-server --changes-since 0123456789',
|
||||
api_version='2.58')
|
||||
self.assertIn('Invalid changes-since value', six.text_type(ex))
|
||||
self.assertIn('Invalid changes-since value', str(ex))
|
||||
|
||||
def test_instance_action_list_changes_before_pre_v266_not_allowed(self):
|
||||
cmd = 'instance-action-list sample-server --changes-before ' \
|
||||
@ -4031,7 +4031,7 @@ class ShellTest(utils.TestCase):
|
||||
exceptions.CommandError, self.run_command,
|
||||
'instance-action-list sample-server --changes-before 0123456789',
|
||||
api_version='2.66')
|
||||
self.assertIn('Invalid changes-before value', six.text_type(ex))
|
||||
self.assertIn('Invalid changes-before value', str(ex))
|
||||
|
||||
def test_instance_usage_audit_log(self):
|
||||
self.run_command('instance-usage-audit-log')
|
||||
@ -4096,7 +4096,7 @@ class ShellTest(utils.TestCase):
|
||||
ex = self.assertRaises(exceptions.CommandError, self.run_command,
|
||||
'migration-list --changes-since 0123456789',
|
||||
api_version='2.59')
|
||||
self.assertIn('Invalid changes-since value', six.text_type(ex))
|
||||
self.assertIn('Invalid changes-since value', str(ex))
|
||||
|
||||
def test_migration_list_with_changes_before_v266(self):
|
||||
self.run_command('migration-list --changes-before 2016-02-29T06:23:22',
|
||||
@ -4108,7 +4108,7 @@ class ShellTest(utils.TestCase):
|
||||
ex = self.assertRaises(exceptions.CommandError, self.run_command,
|
||||
'migration-list --changes-before 0123456789',
|
||||
api_version='2.66')
|
||||
self.assertIn('Invalid changes-before value', six.text_type(ex))
|
||||
self.assertIn('Invalid changes-before value', str(ex))
|
||||
|
||||
def test_migration_list_with_changes_before_pre_v266_not_allowed(self):
|
||||
cmd = 'migration-list --changes-before 2016-02-29T06:23:22'
|
||||
@ -4284,7 +4284,7 @@ class ShellTest(utils.TestCase):
|
||||
api_version="2.2")
|
||||
|
||||
def test_keypair_stdin(self):
|
||||
with mock.patch('sys.stdin', six.StringIO('FAKE_PUBLIC_KEY')):
|
||||
with mock.patch('sys.stdin', io.StringIO('FAKE_PUBLIC_KEY')):
|
||||
self.run_command('keypair-add --pub-key - test', api_version="2.2")
|
||||
self.assert_called(
|
||||
'POST', '/os-keypairs', {
|
||||
@ -4360,7 +4360,7 @@ class ShellTest(utils.TestCase):
|
||||
'server-group-create sg1 anti-affinity '
|
||||
'--rule max_server_per_host=foo', api_version='2.64')
|
||||
self.assertIn("Invalid 'max_server_per_host' value: foo",
|
||||
six.text_type(result))
|
||||
str(result))
|
||||
|
||||
def test_create_server_group_with_rules_pre_264(self):
|
||||
self.assertRaises(SystemExit, self.run_command,
|
||||
|
@ -13,8 +13,6 @@
|
||||
|
||||
import datetime
|
||||
|
||||
import six
|
||||
|
||||
from novaclient import api_versions
|
||||
from novaclient.tests.unit import utils
|
||||
from novaclient.tests.unit.v2 import fakes
|
||||
@ -60,8 +58,8 @@ class UsageTest(utils.TestCase):
|
||||
self.assertIsInstance(u, usage.Usage)
|
||||
|
||||
def test_usage_class_get(self):
|
||||
start = six.u('2012-01-22T19:48:41.750722')
|
||||
stop = six.u('2012-01-22T19:48:41.750722')
|
||||
start = '2012-01-22T19:48:41.750722'
|
||||
stop = '2012-01-22T19:48:41.750722'
|
||||
|
||||
info = {'tenant_id': 'tenantfoo', 'start': start,
|
||||
'stop': stop}
|
||||
|
@ -14,7 +14,6 @@
|
||||
# under the License.
|
||||
|
||||
import mock
|
||||
import six
|
||||
|
||||
from novaclient import api_versions
|
||||
from novaclient.tests.unit import utils
|
||||
@ -156,4 +155,4 @@ class VolumesV279Test(VolumesV249Test):
|
||||
TypeError, self.cs.volumes.create_server_volume, "1234",
|
||||
volume_id='15e59938-07d5-11e1-90e3-e3dffe0c5983',
|
||||
delete_on_termination=True)
|
||||
self.assertIn('delete_on_termination', six.text_type(ex))
|
||||
self.assertIn('delete_on_termination', str(ex))
|
||||
|
@ -16,13 +16,12 @@ import os
|
||||
import re
|
||||
import textwrap
|
||||
import time
|
||||
from urllib import parse
|
||||
|
||||
from oslo_serialization import jsonutils
|
||||
from oslo_utils import encodeutils
|
||||
from oslo_utils import uuidutils
|
||||
import prettytable
|
||||
import six
|
||||
from six.moves.urllib import parse
|
||||
|
||||
from novaclient import exceptions
|
||||
from novaclient.i18n import _
|
||||
@ -149,7 +148,7 @@ def print_list(objs, fields, formatters={}, sortby_index=None):
|
||||
if data is None:
|
||||
data = '-'
|
||||
# '\r' would break the table, so remove it.
|
||||
data = six.text_type(data).replace("\r", "")
|
||||
data = str(data).replace("\r", "")
|
||||
row.append(data)
|
||||
pt.add_row(row)
|
||||
|
||||
@ -158,8 +157,7 @@ def print_list(objs, fields, formatters={}, sortby_index=None):
|
||||
else:
|
||||
result = encodeutils.safe_encode(pt.get_string())
|
||||
|
||||
if six.PY3:
|
||||
result = result.decode()
|
||||
result = result.decode()
|
||||
|
||||
print(result)
|
||||
|
||||
@ -196,7 +194,7 @@ def flatten_dict(data):
|
||||
data = data.copy()
|
||||
# Try and decode any nested JSON structures.
|
||||
for key, value in data.items():
|
||||
if isinstance(value, six.string_types):
|
||||
if isinstance(value, str):
|
||||
try:
|
||||
data[key] = jsonutils.loads(value)
|
||||
except ValueError:
|
||||
@ -213,10 +211,10 @@ def print_dict(d, dict_property="Property", dict_value="Value", wrap=0):
|
||||
if isinstance(v, (dict, list)):
|
||||
v = jsonutils.dumps(v, ensure_ascii=False)
|
||||
if wrap > 0:
|
||||
v = textwrap.fill(six.text_type(v), wrap)
|
||||
v = textwrap.fill(str(v), wrap)
|
||||
# if value has a newline, add in multiple rows
|
||||
# e.g. fault with stacktrace
|
||||
if v and isinstance(v, six.string_types) and (r'\n' in v or '\r' in v):
|
||||
if v and isinstance(v, str) and (r'\n' in v or '\r' in v):
|
||||
# '\r' would break the table, so remove it.
|
||||
if '\r' in v:
|
||||
v = v.replace('\r', '')
|
||||
@ -232,8 +230,7 @@ def print_dict(d, dict_property="Property", dict_value="Value", wrap=0):
|
||||
|
||||
result = encodeutils.safe_encode(pt.get_string())
|
||||
|
||||
if six.PY3:
|
||||
result = result.decode()
|
||||
result = result.decode()
|
||||
|
||||
print(result)
|
||||
|
||||
@ -252,8 +249,7 @@ def find_resource(manager, name_or_id, wrap_exception=True, **find_args):
|
||||
try:
|
||||
tmp_id = encodeutils.safe_encode(name_or_id)
|
||||
|
||||
if six.PY3:
|
||||
tmp_id = tmp_id.decode()
|
||||
tmp_id = tmp_id.decode()
|
||||
|
||||
if uuidutils.is_uuid_like(tmp_id):
|
||||
return manager.get(tmp_id)
|
||||
@ -383,7 +379,7 @@ def do_action_on_many(action, resources, success_msg, error_msg):
|
||||
print(success_msg % _get_resource_string(resource))
|
||||
except Exception as e:
|
||||
failure_flag = True
|
||||
print(encodeutils.safe_encode(six.text_type(e)))
|
||||
print(encodeutils.safe_encode(str(e)))
|
||||
|
||||
if failure_flag:
|
||||
raise exceptions.CommandError(error_msg)
|
||||
|
@ -17,9 +17,7 @@
|
||||
Hypervisors interface
|
||||
"""
|
||||
|
||||
from oslo_utils import encodeutils
|
||||
import six
|
||||
from six.moves.urllib import parse
|
||||
from urllib import parse
|
||||
|
||||
from novaclient import api_versions
|
||||
from novaclient import base
|
||||
@ -92,8 +90,6 @@ class HypervisorManager(base.ManagerWithFind):
|
||||
# Starting with microversion 2.53, the /servers and /search routes are
|
||||
# deprecated and we get the same results using GET /os-hypervisors
|
||||
# using query parameters for the hostname pattern and servers.
|
||||
if six.PY2:
|
||||
hypervisor_match = encodeutils.safe_encode(hypervisor_match)
|
||||
if self.api_version >= api_versions.APIVersion('2.53'):
|
||||
url = ('/os-hypervisors%s?hypervisor_hostname_pattern=%s' %
|
||||
('/detail' if detailed else '',
|
||||
|
@ -13,9 +13,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from oslo_utils import encodeutils
|
||||
import six
|
||||
from six.moves.urllib import parse
|
||||
from urllib import parse
|
||||
|
||||
from novaclient import base
|
||||
|
||||
@ -34,8 +32,6 @@ class InstanceUsageAuditLogManager(base.Manager):
|
||||
before which to list usage audits.
|
||||
"""
|
||||
if before:
|
||||
if six.PY2:
|
||||
before = encodeutils.safe_encode(before)
|
||||
return self._get('/os-instance_usage_audit_log/%s' %
|
||||
parse.quote(before, safe=''),
|
||||
'instance_usage_audit_log')
|
||||
|
@ -21,10 +21,7 @@ Server interface.
|
||||
|
||||
import base64
|
||||
import collections
|
||||
|
||||
from oslo_utils import encodeutils
|
||||
import six
|
||||
from six.moves.urllib import parse
|
||||
from urllib import parse
|
||||
|
||||
from novaclient import api_versions
|
||||
from novaclient import base
|
||||
@ -690,17 +687,11 @@ class ServerManager(base.BootingManagerWithFind):
|
||||
|
||||
# NOTE(melwitt): Text file data is converted to bytes prior to
|
||||
# base64 encoding. The utf-8 encoding will fail for binary files.
|
||||
if six.PY3:
|
||||
try:
|
||||
userdata = userdata.encode("utf-8")
|
||||
except AttributeError:
|
||||
# In python 3, 'bytes' object has no attribute 'encode'
|
||||
pass
|
||||
else:
|
||||
try:
|
||||
userdata = encodeutils.safe_encode(userdata)
|
||||
except UnicodeDecodeError:
|
||||
pass
|
||||
try:
|
||||
userdata = userdata.encode("utf-8")
|
||||
except AttributeError:
|
||||
# In python 3, 'bytes' object has no attribute 'encode'
|
||||
pass
|
||||
|
||||
return base64.b64encode(userdata).decode('utf-8')
|
||||
|
||||
@ -761,7 +752,7 @@ class ServerManager(base.BootingManagerWithFind):
|
||||
else:
|
||||
data = file_or_string
|
||||
|
||||
if six.PY3 and isinstance(data, str):
|
||||
if isinstance(data, str):
|
||||
data = data.encode('utf-8')
|
||||
cont = base64.b64encode(data).decode('utf-8')
|
||||
personality.append({
|
||||
@ -791,7 +782,7 @@ class ServerManager(base.BootingManagerWithFind):
|
||||
if nics is not None:
|
||||
# With microversion 2.37+ nics can be an enum of 'auto' or 'none'
|
||||
# or a list of dicts.
|
||||
if isinstance(nics, six.string_types):
|
||||
if isinstance(nics, str):
|
||||
all_net_data = nics
|
||||
else:
|
||||
# NOTE(tr3buchet): nics can be an empty list
|
||||
@ -899,7 +890,7 @@ class ServerManager(base.BootingManagerWithFind):
|
||||
for opt, val in search_opts.items():
|
||||
# support locked=False from 2.73 microversion
|
||||
if val or (opt == 'locked' and val is False):
|
||||
if isinstance(val, six.text_type):
|
||||
if isinstance(val, str):
|
||||
val = val.encode('utf-8')
|
||||
qparams[opt] = val
|
||||
|
||||
|
@ -14,9 +14,10 @@
|
||||
# under the License.
|
||||
|
||||
"""
|
||||
service interface
|
||||
Service interface.
|
||||
"""
|
||||
from six.moves import urllib
|
||||
|
||||
from urllib import parse
|
||||
|
||||
from novaclient import api_versions
|
||||
from novaclient import base
|
||||
@ -48,7 +49,7 @@ class ServiceManager(base.ManagerWithFind):
|
||||
if binary:
|
||||
filters.append(("binary", binary))
|
||||
if filters:
|
||||
url = "%s?%s" % (url, urllib.parse.urlencode(filters))
|
||||
url = "%s?%s" % (url, parse.urlencode(filters))
|
||||
return self._list(url, "services")
|
||||
|
||||
@api_versions.wraps("2.0", "2.10")
|
||||
|
@ -31,7 +31,6 @@ import time
|
||||
from oslo_utils import netutils
|
||||
from oslo_utils import strutils
|
||||
from oslo_utils import timeutils
|
||||
import six
|
||||
|
||||
import novaclient
|
||||
from novaclient import api_versions
|
||||
@ -478,7 +477,7 @@ def _boot(cs, args):
|
||||
# NOTE(vish): multiple copies of the same hint will
|
||||
# result in a list of values
|
||||
if key in hints:
|
||||
if isinstance(hints[key], six.string_types):
|
||||
if isinstance(hints[key], str):
|
||||
hints[key] = [hints[key]]
|
||||
hints[key] += [value]
|
||||
else:
|
||||
@ -2447,7 +2446,7 @@ def _print_server(cs, args, server=None, wrap=0):
|
||||
try:
|
||||
networks = server.networks
|
||||
except Exception as e:
|
||||
raise exceptions.CommandError(six.text_type(e))
|
||||
raise exceptions.CommandError(str(e))
|
||||
|
||||
info = server.to_dict()
|
||||
for network_label, address_list in networks.items():
|
||||
@ -2556,7 +2555,7 @@ def _find_server(cs, server, raise_if_notfound=True, **find_args):
|
||||
return utils.find_resource(cs.servers, server,
|
||||
wrap_exception=False)
|
||||
except exceptions.NoUniqueMatch as e:
|
||||
raise exceptions.CommandError(six.text_type(e))
|
||||
raise exceptions.CommandError(str(e))
|
||||
except exceptions.NotFound:
|
||||
# The server can be deleted
|
||||
return server
|
||||
@ -2567,7 +2566,7 @@ def _find_image(cs, image):
|
||||
try:
|
||||
return cs.glance.find_image(image)
|
||||
except (exceptions.NotFound, exceptions.NoUniqueMatch) as e:
|
||||
raise exceptions.CommandError(six.text_type(e))
|
||||
raise exceptions.CommandError(str(e))
|
||||
|
||||
|
||||
def _find_images(cs, images):
|
||||
@ -2575,7 +2574,7 @@ def _find_images(cs, images):
|
||||
try:
|
||||
return cs.glance.find_images(images)
|
||||
except (exceptions.NotFound, exceptions.NoUniqueMatch) as e:
|
||||
raise exceptions.CommandError(six.text_type(e))
|
||||
raise exceptions.CommandError(str(e))
|
||||
|
||||
|
||||
def _find_flavor(cs, flavor):
|
||||
@ -2591,7 +2590,7 @@ def _find_network_id(cs, net_name):
|
||||
try:
|
||||
return cs.neutron.find_network(net_name).id
|
||||
except (exceptions.NotFound, exceptions.NoUniqueMatch) as e:
|
||||
raise exceptions.CommandError(six.text_type(e))
|
||||
raise exceptions.CommandError(str(e))
|
||||
|
||||
|
||||
def _print_volume(volume):
|
||||
|
@ -16,7 +16,7 @@
|
||||
version interface
|
||||
"""
|
||||
|
||||
from six.moves import urllib
|
||||
from urllib import parse
|
||||
|
||||
from novaclient import base
|
||||
from novaclient import exceptions as exc
|
||||
@ -79,7 +79,7 @@ class VersionManager(base.ManagerWithFind):
|
||||
"""List all versions."""
|
||||
|
||||
endpoint = self.api.client.get_endpoint()
|
||||
url = urllib.parse.urlparse(endpoint)
|
||||
url = parse.urlparse(endpoint)
|
||||
# NOTE(andreykurilin): endpoint URL has at least 3 formats:
|
||||
# 1. the classic (legacy) endpoint:
|
||||
# http://{host}:{optional_port}/v{2 or 2.1}/{project-id}
|
||||
|
@ -9,5 +9,4 @@ oslo.serialization!=2.19.1,>=2.18.0 # Apache-2.0
|
||||
oslo.utils>=3.33.0 # Apache-2.0
|
||||
PrettyTable<0.8,>=0.7.2 # BSD
|
||||
simplejson>=3.5.1 # MIT
|
||||
six>=1.10.0 # MIT
|
||||
Babel!=2.4.0,>=2.3.4 # BSD
|
||||
|
Loading…
Reference in New Issue
Block a user