Permalink
Browse files

Creating OS clients from the environment variables

Use `osclients.Clients.create_from_env' to create a Clients instance
from the environment variables. Useful for trying things in a Python
shell.

Change-Id: I807176183ff692f15b8700a8db1d0c231af3f5c6
  • Loading branch information...
Pavel Boldin
Pavel Boldin committed Feb 24, 2015
1 parent c339eb9 commit 47756407a0db02890542d2453e396d726cb3d909
Showing with 29 additions and 0 deletions.
  1. +14 −0 rally/osclients.py
  2. +15 −0 tests/unit/test_osclients.py
View
@@ -13,6 +13,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import os
from ceilometerclient import client as ceilometer
from cinderclient import client as cinder
from designateclient import v1 as designate
@@ -33,6 +35,7 @@
from rally.common import log as logging
from rally import consts
from rally import exceptions
from rally import objects
CONF = cfg.CONF
@@ -85,6 +88,17 @@ def __init__(self, endpoint):
self.endpoint = endpoint
self.cache = {}
@classmethod
def create_from_env(cls):
return cls(
objects.Endpoint(
os.environ["OS_AUTH_URL"],
os.environ["OS_USERNAME"],
os.environ["OS_PASSWORD"],
os.environ.get("OS_TENANT_NAME"),
region_name=os.environ.get("OS_REGION_NAME")
))
def clear(self):
"""Remove all cached client handles."""
self.cache = {}
@@ -47,6 +47,21 @@ def setUp(self):
def tearDown(self):
super(OSClientsTestCase, self).tearDown()
def test_create_from_env(self):
with mock.patch.dict("os.environ",
{"OS_AUTH_URL": "foo_auth_url",
"OS_USERNAME": "foo_username",
"OS_PASSWORD": "foo_password",
"OS_TENANT_NAME": "foo_tenant_name",
"OS_REGION_NAME": "foo_region_name"}):
clients = osclients.Clients.create_from_env()
self.assertEqual("foo_auth_url", clients.endpoint.auth_url)
self.assertEqual("foo_username", clients.endpoint.username)
self.assertEqual("foo_password", clients.endpoint.password)
self.assertEqual("foo_tenant_name", clients.endpoint.tenant_name)
self.assertEqual("foo_region_name", clients.endpoint.region_name)
def test_keystone(self):
self.assertNotIn("keystone", self.clients.cache)
client = self.clients.keystone()

0 comments on commit 4775640

Please sign in to comment.