| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
import os |
| 14 |
|
| 15 |
from keystoneauth1 import loading |
| 16 |
from keystoneauth1 import session |
| 17 |
from openstack import config as occ |
| 18 |
from tempest.lib.cli import base |
| 19 |
|
| 20 |
import glanceclient |
| 21 |
|
| 22 |
|
| 23 |
def credentials(cloud='devstack-admin'): |
| 24 |
"""Retrieves credentials to run functional tests |
| 25 |
|
| 26 |
Credentials are either read via os-client-config from the environment |
| 27 |
or from a config file ('clouds.yaml'). Environment variables override |
| 28 |
those from the config file. |
| 29 |
|
| 30 |
devstack produces a clouds.yaml with two named clouds - one named |
| 31 |
'devstack' which has user privs and one named 'devstack-admin' which |
| 32 |
has admin privs. This function will default to getting the devstack-admin |
| 33 |
cloud as that is the current expected behavior. |
| 34 |
""" |
| 35 |
|
| 36 |
return occ.OpenStackConfig().get_one(cloud=cloud) |
| 37 |
|
| 38 |
|
| 39 |
class ClientTestBase(base.ClientTestBase): |
| 40 |
"""This is a first pass at a simple read only python-glanceclient test. |
| 41 |
|
| 42 |
This only exercises client commands that are read only. |
| 43 |
This should test commands: |
| 44 |
* as a regular user |
| 45 |
* as an admin user |
| 46 |
* with and without optional parameters |
| 47 |
* initially just check return codes, and later test command outputs |
| 48 |
|
| 49 |
""" |
| 50 |
|
| 51 |
def _get_clients(self): |
| 52 |
self.creds = credentials().get_auth_args() |
| 53 |
venv_name = os.environ.get('OS_TESTENV_NAME', 'functional') |
| 54 |
cli_dir = os.environ.get( |
| 55 |
'OS_GLANCECLIENT_EXEC_DIR', |
| 56 |
os.path.join(os.path.abspath('.'), '.tox/%s/bin' % venv_name)) |
| 57 |
|
| 58 |
return base.CLIClient( |
| 59 |
username=self.creds['username'], |
| 60 |
password=self.creds['password'], |
| 61 |
tenant_name=self.creds['project_name'], |
| 62 |
user_domain_id=self.creds['user_domain_id'], |
| 63 |
project_domain_id=self.creds['project_domain_id'], |
| 64 |
uri=self.creds['auth_url'], |
| 65 |
cli_dir=cli_dir) |
| 66 |
|
| 67 |
def glance(self, *args, **kwargs): |
| 68 |
return self.clients.glance(*args, |
| 69 |
**kwargs) |
| 70 |
|
| 71 |
def glance_pyclient(self): |
| 72 |
ks_creds = dict( |
| 73 |
auth_url=self.creds["auth_url"], |
| 74 |
username=self.creds["username"], |
| 75 |
password=self.creds["password"], |
| 76 |
project_name=self.creds["project_name"], |
| 77 |
user_domain_id=self.creds["user_domain_id"], |
| 78 |
project_domain_id=self.creds["project_domain_id"]) |
| 79 |
keystoneclient = self.Keystone(**ks_creds) |
| 80 |
return self.Glance(keystoneclient) |
| 81 |
|
| 82 |
class Keystone(object): |
| 83 |
def __init__(self, **kwargs): |
| 84 |
loader = loading.get_plugin_loader("password") |
| 85 |
auth = loader.load_from_options(**kwargs) |
| 86 |
self.session = session.Session(auth=auth) |
| 87 |
|
| 88 |
class Glance(object): |
| 89 |
def __init__(self, keystone, version="2"): |
| 90 |
self.glance = glanceclient.Client( |
| 91 |
version, |
| 92 |
session=keystone.session) |
| 93 |
|
| 94 |
def find(self, image_name): |
| 95 |
for image in self.glance.images.list(): |
| 96 |
if image.name == image_name: |
| 97 |
return image |
| 98 |
return None |