Because openstacksdk superseded os-client-config module, it is recommended to use this module instead. Story: 2002021 Task: 19662 Change-Id: I6f225416ff4791a00b04655614eb8f24bed8ae7b
5.3 KiB
Use python-tempestconf as Python module
python-tempestconf
can be imported and used from a
different Python project.
Warning
The import of config_tempest is possible only when the version of the tool is at least 2.0.0.
Installation
See our Install Guide on
how to install python-tempestconf
.
Import
Import python-tempestconf
in your project as
follows:
from config_tempest import main as tempestconf
python-tempestconf
needs cloud credentials in order to
create a tempest configuration file. There is a helper method for
obtaining cloud credentials which uses openstacksdk
for parsing the cloud for credentials.
The following example shows how to get cloud credentials and how to pass it to the configuration tool:
# The following call will return a dict containing cloud credentials,
# for example:
# >>> tempestconf.get_cloud_creds(args_namespace)
# {
# 'username': 'demo',
# 'project_name': 'demo',
# 'user_domain_name': 'Default',
# 'auth_url': 'http://172.16.52.8:5000/v3',
# 'password': 'f0921edc3c2b4fc8',
# 'project_domain_name': 'Default'
# }
= tempestconf.get_cloud_creds(args_namespace)
cloud_creds
# Then the configuration step can be run using:
=cloud_creds) tempestconf.config_tempest(cloud_creds
Note
If args_namespace contains
--os-cloud
argument, the get_cloud_creds method returns cloud
credentials related to that cloud, otherwise, it returns credentials of
the current cloud (according to the sourced credentials).
List of arguments which may be passed to config_tempest
- cloud_creds
- create
- create_accounts_file
- debug
- deployer_input
- image_disk_format
- image_path
- network_id
- non_admin
- os_cloud
- out
- overrides
- remove
- test_accounts
- verbose
OR
- profile, see why or in CLI documentation
Note
For detailed description of the options see our CLI documentation
Example implementation
Save following code snippet as
example.py
:import argparse from config_tempest import main as tempestconf = argparse.ArgumentParser(description='Example implementation.') parser = parser.parse_args() args # get the credentials of the current cloud according to # the sourced credentials = tempestconf.get_cloud_creds(args) cloud_creds =True, tempestconf.config_tempest(non_admin='./etc/tempest.conf', out=cloud_creds) cloud_creds
Source your OpenStack RC file containing the cloud credentials. Let's say you have a overcloud_rc file with the following content:
$ cat overcloud_rc unset OS_SERVICE_TOKEN export OS_USERNAME=demo export OS_PASSWORD='password' export OS_AUTH_URL=http://172.16.52.15/identity/v3 export PS1='[\u@\h \W(keystone_demo)]\$ ' export OS_PROJECT_NAME=demo export OS_USER_DOMAIN_NAME=default export OS_PROJECT_DOMAIN_NAME=default export OS_IDENTITY_API_VERSION=3
Then it can be source by:
$ source overcloud_rc
Run
example.py
:$ python example.py
Example implementation with a named cloud
Let's say there is a
clouds.yaml
file located in/etc/openstack/
with the following content:$ cat /etc/openstack/clouds.yaml clouds: devstack: auth: auth_url: http://172.16.52.15/identity/v3 password: password project_domain_id: default project_name: demo user_domain_id: default username: demo identity_api_version: '3' region_name: RegionOne volume_api_version: '2'
Save following code snippet as
example.py
:import argparse from config_tempest import main as tempestconf = argparse.ArgumentParser(description='Example implementation.') parser # Let's add an os_cloud option which will be passed # to config_tempest later. '--os-cloud', help='Name of a named cloud.') parser.add_argument(= parser.parse_args() args # get the credentials to the devstack cloud = tempestconf.get_cloud_creds(args) cloud_creds =True, tempestconf.config_tempest(non_admin='./etc/tempest.conf', out=cloud_creds) cloud_creds
Run
example.py
:$ python example.py --os-cloud devstack
Note
In this example you don't need to source cloud credentials. The credentials are obtained from the
/etc/openstack/clouds.yaml
file thanks to--os-cloud
argument.