Add functions to fetch OS_* env variables from stackrc and overcloudrc files
Change-Id: I27053aae5836820e624d0f5e1140fcb779610736
This commit is contained in:
parent
f59e2e441f
commit
99f0636433
|
@ -20,7 +20,6 @@ from tobiko.shell import sh
|
|||
from tobiko.tripleo import undercloud
|
||||
|
||||
CONF = config.CONF
|
||||
TRIPLEO_CONF = CONF.tobiko.tripleo
|
||||
|
||||
|
||||
@undercloud.skip_if_missing_undercloud
|
||||
|
@ -34,13 +33,15 @@ class UndercloudSshConnectionTest(testtools.TestCase):
|
|||
self.ssh_client.connect()
|
||||
|
||||
def test_fetch_undercloud_credentials(self):
|
||||
self._test_fetch_credentials(rcfile=TRIPLEO_CONF.undercloud_rcfile)
|
||||
env = undercloud.load_undercloud_rcfile()
|
||||
self._test_fetch_credentials(env=env)
|
||||
|
||||
def test_fetch_overcloud_credentials(self):
|
||||
self._test_fetch_credentials(rcfile=TRIPLEO_CONF.overcloud_rcfile)
|
||||
env = undercloud.load_overcloud_rcfile()
|
||||
self._test_fetch_credentials(env=env)
|
||||
|
||||
def _test_fetch_credentials(self, env):
|
||||
|
||||
def _test_fetch_credentials(self, rcfile):
|
||||
env = self.fetch_os_env(rcfile=rcfile)
|
||||
self.assertTrue(env['OS_AUTH_URL'])
|
||||
self.assertTrue(env.get('OS_USERNAME') or env.get('OS_USER_ID'))
|
||||
self.assertTrue(env['OS_PASSWORD'])
|
||||
|
@ -49,15 +50,6 @@ class UndercloudSshConnectionTest(testtools.TestCase):
|
|||
env.get('OS_TENANT_ID') or
|
||||
env.get('OS_PROJECT_ID'))
|
||||
|
||||
def fetch_os_env(self, rcfile):
|
||||
command = ". {rcfile}; env | grep '^OS_'".format(rcfile=rcfile)
|
||||
result = sh.execute(command, ssh_client=self.ssh_client)
|
||||
env = {}
|
||||
for line in result.stdout.splitlines():
|
||||
name, value = line.split('=')
|
||||
env[name] = value
|
||||
return env
|
||||
|
||||
def test_execute_command(self):
|
||||
result = sh.execute('hostname', ssh_client=self.ssh_client)
|
||||
self.assertTrue(result.stdout.startswith('undercloud-0'))
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
from __future__ import absolute_import
|
||||
|
||||
import tobiko
|
||||
|
||||
from tobiko.shell import ssh
|
||||
from tobiko.shell import sh
|
||||
from tobiko import config
|
||||
|
||||
CONF = config.CONF
|
||||
|
||||
|
||||
def undercloud_ssh_client():
|
||||
|
@ -14,6 +17,24 @@ def undercloud_host_config():
|
|||
return tobiko.setup_fixture(UndecloudHostConfig)
|
||||
|
||||
|
||||
def fetch_os_env(rcfile):
|
||||
command = ". {rcfile}; env | grep '^OS_'".format(rcfile=rcfile)
|
||||
result = sh.execute(command, ssh_client=undercloud_ssh_client())
|
||||
env = {}
|
||||
for line in result.stdout.splitlines():
|
||||
name, value = line.split('=')
|
||||
env[name] = value
|
||||
return env
|
||||
|
||||
|
||||
def load_undercloud_rcfile():
|
||||
return fetch_os_env(rcfile=CONF.tobiko.tripleo.undercloud_rcfile)
|
||||
|
||||
|
||||
def load_overcloud_rcfile():
|
||||
return fetch_os_env(rcfile=CONF.tobiko.tripleo.overcloud_rcfile)
|
||||
|
||||
|
||||
def has_undercloud():
|
||||
host_config = undercloud_host_config()
|
||||
return bool(host_config.hostname)
|
||||
|
@ -33,9 +54,7 @@ class UndecloudHostConfig(tobiko.SharedFixture):
|
|||
key_filename = None
|
||||
|
||||
def setup_fixture(self):
|
||||
from tobiko import config
|
||||
conf = config.CONF.tobiko.tripleo
|
||||
self.hostname = conf.undercloud_ssh_hostname
|
||||
self.port = conf.undercloud_ssh_port
|
||||
self.username = conf.undercloud_ssh_username
|
||||
self.key_filename = conf.ssh_key_filename
|
||||
self.hostname = CONF.tobiko.tripleo.undercloud_ssh_hostname
|
||||
self.port = CONF.tobiko.tripleo.undercloud_ssh_port
|
||||
self.username = CONF.tobiko.tripleo.undercloud_ssh_username
|
||||
self.key_filename = CONF.tobiko.tripleo.ssh_key_filename
|
||||
|
|
Loading…
Reference in New Issue