Files
zaza-openstack-tests/zaza/openstack/charm_tests/kerberos/tests.py
Camille Rodriguez 3f8a09605e Add functional tests for charm-keystone-kerberos (#206)
* kerberos authentication tests

* kerberos authentication setup and test

* kerberos authentication setup and test

* kerberos authentication setup and test

* pep8 corrections

* pep8 corrections

* remove hardcoded code

* add logging

* fix keytab location

* add logging

* add logging and custom exception for kerberos test server errors

* syntax list

* adding empty keytab in setup

* pep8

* Kerberos custom exception

* date

* fix creation of empty file

* logging

* wait until workload is active

* wait until workload is active

* Edit tests for optimal configuration and logging

* remove empty lines

* add logging to tests

* add logging to tests, import subprocess

* tests.py need setup.py get_unit_full_hostname function

* token retrieval test

* add dns to test host as well as keystone

* test keystone token

* user needs to be the one created in the kerberos system (i.e admin)

* openstack token issue to confirm authentication

* openstack token issue to confirm authentication

* pep8

* cmd has to be formatted differently for subprocess call

* fix error

* piping password to the kinit prompt

* add a verification for the cached kerberos token file

* add a verification for the cached kerberos token file

* must wait for subprocess to go through to check result

* change config to run the kerberos client tests on a ubuntu vm

* change config to run the kerberos client tests on a ubuntu vm

* change config to run the kerberos client tests on a ubuntu vm

* install krb5-client on ubuntu test host

* install krb5-client on ubuntu test host

* retrieve openstack token

* stderr is a dict

* adding python-pip and keystoneauth1[kerberos]

* adding python-pip and keystoneauth1[kerberos]

* adding python-pip and keystoneauth1[kerberos]

* add other mandatory packages to test host

* pep8

* unused exception, removing

* revert change

* rename run_all_tests for run_all_configuration_tests

* install the python3 packages
2020-03-30 16:36:50 -05:00

75 lines
3.1 KiB
Python

# Copyright 2020 Canonical Ltd.
#
# 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.
"""Keystone Kerberos Tests."""
import logging
import zaza.model
from zaza.openstack.charm_tests.kerberos.setup import get_unit_full_hostname
from zaza.openstack.charm_tests.keystone import BaseKeystoneTest
from zaza.openstack.utilities import openstack as openstack_utils
class CharmKeystoneKerberosTest(BaseKeystoneTest):
"""Charm Keystone Kerberos Test."""
@classmethod
def setUpClass(cls):
"""Run class setup for running Keystone Kerberos charm tests."""
super(CharmKeystoneKerberosTest, cls).setUpClass()
def test_keystone_kerberos_authentication(self):
"""Validate auth to Openstack through the kerberos method."""
logging.info('Retrieving a kerberos token with kinit for admin user')
ubuntu_test_host = zaza.model.get_units('ubuntu-test-host')[0]
result = zaza.model.run_on_unit(ubuntu_test_host.name,
"echo password123 | kinit admin")
assert result['Code'] == '0', result['Stderr']
logging.info('Changing token mod for user access')
result = zaza.model.run_on_unit(
ubuntu_test_host.name,
"sudo install -m 777 /tmp/krb5cc_0 /tmp/krb5cc_1000"
)
assert result['Code'] == '0', result['Stderr']
logging.info('Fetching user/project info in Openstack')
domain_name = 'k8s'
project_name = 'k8s'
keystone_session = openstack_utils.get_overcloud_keystone_session()
keystone_client = openstack_utils.get_keystone_session_client(
keystone_session)
domain_id = keystone_client.domains.find(name=domain_name).id
project_id = keystone_client.projects.find(name=project_name).id
keystone_hostname = get_unit_full_hostname('keystone')
logging.info('Retrieving an Openstack token to validate auth')
cmd = 'openstack token issue -f value -c id ' \
'--os-auth-url http://{}:5000/krb/v3 ' \
'--os-project-id {} ' \
'--os-project-name {} ' \
'--os-project-domain-id {} ' \
'--os-region-name RegionOne ' \
'--os-interface public ' \
'--os-identity-api-version 3 ' \
'--os-auth-type v3kerberos'.format(keystone_hostname,
project_id,
project_name,
domain_id)
result = zaza.model.run_on_unit(ubuntu_test_host.name, cmd)
assert result['Code'] == '0', result['Stderr']