2016-03-07 16:44:24 +02:00
|
|
|
# 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 six.moves.urllib import parse
|
2016-05-19 19:25:51 +08:00
|
|
|
import tempest.lib.cli.base
|
2016-03-07 16:44:24 +02:00
|
|
|
|
2017-01-12 13:18:25 +01:00
|
|
|
from novaclient import client
|
2016-03-07 16:44:24 +02:00
|
|
|
from novaclient.tests.functional import base
|
|
|
|
|
|
|
|
|
|
|
|
class TestAuthentication(base.ClientTestBase):
|
2017-01-12 13:18:25 +01:00
|
|
|
|
|
|
|
def _get_url(self, identity_api_version):
|
2016-03-07 16:44:24 +02:00
|
|
|
url = parse.urlparse(self.cli_clients.uri)
|
2017-01-12 13:18:25 +01:00
|
|
|
return parse.urlunparse((url.scheme, url.netloc,
|
|
|
|
'/identity/v%s' % identity_api_version,
|
|
|
|
url.params, url.query,
|
|
|
|
url.fragment))
|
|
|
|
|
|
|
|
def nova_auth_with_password(self, action, identity_api_version):
|
2016-03-07 16:44:24 +02:00
|
|
|
flags = ('--os-username %s --os-tenant-name %s --os-password %s '
|
2016-07-01 14:39:01 +03:00
|
|
|
'--os-auth-url %s --os-endpoint-type publicURL' % (
|
2016-03-07 16:44:24 +02:00
|
|
|
self.cli_clients.username,
|
|
|
|
self.cli_clients.tenant_name,
|
|
|
|
self.cli_clients.password,
|
2017-01-12 13:18:25 +01:00
|
|
|
self._get_url(identity_api_version)))
|
2016-03-07 16:44:24 +02:00
|
|
|
if self.cli_clients.insecure:
|
|
|
|
flags += ' --insecure '
|
|
|
|
|
2016-05-19 19:25:51 +08:00
|
|
|
return tempest.lib.cli.base.execute(
|
2016-03-07 16:44:24 +02:00
|
|
|
"nova", action, flags, cli_dir=self.cli_clients.cli_dir)
|
|
|
|
|
2017-01-12 13:18:25 +01:00
|
|
|
def nova_auth_with_token(self, identity_api_version):
|
|
|
|
auth_ref = self.client.client.session.auth.get_access(
|
|
|
|
self.client.client.session)
|
|
|
|
token = auth_ref.auth_token
|
|
|
|
auth_url = self._get_url(identity_api_version)
|
|
|
|
kw = {}
|
|
|
|
if identity_api_version == "3":
|
|
|
|
kw["project_domain_id"] = self.project_domain_id
|
|
|
|
nova = client.Client("2", auth_token=token, auth_url=auth_url,
|
|
|
|
project_name=self.project_name, **kw)
|
|
|
|
nova.servers.list()
|
|
|
|
|
2017-01-23 19:22:14 +02:00
|
|
|
flags = ('--os-tenant-name %(project_name)s --os-token %(token)s '
|
|
|
|
'--os-auth-url %(auth_url)s --os-endpoint-type publicURL'
|
|
|
|
% {"project_name": self.project_name,
|
|
|
|
"token": token, "auth_url": auth_url})
|
|
|
|
if self.cli_clients.insecure:
|
|
|
|
flags += ' --insecure '
|
|
|
|
|
|
|
|
tempest.lib.cli.base.execute(
|
|
|
|
"nova", "list", flags, cli_dir=self.cli_clients.cli_dir)
|
2017-01-12 13:18:25 +01:00
|
|
|
|
2016-03-07 16:44:24 +02:00
|
|
|
def test_auth_via_keystone_v2(self):
|
2016-07-01 14:36:03 +03:00
|
|
|
session = self.keystone.session
|
|
|
|
version = (2, 0)
|
|
|
|
if not base.is_keystone_version_available(session, version):
|
2017-01-12 13:18:25 +01:00
|
|
|
self.skipTest("Identity API version 2.0 is not available.")
|
2016-07-01 14:36:03 +03:00
|
|
|
|
2017-01-12 13:18:25 +01:00
|
|
|
self.nova_auth_with_password("list", identity_api_version="2.0")
|
|
|
|
self.nova_auth_with_token(identity_api_version="2.0")
|
2016-03-07 16:44:24 +02:00
|
|
|
|
|
|
|
def test_auth_via_keystone_v3(self):
|
2016-07-01 14:36:03 +03:00
|
|
|
session = self.keystone.session
|
|
|
|
version = (3, 0)
|
|
|
|
if not base.is_keystone_version_available(session, version):
|
2017-01-12 13:18:25 +01:00
|
|
|
self.skipTest("Identity API version 3.0 is not available.")
|
2016-07-01 14:36:03 +03:00
|
|
|
|
2017-01-12 13:18:25 +01:00
|
|
|
self.nova_auth_with_password("list", identity_api_version="3")
|
|
|
|
self.nova_auth_with_token(identity_api_version="3")
|