Use Tempest config for user sessions
Story: #2004053 Task: #28634 Change-Id: Id37850f37505444d099c46488e1e31a7907b4f7b
This commit is contained in:
parent
a3771ed121
commit
64e915e476
|
@ -80,9 +80,7 @@ class TestTopology(BaseTopologyTest):
|
|||
either admin or None, this test is expected to be identical to the one
|
||||
with --all-tenants
|
||||
"""
|
||||
num_admin_networks = \
|
||||
self._calc_num_tenant_networks(self.ADMIN_USERNAME,
|
||||
self.ADMIN_PROJECT_NAME)
|
||||
num_admin_networks = self._calc_num_admin_tenant_networks()
|
||||
|
||||
self._do_test_default_graph(num_default_networks=num_admin_networks,
|
||||
all_tenants=False)
|
||||
|
@ -111,7 +109,7 @@ class TestTopology(BaseTopologyTest):
|
|||
zone_edges=0, host_entities=0, host_edges=0,
|
||||
instance_entities=0, instance_edges=0, volume_entities=0,
|
||||
volume_edges=0)
|
||||
num_entities = self.num_demo_tenant_networks
|
||||
num_entities = self._calc_num_tenant_networks()
|
||||
|
||||
# Test Assertions
|
||||
self._validate_graph_correctness(graph, num_entities, 0, entities)
|
||||
|
|
|
@ -19,7 +19,8 @@ import six
|
|||
from networkx.readwrite import json_graph
|
||||
from oslo_log import log as logging
|
||||
from oslo_utils import timeutils
|
||||
from oslotest import base
|
||||
from tempest.common import credentials_factory as common_creds
|
||||
from tempest import test
|
||||
from testtools.matchers import HasLength
|
||||
from testtools.matchers import Not
|
||||
|
||||
|
@ -61,17 +62,15 @@ if six.PY2:
|
|||
pass
|
||||
|
||||
|
||||
class BaseVitrageTempest(base.BaseTestCase):
|
||||
class BaseVitrageTempest(test.BaseTestCase):
|
||||
"""Base test class for All Vitrage tests."""
|
||||
|
||||
credentials = ['primary']
|
||||
|
||||
NUM_VERTICES_PER_TYPE = 'num_vertices'
|
||||
NUM_EDGES_PER_TYPE = 'num_edges_per_type'
|
||||
USER_DOMAIN_ID = 'default'
|
||||
PROJECT_DOMAIN_ID = 'default'
|
||||
DEMO_USERNAME = 'demo'
|
||||
# TODO(e0ne): use credentials from the config
|
||||
DEMO_PROJECT_NAME = 'demo'
|
||||
ADMIN_USERNAME = 'admin'
|
||||
ADMIN_PROJECT_NAME = 'admin'
|
||||
|
||||
def assert_list_equal(self, l1, l2, message=None):
|
||||
self.assertListEqual(l1, l2, message)
|
||||
|
@ -133,19 +132,17 @@ class BaseVitrageTempest(base.BaseTestCase):
|
|||
message="unclosed",
|
||||
category=ResourceWarning)
|
||||
cls.conf = service.prepare_service([])
|
||||
TempestClients.class_init(cls.conf)
|
||||
TempestClients.class_init(cls.conf, cls.os_primary.credentials)
|
||||
cls.vitrage_client = TempestClients.vitrage()
|
||||
cls.vitrage_client_for_demo_user = \
|
||||
TempestClients.vitrage_client_for_user(
|
||||
cls.DEMO_USERNAME, cls.USER_DOMAIN_ID,
|
||||
cls.DEMO_PROJECT_NAME, cls.PROJECT_DOMAIN_ID)
|
||||
TempestClients.vitrage_client_for_user()
|
||||
|
||||
cls.num_default_networks = \
|
||||
len(TempestClients.neutron().list_networks()['networks'])
|
||||
cls.num_default_ports = cls._get_num_default_ports()
|
||||
cls.num_default_entities = 3
|
||||
cls.num_default_edges = 2
|
||||
cls.num_demo_tenant_networks = cls._calc_num_demo_tenant_networks()
|
||||
cls.num_demo_tenant_networks = cls._calc_num_tenant_networks()
|
||||
|
||||
@classmethod
|
||||
def _get_num_default_ports(cls):
|
||||
|
@ -356,17 +353,18 @@ class BaseVitrageTempest(base.BaseTestCase):
|
|||
self._print_entity_graph()
|
||||
|
||||
@classmethod
|
||||
def _calc_num_demo_tenant_networks(cls):
|
||||
return cls._calc_num_tenant_networks(
|
||||
cls.DEMO_USERNAME, cls.DEMO_PROJECT_NAME)
|
||||
def _calc_num_admin_tenant_networks(cls):
|
||||
neutron_client = TempestClients.neutron()
|
||||
admin_creds = common_creds.get_configured_admin_credentials()
|
||||
tenant_networks = neutron_client.list_networks(
|
||||
tenant_id=admin_creds.project_id)['networks']
|
||||
return len(tenant_networks)
|
||||
|
||||
@classmethod
|
||||
def _calc_num_tenant_networks(cls, username, project_name):
|
||||
neutron_client = TempestClients.neutron_client_for_user(
|
||||
username, cls.USER_DOMAIN_ID,
|
||||
project_name, cls.PROJECT_DOMAIN_ID)
|
||||
def _calc_num_tenant_networks(cls):
|
||||
neutron_client = TempestClients.neutron_client_for_user()
|
||||
tenant_networks = neutron_client.list_networks(
|
||||
tenant_id=cls._get_demo_tenant_id())['networks']
|
||||
tenant_id=cls.os_primary.credentials.project_id)['networks']
|
||||
return len(tenant_networks)
|
||||
|
||||
@classmethod
|
||||
|
|
|
@ -15,16 +15,19 @@
|
|||
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 import config
|
||||
from vitrage import keystone_client
|
||||
from vitrage import os_clients
|
||||
from vitrage_tempest_plugin.tests.utils import get_property_value
|
||||
from vitrageclient import client as vc
|
||||
|
||||
CONF = config.CONF
|
||||
|
||||
|
||||
class TempestClients(object):
|
||||
@classmethod
|
||||
def class_init(cls, conf):
|
||||
def class_init(cls, conf, creds=None):
|
||||
cls._conf = conf
|
||||
cls.creds = creds
|
||||
cls._vitrage = None
|
||||
cls._ceilometer = None
|
||||
cls._nova = None
|
||||
|
@ -49,21 +52,17 @@ class TempestClients(object):
|
|||
return cls._vitrage
|
||||
|
||||
@classmethod
|
||||
def vitrage_client_for_user(cls, username, user_domain_id,
|
||||
project_name, project_domain_id):
|
||||
def vitrage_client_for_user(cls):
|
||||
"""vitrage client for a specific user and tenant
|
||||
|
||||
:rtype: vitrageclient.v1.client.Client
|
||||
"""
|
||||
session = cls._get_session_for_user(
|
||||
username, user_domain_id, project_name, project_domain_id)
|
||||
session = cls._get_session_for_user()
|
||||
return vc.Client('1', session=session)
|
||||
|
||||
@classmethod
|
||||
def neutron_client_for_user(cls, username, user_domain_id,
|
||||
project_name, project_domain_id):
|
||||
session = cls._get_session_for_user(
|
||||
username, user_domain_id, project_name, project_domain_id)
|
||||
def neutron_client_for_user(cls):
|
||||
session = cls._get_session_for_user()
|
||||
return neutron_client.Client(session=session)
|
||||
|
||||
@classmethod
|
||||
|
@ -167,13 +166,17 @@ class TempestClients(object):
|
|||
return cls._gnocchi
|
||||
|
||||
@classmethod
|
||||
def _get_session_for_user(cls, username, user_domain_id,
|
||||
project_name, project_domain_id):
|
||||
password = get_property_value(
|
||||
'OS_PASSWORD', 'password', 'password', cls._conf)
|
||||
def _get_session_for_user(cls):
|
||||
password = cls.creds.password
|
||||
username = cls.creds.username
|
||||
user_domain_id = cls.creds.user_domain_id
|
||||
project_name = cls.creds.project_name
|
||||
project_domain_id = cls.creds.project_domain_id
|
||||
|
||||
loader = ka_loading.get_plugin_loader('password')
|
||||
auth_url = CONF.identity.uri_v3
|
||||
auth_plugin = loader.load_from_options(
|
||||
auth_url=cls._conf.service_credentials.auth_url,
|
||||
auth_url=auth_url,
|
||||
username=username, password=password, project_name=project_name,
|
||||
project_domain_id=project_domain_id,
|
||||
user_domain_id=user_domain_id)
|
||||
|
|
Loading…
Reference in New Issue