Remove usage of get_credentials_for method

Deployment object comes from Rally framework and it has special
`get_credentials_for` method. For backward compatibility, it transforms
raw dict credentials to OpenStackCredential object.
This compatibility level should be removed someday and this day has come
since we moved rally_openstack.credential module to
rally_openstack.common.credential place and `get_credentials_for`
produces warning now.

Change-Id: I84f3c366ce23b6e67089d7ce053ca0f88d795b01
This commit is contained in:
Andrey Kurilin 2020-04-22 00:04:26 +03:00
parent f13406795a
commit 8de6f3d230
10 changed files with 84 additions and 36 deletions

View File

@ -23,6 +23,9 @@ from rally.common import logging
from rally import exceptions
from rally.verification import utils
from rally_openstack.common import consts
from rally_openstack.common import credential
CONF = cfg.CONF
LOG = logging.getLogger(__name__)
@ -31,13 +34,16 @@ LOG = logging.getLogger(__name__)
class TempestConfigfileManager(object):
"""Class to create a Tempest config file."""
def __init__(self, deployment):
self.credential = deployment.get_credentials_for("openstack")["admin"]
def __init__(self, env):
openstack_platform = env.data["platforms"]["openstack"]
self.credential = credential.OpenStackCredential(
permission=consts.EndpointPermission.ADMIN,
**openstack_platform["platform_data"]["admin"])
if not self.credential:
raise exceptions.ValidationError(
"Failed to configure 'tempest' for '%s' environment since "
"admin credentials for OpenStack platform is missed there." %
deployment["name"]
f"Failed to configure 'tempest' for '{env} since "
"admin credentials for OpenStack platform is missed there."
)
self.clients = self.credential.clients()
self.available_services = self.clients.services().values()

View File

@ -25,6 +25,8 @@ from rally.task import utils as task_utils
from rally.verification import context
from rally.verification import utils
from rally_openstack.common import consts
from rally_openstack.common import credential
from rally_openstack.common.services.image import image
from rally_openstack.common.wrappers import network
from rally_openstack.verification.tempest import config as conf
@ -42,8 +44,12 @@ class TempestContext(context.VerifierContext):
def __init__(self, ctx):
super(TempestContext, self).__init__(ctx)
creds = self.verifier.deployment.get_credentials_for("openstack")
self.clients = creds["admin"].clients()
openstack_platform = self.verifier.env.data["platforms"]["openstack"]
admin_creds = credential.OpenStackCredential(
permission=consts.EndpointPermission.ADMIN,
**openstack_platform["platform_data"]["admin"])
self.clients = admin_creds.clients()
self.available_services = self.clients.services().values()
self.conf = configparser.ConfigParser(allow_no_value=True)

View File

@ -104,7 +104,7 @@ class TempestManager(testr.TestrLauncher):
def configure(self, extra_options=None):
"""Configure Tempest."""
utils.create_dir(self.home_dir)
tcm = config.TempestConfigfileManager(self.verifier.deployment)
tcm = config.TempestConfigfileManager(self.verifier.env)
return tcm.create(self.configfile, extra_options)
def is_configured(self):

View File

@ -26,6 +26,10 @@ import uuid
import jinja2
from rally import api
from rally.env import env_mgr
from rally_openstack.common import consts
from rally_openstack.common import credential
LOG = logging.getLogger("verify-job")
LOG.setLevel(logging.DEBUG)
@ -148,31 +152,32 @@ class Step(object):
class SetUpStep(Step):
"""Validate deployment, create required resources and directories."""
DEPLOYMENT_NAME = "tempest"
ENV_NAME = "tempest"
def run(self):
if not os.path.exists("%s/extra" % self.BASE_DIR):
os.makedirs("%s/extra" % self.BASE_DIR)
# ensure that deployment exit
deployment = self.rapi.deployment._get(self.DEPLOYMENT_NAME)
# check it
result = self.rapi.deployment.check(
deployment=self.DEPLOYMENT_NAME)["openstack"]
if "admin_error" in result[0] or "user_error" in result[0]:
# ensure that environment exit and check it
env = env_mgr.EnvManager.get(self.ENV_NAME)
for p_name, status in env.check_health().items():
if not status["available"]:
self.result["status"] = Status.ERROR
return
try:
subprocess.check_call(["rally", "deployment", "use",
"--deployment", self.DEPLOYMENT_NAME],
subprocess.check_call(
["rally", "env", "use", "--env", self.ENV_NAME],
stdout=sys.stdout)
except subprocess.CalledProcessError:
self.result["status"] = Status.ERROR
return
credentials = deployment.get_credentials_for("openstack")["admin"]
clients = credentials.clients()
openstack_platform = env.data["platforms"]["openstack"]
admin_creds = credential.OpenStackCredential(
permission=consts.EndpointPermission.ADMIN,
**openstack_platform["platform_data"]["admin"])
clients = admin_creds.clients()
if self.args.ctx_create_resources:
# If the 'ctx-create-resources' arg is provided, delete images and
@ -455,7 +460,7 @@ class DestroyDeployment(Step):
"""Delete the deployment, and verifications of this deployment."""
COMMAND = "deployment destroy --deployment %(id)s"
CALL_ARGS = {"id": SetUpStep.DEPLOYMENT_NAME}
CALL_ARGS = {"id": SetUpStep.ENV_NAME}
DEPENDS_ON = SetUpStep

View File

@ -25,7 +25,10 @@ from rally import api
from rally.cli import yamlutils as yaml
from rally.common import broker
from rally import plugins
import rally_openstack as rally_openstack_module
from rally_openstack.common import consts
from rally_openstack.common import credential
from tests.functional import utils
@ -57,13 +60,17 @@ class TestTaskSamples(unittest.TestCase):
# let's use pre-created users to make TestTaskSamples quicker
rapi = api.API(config_file=rally.config_filename)
deployment = rapi.deployment._get("MAIN")
admin_cred = deployment.get_credentials_for("openstack")["admin"]
openstack_platform = deployment.env_obj.data["platforms"]["openstack"]
admin_creds = credential.OpenStackCredential(
permission=consts.EndpointPermission.ADMIN,
**openstack_platform["platform_data"]["admin"])
ctx = {
"env": {
"platforms": {
"openstack": {
"admin": admin_cred.to_dict(),
"admin": admin_creds.to_dict(),
"users": []}}},
"task": {"uuid": self.__class__.__name__,
"deployment_uuid": deployment["uuid"]}}

View File

@ -1904,6 +1904,16 @@ class FakeDeployment(dict):
return {}
class FakeEnvironment(object):
def __init__(self, env_uuid, data):
self.uuid = env_uuid
self.data = data
@property
def cached_data(self):
return self.data
class FakeTask(dict, object):
def __init__(self, task=None, temporary=False, **kwargs):

View File

@ -32,7 +32,6 @@ CRED = {
"tenant_name": "admin",
"password": "admin-12345",
"auth_url": "http://test:5000/v2.0/",
"permission": "admin",
"region_name": "test",
"https_insecure": False,
"https_cacert": "/path/to/cacert/file",
@ -48,9 +47,21 @@ class TempestConfigfileManagerTestCase(test.TestCase):
def setUp(self):
super(TempestConfigfileManagerTestCase, self).setUp()
deployment = fakes.FakeDeployment(uuid="fake_deployment",
admin=fakes.FakeCredential(**CRED))
self.tempest = config.TempestConfigfileManager(deployment)
env = fakes.FakeEnvironment(
env_uuid="fake_env",
data={
"platforms": {
"openstack": {
"platform_data": {
"admin": CRED
}
}
}
}
)
with mock.patch("%s.credential.OpenStackCredential" % PATH,
return_value=fakes.FakeCredential(**CRED)):
self.tempest = config.TempestConfigfileManager(env)
def test__configure_auth(self):
self.tempest.conf.add_section("auth")

View File

@ -57,9 +57,14 @@ class TempestContextTestCase(test.TestCase):
return_value=True).start()
self.cred = fakes.FakeCredential(**CRED)
self.deployment = fakes.FakeDeployment(
uuid="fake_deployment", admin=self.cred)
cfg = {"verifier": mock.Mock(deployment=self.deployment),
p_cred = mock.patch(PATH + ".credential.OpenStackCredential",
return_value=self.cred)
p_cred.start()
self.addCleanup(p_cred.stop)
self.env = mock.Mock(data={"platforms": {"openstack": {
"platform_data": {"admin": {}}}}}
)
cfg = {"verifier": mock.Mock(env=self.env),
"verification": {"uuid": "uuid"}}
cfg["verifier"].manager.home_dir = "/p/a/t/h"
cfg["verifier"].manager.configfile = "/fake/path/to/config"
@ -362,7 +367,7 @@ class TempestContextTestCase(test.TestCase):
def test_setup(self, mock_create_dir,
mock__create_tempest_roles, mock__configure_option,
mock_open):
verifier = mock.Mock(deployment=self.deployment)
verifier = mock.Mock(env=self.env)
verifier.manager.home_dir = "/p/a/t/h"
# case #1: no neutron and heat

View File

@ -61,7 +61,7 @@ class TempestManagerTestCase(test.TestCase):
self.assertEqual(cm.create.return_value,
tempest.configure(extra_options))
mock_tempest_configfile_manager.assert_called_once_with(
tempest.verifier.deployment)
tempest.verifier.env)
cm.create.assert_called_once_with(tempest.configfile, extra_options)
@mock.patch("%s.config.os.path.exists" % PATH)

View File

@ -123,7 +123,5 @@ filterwarnings =
ignore:::.*netaddr.strategy.*
ignore:Using or importing the ABCs:DeprecationWarning:.*oslo_context.*
ignore:the imp module is deprecated in favour of importlib.*:DeprecationWarning
# should be fixed soon (raised by functional job)
ignore:Module rally_openstack.credential is deprecated.*:
# should be fixed at rally framework (raised by functional job)
ignore:.*EngineFacade is deprecated; please use oslo_db.sqlalchemy.enginefacade*: