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 import exceptions
from rally.verification import utils from rally.verification import utils
from rally_openstack.common import consts
from rally_openstack.common import credential
CONF = cfg.CONF CONF = cfg.CONF
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@ -31,13 +34,16 @@ LOG = logging.getLogger(__name__)
class TempestConfigfileManager(object): class TempestConfigfileManager(object):
"""Class to create a Tempest config file.""" """Class to create a Tempest config file."""
def __init__(self, deployment): def __init__(self, env):
self.credential = deployment.get_credentials_for("openstack")["admin"] openstack_platform = env.data["platforms"]["openstack"]
self.credential = credential.OpenStackCredential(
permission=consts.EndpointPermission.ADMIN,
**openstack_platform["platform_data"]["admin"])
if not self.credential: if not self.credential:
raise exceptions.ValidationError( raise exceptions.ValidationError(
"Failed to configure 'tempest' for '%s' environment since " f"Failed to configure 'tempest' for '{env} since "
"admin credentials for OpenStack platform is missed there." % "admin credentials for OpenStack platform is missed there."
deployment["name"]
) )
self.clients = self.credential.clients() self.clients = self.credential.clients()
self.available_services = self.clients.services().values() 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 context
from rally.verification import utils 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.services.image import image
from rally_openstack.common.wrappers import network from rally_openstack.common.wrappers import network
from rally_openstack.verification.tempest import config as conf from rally_openstack.verification.tempest import config as conf
@ -42,8 +44,12 @@ class TempestContext(context.VerifierContext):
def __init__(self, ctx): def __init__(self, ctx):
super(TempestContext, self).__init__(ctx) super(TempestContext, self).__init__(ctx)
creds = self.verifier.deployment.get_credentials_for("openstack") openstack_platform = self.verifier.env.data["platforms"]["openstack"]
self.clients = creds["admin"].clients() 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.available_services = self.clients.services().values()
self.conf = configparser.ConfigParser(allow_no_value=True) self.conf = configparser.ConfigParser(allow_no_value=True)

View File

@ -104,7 +104,7 @@ class TempestManager(testr.TestrLauncher):
def configure(self, extra_options=None): def configure(self, extra_options=None):
"""Configure Tempest.""" """Configure Tempest."""
utils.create_dir(self.home_dir) 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) return tcm.create(self.configfile, extra_options)
def is_configured(self): def is_configured(self):

View File

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

View File

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

View File

@ -1904,6 +1904,16 @@ class FakeDeployment(dict):
return {} 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): class FakeTask(dict, object):
def __init__(self, task=None, temporary=False, **kwargs): def __init__(self, task=None, temporary=False, **kwargs):

View File

@ -32,7 +32,6 @@ CRED = {
"tenant_name": "admin", "tenant_name": "admin",
"password": "admin-12345", "password": "admin-12345",
"auth_url": "http://test:5000/v2.0/", "auth_url": "http://test:5000/v2.0/",
"permission": "admin",
"region_name": "test", "region_name": "test",
"https_insecure": False, "https_insecure": False,
"https_cacert": "/path/to/cacert/file", "https_cacert": "/path/to/cacert/file",
@ -48,9 +47,21 @@ class TempestConfigfileManagerTestCase(test.TestCase):
def setUp(self): def setUp(self):
super(TempestConfigfileManagerTestCase, self).setUp() super(TempestConfigfileManagerTestCase, self).setUp()
deployment = fakes.FakeDeployment(uuid="fake_deployment", env = fakes.FakeEnvironment(
admin=fakes.FakeCredential(**CRED)) env_uuid="fake_env",
self.tempest = config.TempestConfigfileManager(deployment) 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): def test__configure_auth(self):
self.tempest.conf.add_section("auth") self.tempest.conf.add_section("auth")

View File

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

View File

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

View File

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