Try multiple tripleo RC files for OS credentials
Change-Id: I6e4a18bc712662171bb4b50d62e29ecf5cabd061
This commit is contained in:
parent
cce0efc4e0
commit
07fa7d1b3e
@ -22,7 +22,7 @@ import testtools
|
||||
|
||||
from tobiko import config
|
||||
from tobiko.openstack import nova
|
||||
from tobiko.tripleo import overcloud
|
||||
from tobiko import tripleo
|
||||
from tobiko.tripleo import pacemaker
|
||||
from tobiko.tripleo import services
|
||||
from tobiko.tripleo import processes
|
||||
@ -32,11 +32,11 @@ import tobiko
|
||||
CONF = config.CONF
|
||||
|
||||
|
||||
@overcloud.skip_if_missing_overcloud
|
||||
@tripleo.skip_if_missing_overcloud
|
||||
class OvercloudSshConnectionTest(testtools.TestCase):
|
||||
|
||||
def test_fetch_overcloud_credentials(self):
|
||||
env = overcloud.load_overcloud_rcfile()
|
||||
env = tripleo.load_overcloud_rcfile()
|
||||
self.assertTrue(env['OS_AUTH_URL'])
|
||||
self.assertTrue(env.get('OS_USERNAME') or env.get('OS_USER_ID'))
|
||||
self.assertTrue(env['OS_PASSWORD'])
|
||||
@ -46,11 +46,11 @@ class OvercloudSshConnectionTest(testtools.TestCase):
|
||||
env.get('OS_PROJECT_ID'))
|
||||
|
||||
|
||||
@overcloud.skip_if_missing_overcloud
|
||||
@tripleo.skip_if_missing_overcloud
|
||||
class OvercloudNovaApiTest(testtools.TestCase):
|
||||
|
||||
def test_list_overcloud_nodes(self):
|
||||
nodes = overcloud.list_overcloud_nodes()
|
||||
nodes = tripleo.list_overcloud_nodes()
|
||||
self.assertTrue(nodes)
|
||||
for node in nodes:
|
||||
node_ip = nova.find_server_ip_address(server=node,
|
||||
@ -58,19 +58,19 @@ class OvercloudNovaApiTest(testtools.TestCase):
|
||||
self.assertIsInstance(node_ip, netaddr.IPAddress)
|
||||
|
||||
def test_find_overcloud_nodes(self):
|
||||
node = overcloud.find_overcloud_node()
|
||||
node = tripleo.find_overcloud_node()
|
||||
node_ip = nova.find_server_ip_address(server=node,
|
||||
check_connectivity=True)
|
||||
self.assertIsInstance(node_ip, netaddr.IPAddress)
|
||||
|
||||
def test_get_overcloud_node_ip_address(self):
|
||||
overcloud_node_ip = overcloud.overcloud_node_ip_address()
|
||||
overcloud_node_ip = tripleo.overcloud_node_ip_address()
|
||||
self.assertIsInstance(overcloud_node_ip, netaddr.IPAddress)
|
||||
|
||||
def test_overcloud_host_config(self):
|
||||
hostname = overcloud.find_overcloud_node().name
|
||||
hostname = tripleo.find_overcloud_node().name
|
||||
host_config = tobiko.setup_fixture(
|
||||
overcloud.overcloud_host_config(hostname=hostname))
|
||||
tripleo.overcloud_host_config(hostname=hostname))
|
||||
self.assertEqual(hostname, host_config.host)
|
||||
self.assertIsInstance(host_config.hostname, six.string_types)
|
||||
netaddr.IPAddress(host_config.hostname)
|
||||
@ -85,12 +85,12 @@ class OvercloudNovaApiTest(testtools.TestCase):
|
||||
self.assertTrue(os.path.isfile(key_filename + '.pub'))
|
||||
|
||||
def test_overcloud_ssh_client_connection(self):
|
||||
hostname = overcloud.find_overcloud_node().name
|
||||
ssh_client = overcloud.overcloud_ssh_client(hostname=hostname)
|
||||
hostname = tripleo.find_overcloud_node().name
|
||||
ssh_client = tripleo.overcloud_ssh_client(hostname=hostname)
|
||||
ssh_client.connect()
|
||||
|
||||
|
||||
@overcloud.skip_if_missing_overcloud
|
||||
@tripleo.skip_if_missing_overcloud
|
||||
class OvercloudPacemakerTest(testtools.TestCase):
|
||||
"""
|
||||
Assert that all pacemaker resources are in
|
||||
@ -106,7 +106,7 @@ class OvercloudPacemakerTest(testtools.TestCase):
|
||||
self.assertTrue(pcs_health.all_healthy)
|
||||
|
||||
|
||||
@overcloud.skip_if_missing_overcloud
|
||||
@tripleo.skip_if_missing_overcloud
|
||||
class OvercloudServicesTest(testtools.TestCase):
|
||||
"""
|
||||
Assert that a subset of overcloud services are in running state
|
||||
@ -129,7 +129,7 @@ class OvercloudServicesTest(testtools.TestCase):
|
||||
self.assertIsInstance(nodes_list, list)
|
||||
|
||||
|
||||
@overcloud.skip_if_missing_overcloud
|
||||
@tripleo.skip_if_missing_overcloud
|
||||
class OvercloudProcessesTest(testtools.TestCase):
|
||||
"""
|
||||
Assert that a subset of overcloud processes are in running state
|
||||
@ -146,7 +146,7 @@ class OvercloudProcessesTest(testtools.TestCase):
|
||||
self.assertTrue(ops.basic_overcloud_processes_running)
|
||||
|
||||
|
||||
@overcloud.skip_if_missing_overcloud
|
||||
@tripleo.skip_if_missing_overcloud
|
||||
class OvercloudNeutronAgentsTest(testtools.TestCase):
|
||||
"""
|
||||
Assert that a the neutron agents are healthy
|
||||
|
@ -19,24 +19,24 @@ from tobiko import config
|
||||
from tobiko.shell import sh
|
||||
from tobiko.openstack import keystone
|
||||
from tobiko.openstack import nova
|
||||
from tobiko.tripleo import undercloud
|
||||
from tobiko import tripleo
|
||||
|
||||
|
||||
CONF = config.CONF
|
||||
|
||||
|
||||
@undercloud.skip_if_missing_undercloud
|
||||
@tripleo.skip_if_missing_undercloud
|
||||
class UndercloudSshConnectionTest(testtools.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(UndercloudSshConnectionTest, self).setUp()
|
||||
self.ssh_client = undercloud.undercloud_ssh_client()
|
||||
self.ssh_client = tripleo.undercloud_ssh_client()
|
||||
|
||||
def test_connect_to_undercloud(self):
|
||||
self.ssh_client.connect()
|
||||
|
||||
def test_fetch_undercloud_credentials(self):
|
||||
env = undercloud.load_undercloud_rcfile()
|
||||
env = tripleo.load_undercloud_rcfile()
|
||||
self.assertTrue(env['OS_AUTH_URL'])
|
||||
self.assertTrue(env.get('OS_USERNAME') or env.get('OS_USER_ID'))
|
||||
self.assertTrue(env['OS_PASSWORD'])
|
||||
@ -50,21 +50,21 @@ class UndercloudSshConnectionTest(testtools.TestCase):
|
||||
self.assertTrue(result.stdout.startswith('undercloud-0'))
|
||||
|
||||
|
||||
@undercloud.skip_if_missing_undercloud
|
||||
@tripleo.skip_if_missing_undercloud
|
||||
class UndercloudKeystoneClientTest(testtools.TestCase):
|
||||
|
||||
def test_undercloud_keystone_credentials(self):
|
||||
credentials = undercloud.undercloud_keystone_credentials()
|
||||
credentials = tripleo.undercloud_keystone_credentials()
|
||||
self.assertIsInstance(credentials, keystone.KeystoneCredentials)
|
||||
credentials.validate()
|
||||
|
||||
def test_undercloud_keystone_session(self):
|
||||
session = undercloud.undercloud_keystone_session()
|
||||
session = tripleo.undercloud_keystone_session()
|
||||
client = nova.get_nova_client(session=session)
|
||||
overcloud_nodes = nova.list_servers(client=client)
|
||||
self.assertTrue(overcloud_nodes)
|
||||
|
||||
def test_undercloud_keystone_client(self):
|
||||
client = undercloud.undercloud_keystone_client()
|
||||
client = tripleo.undercloud_keystone_client()
|
||||
services = keystone.list_services(client=client)
|
||||
self.assertTrue(services)
|
||||
|
@ -48,8 +48,8 @@ class UndercloudConfigTest(unit.TobikoUnitTest):
|
||||
six.string_types)
|
||||
|
||||
def test_undercloud_rcfile(self):
|
||||
self.assertIsInstance(TIPLEO_CONF.undercloud_rcfile,
|
||||
six.string_types)
|
||||
for rcfile in TIPLEO_CONF.undercloud_rcfile:
|
||||
self.assertIsInstance(rcfile, six.string_types)
|
||||
|
||||
|
||||
class OvercloudConfigTest(unit.TobikoUnitTest):
|
||||
@ -65,5 +65,5 @@ class OvercloudConfigTest(unit.TobikoUnitTest):
|
||||
six.string_types)
|
||||
|
||||
def test_overcloud_rcfile(self):
|
||||
self.assertIsInstance(TIPLEO_CONF.overcloud_rcfile,
|
||||
six.string_types)
|
||||
for rcfile in TIPLEO_CONF.overcloud_rcfile:
|
||||
self.assertIsInstance(rcfile, six.string_types)
|
||||
|
@ -14,6 +14,7 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
from tobiko.tripleo import _ansible
|
||||
from tobiko.tripleo import _overcloud as overcloud
|
||||
from tobiko.tripleo import _undercloud as undercloud
|
||||
|
||||
|
||||
@ -25,4 +26,17 @@ read_tripleo_ansible_inventory = _ansible.read_tripleo_ansible_inventory
|
||||
skip_if_missing_tripleo_ansible_inventory = \
|
||||
_ansible.skip_if_missing_tripleo_ansible_inventory
|
||||
|
||||
find_overcloud_node = overcloud.find_overcloud_node
|
||||
list_overcloud_nodes = overcloud.list_overcloud_nodes
|
||||
load_overcloud_rcfile = overcloud.load_overcloud_rcfile
|
||||
overcloud_host_config = overcloud.overcloud_host_config
|
||||
overcloud_node_ip_address = overcloud.overcloud_node_ip_address
|
||||
overcloud_ssh_client = overcloud.overcloud_ssh_client
|
||||
skip_if_missing_overcloud = overcloud.skip_if_missing_overcloud
|
||||
|
||||
load_undercloud_rcfile = undercloud.load_undercloud_rcfile
|
||||
skip_if_missing_undercloud = undercloud.skip_if_missing_undercloud
|
||||
undercloud_keystone_client = undercloud.undercloud_keystone_client
|
||||
undercloud_keystone_credentials = undercloud.undercloud_keystone_credentials
|
||||
undercloud_keystone_session = undercloud.undercloud_keystone_session
|
||||
undercloud_ssh_client = undercloud.undercloud_ssh_client
|
||||
|
@ -16,6 +16,7 @@ from __future__ import absolute_import
|
||||
import io
|
||||
import os
|
||||
|
||||
from oslo_log import log
|
||||
import pandas
|
||||
import six
|
||||
|
||||
@ -25,19 +26,20 @@ from tobiko.openstack import keystone
|
||||
from tobiko.openstack import nova
|
||||
from tobiko.shell import sh
|
||||
from tobiko.shell import ssh
|
||||
from tobiko.tripleo import undercloud
|
||||
from tobiko.tripleo import _undercloud
|
||||
|
||||
|
||||
CONF = config.CONF
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
|
||||
def has_overcloud():
|
||||
# rewrite this function
|
||||
return undercloud.has_undercloud()
|
||||
return _undercloud.has_undercloud()
|
||||
|
||||
|
||||
def load_overcloud_rcfile():
|
||||
return undercloud.fetch_os_env(rcfile=CONF.tobiko.tripleo.overcloud_rcfile)
|
||||
return _undercloud.fetch_os_env(*CONF.tobiko.tripleo.overcloud_rcfile)
|
||||
|
||||
|
||||
skip_if_missing_overcloud = tobiko.skip_unless(
|
||||
@ -55,13 +57,13 @@ class OvercloudKeystoneCredentialsFixture(
|
||||
|
||||
|
||||
def list_overcloud_nodes(**params):
|
||||
session = undercloud.undercloud_keystone_session()
|
||||
session = _undercloud.undercloud_keystone_session()
|
||||
client = nova.get_nova_client(session=session)
|
||||
return nova.list_servers(client=client, **params)
|
||||
|
||||
|
||||
def find_overcloud_node(**params):
|
||||
session = undercloud.undercloud_keystone_session()
|
||||
session = _undercloud.undercloud_keystone_session()
|
||||
client = nova.get_nova_client(session=session)
|
||||
return nova.find_server(client=client, **params)
|
||||
|
||||
@ -107,7 +109,7 @@ class OvercloudSshKeyFileFixture(tobiko.SharedFixture):
|
||||
key_dirname = os.path.dirname(key_filename)
|
||||
tobiko.makedirs(key_dirname, mode=0o700)
|
||||
|
||||
ssh_client = undercloud.undercloud_ssh_client()
|
||||
ssh_client = _undercloud.undercloud_ssh_client()
|
||||
_get_undercloud_file(ssh_client=ssh_client,
|
||||
source='~/.ssh/id_rsa',
|
||||
destination=key_filename,
|
@ -35,18 +35,36 @@ 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
|
||||
class InvalidRCFile(tobiko.TobikoException):
|
||||
message = "Invalid RC file: {rcfile}"
|
||||
|
||||
|
||||
def fetch_os_env(rcfile, *rcfiles):
|
||||
rcfiles = (rcfile,) + rcfiles
|
||||
errors = []
|
||||
for rcfile in rcfiles:
|
||||
try:
|
||||
result = sh.execute(f". {rcfile}; env | grep '^OS_'",
|
||||
ssh_client=undercloud_ssh_client())
|
||||
except sh.ShellCommandFailed as ex:
|
||||
LOG.debug(f"Unable to get overcloud RC file '{rcfile}' content "
|
||||
f"({ex})")
|
||||
errors.append(tobiko.exc_info)
|
||||
else:
|
||||
env = {}
|
||||
for line in result.stdout.splitlines():
|
||||
name, value = line.split('=')
|
||||
env[name] = value
|
||||
if env:
|
||||
return env
|
||||
for error in errors:
|
||||
LOG.exception(f"Unable to get overcloud RC file '{rcfile}' "
|
||||
"content", exc_info=error)
|
||||
raise InvalidRCFile(rcfile=", ".join(rcfiles))
|
||||
|
||||
|
||||
def load_undercloud_rcfile():
|
||||
return fetch_os_env(rcfile=CONF.tobiko.tripleo.undercloud_rcfile)
|
||||
return fetch_os_env(*CONF.tobiko.tripleo.undercloud_rcfile)
|
||||
|
||||
|
||||
class UndercloudKeystoneCredentialsFixture(
|
||||
|
@ -33,9 +33,9 @@ OPTIONS = [
|
||||
cfg.StrOpt('undercloud_ssh_key_filename',
|
||||
default='~/.ssh/id_rsa',
|
||||
help="SSH key filename used to login to Undercloud node"),
|
||||
cfg.StrOpt('undercloud_rcfile',
|
||||
default='~/stackrc',
|
||||
help="Undercloud RC filename"),
|
||||
cfg.ListOpt('undercloud_rcfile',
|
||||
default=['~/stackrc'],
|
||||
help="Undercloud RC filename"),
|
||||
|
||||
# Overcloud options
|
||||
cfg.IntOpt('overcloud_ssh_port',
|
||||
@ -47,9 +47,9 @@ OPTIONS = [
|
||||
cfg.StrOpt('overcloud_ssh_key_filename',
|
||||
default='~/.ssh/id_overcloud',
|
||||
help="SSH key filename used to login to Overcloud nodes"),
|
||||
cfg.StrOpt('overcloud_rcfile',
|
||||
default='~/overcloudrc',
|
||||
help="Overcloud RC filename"),
|
||||
cfg.ListOpt('overcloud_rcfile',
|
||||
default=['~/overcloudrc', '~/qe-Cloud-0rc'],
|
||||
help="Overcloud RC filenames"),
|
||||
cfg.IntOpt('overcloud_ip_version',
|
||||
help=("Default IP address version to be used to connect to "
|
||||
"overcloud nodes ")),
|
||||
|
Loading…
Reference in New Issue
Block a user