diff --git a/rally_openstack/verification/tempest/config.py b/rally_openstack/verification/tempest/config.py index 94026fba..f4a03eba 100644 --- a/rally_openstack/verification/tempest/config.py +++ b/rally_openstack/verification/tempest/config.py @@ -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() diff --git a/rally_openstack/verification/tempest/context.py b/rally_openstack/verification/tempest/context.py index c101f9db..87481271 100644 --- a/rally_openstack/verification/tempest/context.py +++ b/rally_openstack/verification/tempest/context.py @@ -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) diff --git a/rally_openstack/verification/tempest/manager.py b/rally_openstack/verification/tempest/manager.py index b8283e13..911d9df1 100644 --- a/rally_openstack/verification/tempest/manager.py +++ b/rally_openstack/verification/tempest/manager.py @@ -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): diff --git a/tests/ci/rally_verify.py b/tests/ci/rally_verify.py index 651abd7c..949a1f77 100644 --- a/tests/ci/rally_verify.py +++ b/tests/ci/rally_verify.py @@ -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]: - self.result["status"] = Status.ERROR - return + # 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], - stdout=sys.stdout) + 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 diff --git a/tests/functional/test_task_samples.py b/tests/functional/test_task_samples.py index 6b6f4503..e12766b1 100644 --- a/tests/functional/test_task_samples.py +++ b/tests/functional/test_task_samples.py @@ -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"]}} diff --git a/tests/unit/fakes.py b/tests/unit/fakes.py index 662256da..5c3f9995 100644 --- a/tests/unit/fakes.py +++ b/tests/unit/fakes.py @@ -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): diff --git a/tests/unit/verification/tempest/test_config.py b/tests/unit/verification/tempest/test_config.py index 64fa732d..a1bc975d 100644 --- a/tests/unit/verification/tempest/test_config.py +++ b/tests/unit/verification/tempest/test_config.py @@ -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") diff --git a/tests/unit/verification/tempest/test_context.py b/tests/unit/verification/tempest/test_context.py index 4aa29ac1..1de4e0b7 100644 --- a/tests/unit/verification/tempest/test_context.py +++ b/tests/unit/verification/tempest/test_context.py @@ -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 diff --git a/tests/unit/verification/tempest/test_manager.py b/tests/unit/verification/tempest/test_manager.py index 009acab7..30fcf52a 100644 --- a/tests/unit/verification/tempest/test_manager.py +++ b/tests/unit/verification/tempest/test_manager.py @@ -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) diff --git a/tox.ini b/tox.ini index 93c7511f..4873616b 100644 --- a/tox.ini +++ b/tox.ini @@ -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*: