summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2019-02-25 18:32:28 +0000
committerGerrit Code Review <review@openstack.org>2019-02-25 18:32:28 +0000
commitcaf1f6203a6780ee9584a20549390bdce022a5fb (patch)
tree768e95d88fab2f8c8fcdca132b0510b90d9f7619
parent14a45183ee9558281fd38a60471adf5db55637c8 (diff)
parent4450e7ba3176cd26cdfa758355f8ed4ad8bacab2 (diff)
downloadpython-novaclient-caf1f6203a6780ee9584a20549390bdce022a5fb.tar.gz
Merge "Handle unicode multi-byte characters"
-rw-r--r--novaclient/tests/unit/fixture_data/hypervisors.py28
-rw-r--r--novaclient/tests/unit/v2/fakes.py8
-rw-r--r--novaclient/tests/unit/v2/test_hypervisors.py12
-rw-r--r--novaclient/tests/unit/v2/test_instance_usage_audit_log.py6
-rw-r--r--novaclient/v2/hypervisors.py4
-rw-r--r--novaclient/v2/instance_usage_audit_log.py4
6 files changed, 62 insertions, 0 deletions
diff --git a/novaclient/tests/unit/fixture_data/hypervisors.py b/novaclient/tests/unit/fixture_data/hypervisors.py
index 1e706786..48d7efc8 100644
--- a/novaclient/tests/unit/fixture_data/hypervisors.py
+++ b/novaclient/tests/unit/fixture_data/hypervisors.py
@@ -10,6 +10,9 @@
# License for the specific language governing permissions and limitations
# under the License.
+from oslo_utils import encodeutils
+from six.moves.urllib import parse
+
from novaclient import api_versions
from novaclient.tests.unit.fixture_data import base
@@ -130,6 +133,31 @@ class V1(base.Fixture):
json=get_os_hypervisors_search,
headers=self.headers)
+ if uuid_as_id:
+ get_os_hypervisors_search_u_v2_53 = {
+ 'error_name': 'BadRequest',
+ 'message': 'Invalid input for query parameters '
+ 'hypervisor_hostname_pattern.',
+ 'code': 400}
+ # hypervisor_hostname_pattern is encoded in the url method
+ url = self.url(hypervisor_hostname_pattern='\\u5de5\\u4f5c')
+ self.requests_mock.get(url,
+ json=get_os_hypervisors_search_u_v2_53,
+ headers=self.headers, status_code=400)
+ else:
+ get_os_hypervisors_search_unicode = {
+ 'error_name': 'NotFound',
+ 'message': "No hypervisor matching "
+ "'\\u5de5\\u4f5c' could be found.",
+ 'code': 404
+ }
+ hypervisor_hostname_pattern = parse.quote(encodeutils.safe_encode(
+ '\\u5de5\\u4f5c'))
+ url = self.url(hypervisor_hostname_pattern, 'search')
+ self.requests_mock.get(url,
+ json=get_os_hypervisors_search_unicode,
+ headers=self.headers, status_code=404)
+
get_hyper_server = {
'hypervisors': [
{
diff --git a/novaclient/tests/unit/v2/fakes.py b/novaclient/tests/unit/v2/fakes.py
index 0b72a677..a1e298e7 100644
--- a/novaclient/tests/unit/v2/fakes.py
+++ b/novaclient/tests/unit/v2/fakes.py
@@ -126,6 +126,7 @@ class FakeSessionClient(base_client.SessionClient):
munged_url = munged_url.replace('@', '_')
munged_url = munged_url.replace('%20', '_')
munged_url = munged_url.replace('%3A', '_')
+ munged_url = munged_url.replace('%', '_')
callback = "%s_%s" % (method.lower(), munged_url)
if url is None or callback == "get_http:__nova_api:8774":
@@ -176,6 +177,10 @@ class FakeSessionClient(base_client.SessionClient):
"text": body,
"headers": headers,
})
+
+ if status >= 400:
+ raise exceptions.from_response(r, body, url, method)
+
return r, body
def get_versions(self):
@@ -2167,6 +2172,9 @@ class FakeSessionClient(base_client.SessionClient):
"total_errors": 3,
"total_instances": 6}})
+ def get_os_instance_usage_audit_log__5Cu5de5_5Cu4f5c(self, **kw):
+ return (400, {}, {"Invalid timestamp for date \u6f22\u5b57"})
+
def post_servers_uuid1_action(self, **kw):
return 202, {}, {}
diff --git a/novaclient/tests/unit/v2/test_hypervisors.py b/novaclient/tests/unit/v2/test_hypervisors.py
index 0a3a2514..0c24209b 100644
--- a/novaclient/tests/unit/v2/test_hypervisors.py
+++ b/novaclient/tests/unit/v2/test_hypervisors.py
@@ -14,6 +14,7 @@
# under the License.
from novaclient import api_versions
+from novaclient import exceptions
from novaclient.tests.unit.fixture_data import client
from novaclient.tests.unit.fixture_data import hypervisors as data
from novaclient.tests.unit import utils
@@ -107,6 +108,17 @@ class HypervisorsTest(utils.FixturedTestCase):
for idx, hyper in enumerate(result):
self.compare_to_expected(expected[idx], hyper)
+ def test_hypervisor_search_unicode(self):
+ hypervisor_match = u'\\u5de5\\u4f5c'
+ if self.cs.api_version >= api_versions.APIVersion('2.53'):
+ self.assertRaises(exceptions.BadRequest,
+ self.cs.hypervisors.search,
+ hypervisor_match)
+ else:
+ self.assertRaises(exceptions.NotFound,
+ self.cs.hypervisors.search,
+ hypervisor_match)
+
def test_hypervisor_servers(self):
expected = [
dict(id=self.data_fixture.hyper_id_1,
diff --git a/novaclient/tests/unit/v2/test_instance_usage_audit_log.py b/novaclient/tests/unit/v2/test_instance_usage_audit_log.py
index 148ebbda..f3cb65cd 100644
--- a/novaclient/tests/unit/v2/test_instance_usage_audit_log.py
+++ b/novaclient/tests/unit/v2/test_instance_usage_audit_log.py
@@ -14,6 +14,7 @@
# under the License.
from novaclient import api_versions
+from novaclient import exceptions
from novaclient.tests.unit import utils
from novaclient.tests.unit.v2 import fakes
@@ -35,3 +36,8 @@ class InstanceUsageAuditLogTests(utils.TestCase):
self.cs.assert_called(
'GET',
'/os-instance_usage_audit_log/2016-12-10%2013%3A59%3A59.999999')
+
+ def test_instance_usage_audit_log_with_before_unicode(self):
+ before = u'\\u5de5\\u4f5c'
+ self.assertRaises(exceptions.BadRequest,
+ self.cs.instance_usage_audit_log.get, before)
diff --git a/novaclient/v2/hypervisors.py b/novaclient/v2/hypervisors.py
index e43ef7a1..f457fa08 100644
--- a/novaclient/v2/hypervisors.py
+++ b/novaclient/v2/hypervisors.py
@@ -17,6 +17,8 @@
Hypervisors interface
"""
+from oslo_utils import encodeutils
+import six
from six.moves.urllib import parse
from novaclient import api_versions
@@ -83,6 +85,8 @@ class HypervisorManager(base.ManagerWithFind):
# Starting with microversion 2.53, the /servers and /search routes are
# deprecated and we get the same results using GET /os-hypervisors
# using query parameters for the hostname pattern and servers.
+ if six.PY2:
+ hypervisor_match = encodeutils.safe_encode(hypervisor_match)
if self.api_version >= api_versions.APIVersion('2.53'):
url = ('/os-hypervisors?hypervisor_hostname_pattern=%s' %
parse.quote(hypervisor_match, safe=''))
diff --git a/novaclient/v2/instance_usage_audit_log.py b/novaclient/v2/instance_usage_audit_log.py
index 19b588e9..9ada06c1 100644
--- a/novaclient/v2/instance_usage_audit_log.py
+++ b/novaclient/v2/instance_usage_audit_log.py
@@ -13,6 +13,8 @@
# License for the specific language governing permissions and limitations
# under the License.
+from oslo_utils import encodeutils
+import six
from six.moves.urllib import parse
from novaclient import base
@@ -32,6 +34,8 @@ class InstanceUsageAuditLogManager(base.Manager):
before which to list usage audits.
"""
if before:
+ if six.PY2:
+ before = encodeutils.safe_encode(before)
return self._get('/os-instance_usage_audit_log/%s' %
parse.quote(before, safe=''),
'instance_usage_audit_log')