From 883d5698cd855a75be370703eb7f331ca7b7b447 Mon Sep 17 00:00:00 2001 From: Ivan Kolodyazhny Date: Mon, 18 Feb 2019 15:59:04 +0200 Subject: [PATCH] Use admin credentials for vitrageclient from tempest.conf Story: #2004053 Task: #28634 Change-Id: I32431783a8d07b54b09da13ce3a00bb191900a68 --- .../tests/api/resources/test_resources.py | 6 +++-- .../tests/common/tempest_clients.py | 23 +++++++++++++++++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/vitrage_tempest_plugin/tests/api/resources/test_resources.py b/vitrage_tempest_plugin/tests/api/resources/test_resources.py index 04ac55e..a0fb976 100644 --- a/vitrage_tempest_plugin/tests/api/resources/test_resources.py +++ b/vitrage_tempest_plugin/tests/api/resources/test_resources.py @@ -75,11 +75,13 @@ class TestResource(BaseVitrageTempest): def test_default_resource_list(self): """resource list with default query - get the resources: network, instance, port + get the resources: network, instance, port, zone, host, cluster """ + # TODO(e0ne): split this test to verify that only network, + # instance and port are returned to non-admin user. try: resources = self.vitrage_client.resource.list(all_tenants=False) - self.assertThat(resources, matchers.HasLength(3)) + self.assertThat(resources, matchers.HasLength(6)) except Exception as e: self._handle_exception(e) raise diff --git a/vitrage_tempest_plugin/tests/common/tempest_clients.py b/vitrage_tempest_plugin/tests/common/tempest_clients.py index a9162b5..4052989 100644 --- a/vitrage_tempest_plugin/tests/common/tempest_clients.py +++ b/vitrage_tempest_plugin/tests/common/tempest_clients.py @@ -15,6 +15,7 @@ from keystoneauth1 import loading as ka_loading from keystoneauth1 import session as ka_session from neutronclient.v2_0 import client as neutron_client +from tempest.common import credentials_factory as common_creds from tempest import config from vitrage import keystone_client from vitrage import os_clients @@ -48,7 +49,7 @@ class TempestClients(object): """ if not cls._vitrage: cls._vitrage = vc.Client( - '1', session=keystone_client.get_session(cls._conf)) + '1', session=cls._get_session_for_admin()) return cls._vitrage @classmethod @@ -165,14 +166,32 @@ class TempestClients(object): cls._gnocchi = os_clients.gnocchi_client(cls._conf) return cls._gnocchi + @classmethod + def _get_session_for_admin(cls): + admin_creds = common_creds.get_configured_admin_credentials() + password = admin_creds.password + username = admin_creds.username + user_domain_id = admin_creds.user_domain_id + project_name = admin_creds.project_name + project_domain_id = admin_creds.project_domain_id + + return cls._get_session(username, password, user_domain_id, + project_name, project_domain_id) + @classmethod def _get_session_for_user(cls): - password = cls.creds.password username = cls.creds.username + password = cls.creds.password user_domain_id = cls.creds.user_domain_id project_name = cls.creds.project_name project_domain_id = cls.creds.project_domain_id + return cls._get_session(username, password, user_domain_id, + project_name, project_domain_id) + + @classmethod + def _get_session(cls, username, password, user_domain_id, project_name, + project_domain_id): loader = ka_loading.get_plugin_loader('password') auth_url = CONF.identity.uri_v3 auth_plugin = loader.load_from_options(