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
This commit is contained in:
parent
c339eb910f
commit
47756407a0
@ -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 zaqarclient.queues import client as zaqar
|
||||
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 @@ class Clients(object):
|
||||
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 @@ class OSClientsTestCase(test.TestCase):
|
||||
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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user