Take out overcloud stuff from undercloud module

Change-Id: I8d68309e05d3573b54d40493fed7dcb9685dc019
This commit is contained in:
Federico Ressi
2019-08-22 15:12:37 +02:00
parent 6f95a7f4c1
commit 8796e07bfe
5 changed files with 93 additions and 21 deletions

View File

@@ -0,0 +1,36 @@
# Copyright 2019 Red Hat
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from __future__ import absolute_import
import testtools
from tobiko import config
from tobiko.tripleo import overcloud
CONF = config.CONF
@overcloud.skip_if_missing_overcloud
class OvercloudSshConnectionTest(testtools.TestCase):
def test_fetch_overcloud_credentials(self):
env = overcloud.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'])
self.assertTrue(env.get('OS_TENANT_NAME') or
env.get('OS_PROJECT_NAME') or
env.get('OS_TENANT_ID') or
env.get('OS_PROJECT_ID'))

View File

@@ -34,14 +34,6 @@ class UndercloudSshConnectionTest(testtools.TestCase):
def test_fetch_undercloud_credentials(self):
env = undercloud.load_undercloud_rcfile()
self._test_fetch_credentials(env=env)
def test_fetch_overcloud_credentials(self):
env = undercloud.load_overcloud_rcfile()
self._test_fetch_credentials(env=env)
def _test_fetch_credentials(self, env):
self.assertTrue(env['OS_AUTH_URL'])
self.assertTrue(env.get('OS_USERNAME') or env.get('OS_USER_ID'))
self.assertTrue(env['OS_PASSWORD'])

View File

@@ -51,7 +51,7 @@ def list_options():
def setup_tobiko_config(conf):
# pylint: disable=unused-argument
from tobiko.openstack import keystone
from tobiko.tripleo import undercloud
if undercloud.has_undercloud():
from tobiko.tripleo import overcloud
if overcloud.has_overcloud():
keystone.DEFAULT_KEYSTONE_CREDENTIALS_FIXTURES.append(
undercloud.OvercloudKeystoneCredentialsFixture)
overcloud.OvercloudKeystoneCredentialsFixture)

View File

@@ -0,0 +1,41 @@
# Copyright 2019 Red Hat
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from __future__ import absolute_import
import tobiko
from tobiko import config
from tobiko.openstack import keystone
from tobiko.tripleo import undercloud
CONF = config.CONF
def has_overcloud():
# rewrite this function
return undercloud.has_undercloud()
def load_overcloud_rcfile():
return undercloud.fetch_os_env(rcfile=CONF.tobiko.tripleo.overcloud_rcfile)
skip_if_missing_overcloud = tobiko.skip_unless(
'TripleO overcloud not configured', has_overcloud)
class OvercloudKeystoneCredentialsFixture(
keystone.EnvironKeystoneCredentialsFixture):
def get_environ(self):
return load_overcloud_rcfile()

View File

@@ -1,3 +1,16 @@
# Copyright 2019 Red Hat
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from __future__ import absolute_import
import tobiko
@@ -32,22 +45,12 @@ 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)
class UndercloudKeystoneCredentialsFixture(
keystone.EnvironKeystoneCredentialsFixture):
def get_environ(self):
return load_undercloud_rcfile()
class OvercloudKeystoneCredentialsFixture(
keystone.EnvironKeystoneCredentialsFixture):
def get_environ(self):
return load_overcloud_rcfile()
def has_undercloud():
host_config = undercloud_host_config()
return bool(host_config.hostname)