Switch to basic auth in functional tests and fix encoding
Sure there's less parenthesis than in Lisp but then you made much more mistake like that. Also added a test to make sure I got it right this time, dummy. Change-Id: Ib63c71a750e41029d6f230a5e7518f84146a606a
This commit is contained in:
parent
069108306f
commit
f14fe0e03b
|
@ -92,7 +92,8 @@ class GnocchiBasicPlugin(plugin.BaseAuthPlugin):
|
||||||
def get_headers(self, session, **kwargs):
|
def get_headers(self, session, **kwargs):
|
||||||
return {
|
return {
|
||||||
'Authorization':
|
'Authorization':
|
||||||
b"basic " + base64.b64encode(self._user + b":").decode('ascii')
|
(b"basic " + base64.b64encode(
|
||||||
|
self._user + b":")).decode('ascii')
|
||||||
}
|
}
|
||||||
|
|
||||||
def get_endpoint(self, session, **kwargs):
|
def get_endpoint(self, session, **kwargs):
|
||||||
|
|
|
@ -16,8 +16,6 @@ import six
|
||||||
import subprocess
|
import subprocess
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from oslo_utils import uuidutils
|
|
||||||
|
|
||||||
from tempest.lib.cli import base
|
from tempest.lib.cli import base
|
||||||
from tempest.lib import exceptions
|
from tempest.lib import exceptions
|
||||||
|
|
||||||
|
@ -31,16 +29,12 @@ class GnocchiClient(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.cli_dir = os.environ.get('GNOCCHI_CLIENT_EXEC_DIR')
|
self.cli_dir = os.environ.get('GNOCCHI_CLIENT_EXEC_DIR')
|
||||||
self.endpoint = os.environ.get('PIFPAF_GNOCCHI_HTTP_URL')
|
self.endpoint = os.environ.get('PIFPAF_GNOCCHI_HTTP_URL')
|
||||||
self.user_id = uuidutils.generate_uuid()
|
|
||||||
self.project_id = uuidutils.generate_uuid()
|
|
||||||
|
|
||||||
def gnocchi(self, action, flags='', params='',
|
def gnocchi(self, action, flags='', params='',
|
||||||
fail_ok=False, merge_stderr=False, input=None):
|
fail_ok=False, merge_stderr=False, input=None):
|
||||||
creds = ("--os-auth-plugin gnocchi-noauth "
|
creds = ("--os-auth-plugin gnocchi-basic "
|
||||||
"--user-id %s --project-id %s "
|
"--user admin "
|
||||||
"--endpoint %s") % (self.user_id,
|
"--endpoint %s") % self.endpoint
|
||||||
self.project_id,
|
|
||||||
self.endpoint)
|
|
||||||
|
|
||||||
flags = creds + ' ' + flags
|
flags = creds + ' ' + flags
|
||||||
|
|
||||||
|
|
|
@ -63,9 +63,9 @@ class MetricClientTest(base.ClientTestBase):
|
||||||
u" --archive-policy-name metric-test some-name")
|
u" --archive-policy-name metric-test some-name")
|
||||||
metric = self.details_multiple(result)[0]
|
metric = self.details_multiple(result)[0]
|
||||||
self.assertIsNotNone(metric["id"])
|
self.assertIsNotNone(metric["id"])
|
||||||
self.assertEqual(self.clients.project_id,
|
self.assertEqual("admin", metric["creator"])
|
||||||
metric["created_by_project_id"])
|
self.assertEqual("", metric["created_by_project_id"])
|
||||||
self.assertEqual(self.clients.user_id, metric["created_by_user_id"])
|
self.assertEqual("admin", metric["created_by_user_id"])
|
||||||
self.assertEqual('some-name', metric["name"])
|
self.assertEqual('some-name', metric["name"])
|
||||||
self.assertEqual('None', metric["unit"])
|
self.assertEqual('None', metric["unit"])
|
||||||
self.assertEqual('None', metric["resource/id"])
|
self.assertEqual('None', metric["resource/id"])
|
||||||
|
@ -78,9 +78,9 @@ class MetricClientTest(base.ClientTestBase):
|
||||||
u" --unit some-unit")
|
u" --unit some-unit")
|
||||||
metric = self.details_multiple(result)[0]
|
metric = self.details_multiple(result)[0]
|
||||||
self.assertIsNotNone(metric["id"])
|
self.assertIsNotNone(metric["id"])
|
||||||
self.assertEqual(self.clients.project_id,
|
self.assertEqual("admin", metric["creator"])
|
||||||
metric["created_by_project_id"])
|
self.assertEqual("", metric["created_by_project_id"])
|
||||||
self.assertEqual(self.clients.user_id, metric["created_by_user_id"])
|
self.assertEqual("admin", metric["created_by_user_id"])
|
||||||
self.assertEqual('another-name', metric["name"])
|
self.assertEqual('another-name', metric["name"])
|
||||||
self.assertEqual('some-unit', metric["unit"])
|
self.assertEqual('some-unit', metric["unit"])
|
||||||
self.assertEqual('None', metric["resource/id"])
|
self.assertEqual('None', metric["resource/id"])
|
||||||
|
@ -226,9 +226,9 @@ class MetricClientTest(base.ClientTestBase):
|
||||||
u" --unit some-unit")
|
u" --unit some-unit")
|
||||||
metric = self.details_multiple(result)[0]
|
metric = self.details_multiple(result)[0]
|
||||||
self.assertIsNotNone(metric["id"])
|
self.assertIsNotNone(metric["id"])
|
||||||
self.assertEqual(self.clients.project_id,
|
self.assertEqual("", metric['created_by_project_id'])
|
||||||
metric["created_by_project_id"])
|
self.assertEqual("admin", metric['created_by_user_id'])
|
||||||
self.assertEqual(self.clients.user_id, metric["created_by_user_id"])
|
self.assertEqual("admin", metric['creator'])
|
||||||
self.assertEqual('metric-name', metric["name"])
|
self.assertEqual('metric-name', metric["name"])
|
||||||
self.assertEqual('some-unit', metric["unit"])
|
self.assertEqual('some-unit', metric["unit"])
|
||||||
self.assertNotEqual('None', metric["resource/id"])
|
self.assertNotEqual('None', metric["resource/id"])
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
# -*- encoding: utf-8 -*-
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
# not use this file except in compliance with the License. You may obtain
|
||||||
|
# a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
# License for the specific language governing permissions and limitations
|
||||||
|
# under the License.
|
||||||
|
|
||||||
|
from oslotest import base
|
||||||
|
|
||||||
|
from gnocchiclient import auth
|
||||||
|
|
||||||
|
|
||||||
|
class GnocchiBasicPluginTest(base.BaseTestCase):
|
||||||
|
def test_get_headers(self):
|
||||||
|
p = auth.GnocchiBasicPlugin("foobar", "http://localhost")
|
||||||
|
self.assertEqual({'Authorization': 'basic Zm9vYmFyOg=='},
|
||||||
|
p.get_headers(None))
|
Loading…
Reference in New Issue