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