From 4dd2a0dfba906d8b2f76b2999e7770236bb0f2c0 Mon Sep 17 00:00:00 2001 From: Eyal Date: Mon, 13 Nov 2017 15:57:36 +0200 Subject: [PATCH] fix py charm warnings and doc fix trust id although not used fix api doc Change-Id: I7f6b25617be16de4391499c402d2831057390e1c --- doc/source/contributor/vitrage-api.rst | 54 ++++++++++--------- vitrage/hacking/checks.py | 4 +- vitrage/keystone_client.py | 35 ++++++------ vitrage/tests/unit/graph/test_graph.py | 1 - .../tests/api/alarms/test_alarms.py | 2 +- 5 files changed, 47 insertions(+), 49 deletions(-) diff --git a/doc/source/contributor/vitrage-api.rst b/doc/source/contributor/vitrage-api.rst index 4bc13c1b9..e203b11a7 100755 --- a/doc/source/contributor/vitrage-api.rst +++ b/doc/source/contributor/vitrage-api.rst @@ -161,33 +161,35 @@ Query example X-Auth-Token: 2b8882ba2ec44295bf300aecb2caa4f7 { - "query" : - { - "or": - [ - "==": - { - "vitrage_type":"host" - }, - "==": - { - "vitrage_type":"instance" - }, - "==": - { - "vitrage_type":"zone" - }, - "==": - { - "vitrage_type":"node" - } - ] - } - "graph_type" : "tree" - "depth" : 4 - } - + "query" : + { + "or": [ + { + "==": { + "vitrage_type": "host" + } + }, + { + "==": { + "vitrage_type": "instance" + } + }, + { + "==": { + "vitrage_type": "zone" + } + }, + { + "==": { + "vitrage_type": "node" + } + } + ] + }, + "graph_type" : "tree", + "depth" : 4 + } Response Status Code ==================== diff --git a/vitrage/hacking/checks.py b/vitrage/hacking/checks.py index 5925a239c..4fa4104f5 100644 --- a/vitrage/hacking/checks.py +++ b/vitrage/hacking/checks.py @@ -15,7 +15,7 @@ import re -mutable_default_args = re.compile(r"^\s*def .+\((.+=\{\}|.+=\[\])") +mutable_default_args = re.compile(r"^\s*def .+\((.+={\}|.+=\[\])") asse_trueinst_re = re.compile( r"(.)*assertTrue\(isinstance\((\w|\.|\'|\"|\[|\])+, " @@ -35,7 +35,7 @@ _all_log_levels = {'debug', 'error', 'info', 'warning', translated_logs = re.compile( r"(.)*LOG\.(%(level)s)\(\s*_\(" % {'level': '|'.join(_all_log_levels)}) -dict_constructor_with_list_copy_re = re.compile(r".*\bdict\((\[)?(\(|\[)") +dict_constructor_with_list_copy_re = re.compile(r".*\bdict\((\[)?([(\[])") def assert_true_instance(logical_line): diff --git a/vitrage/keystone_client.py b/vitrage/keystone_client.py index 89d459fcc..27da538c3 100644 --- a/vitrage/keystone_client.py +++ b/vitrage/keystone_client.py @@ -18,6 +18,7 @@ import os from keystoneauth1 import exceptions as ka_exception from keystoneauth1 import loading as ka_loading +from keystoneauth1 import session # noinspection PyPackageRequirements from keystoneclient.v3 import client as ks_client_v3 from oslo_config import cfg @@ -28,19 +29,18 @@ LOG = log.getLogger(__name__) CFG_GROUP = "service_credentials" -def get_session(conf, requests_session=None): +def get_session(conf): """Get a vitrage service credentials auth session.""" auth_plugin = ka_loading.load_auth_from_conf_options(conf, CFG_GROUP) - session = ka_loading.load_session_from_conf_options( - conf, CFG_GROUP, auth=auth_plugin, session=requests_session + return ka_loading.load_session_from_conf_options( + conf, CFG_GROUP, auth=auth_plugin ) - return session -def get_client(conf, trust_id=None, requests_session=None): - """Return a client for keystone v3 endpoint, optionally using a trust.""" - session = get_session(conf, requests_session=requests_session) - return ks_client_v3.Client(session=session, trust_id=trust_id) +def get_client(conf): + """Return a client for keystone v3 endpoint.""" + sess = get_session(conf) + return ks_client_v3.Client(session=sess) def get_service_catalog(client): @@ -51,22 +51,19 @@ def get_auth_token(client): return client.session.auth.get_access(client.session).auth_token -def get_client_on_behalf_user(conf, auth_plugin, trust_id=None, - requests_session=None): - """Return a client for keystone v3 endpoint, optionally using a trust.""" - session = ka_loading.load_session_from_conf_options( - conf, CFG_GROUP, auth=auth_plugin, session=requests_session - ) - return ks_client_v3.Client(session=session, trust_id=trust_id) +def get_client_on_behalf_user(auth_plugin): + """Return a client for keystone v3 endpoint.""" + sess = session.Session(auth=auth_plugin) + return ks_client_v3.Client(session=sess) def create_trust_id(conf, trustor_user_id, trustor_project_id, roles, auth_plugin): """Create a new trust using the vitrage service user.""" admin_client = get_client(conf) - trustee_user_id = admin_client.auth_ref.user_id + trustee_user_id = admin_client.session.get_user_id() - client = get_client_on_behalf_user(conf, auth_plugin=auth_plugin) + client = get_client_on_behalf_user(auth_plugin) trust = client.trusts.create(trustor_user=trustor_user_id, trustee_user=trustee_user_id, project=trustor_project_id, @@ -75,9 +72,9 @@ def create_trust_id(conf, trustor_user_id, trustor_project_id, roles, return trust.id -def delete_trust_id(conf, trust_id, auth_plugin): +def delete_trust_id(trust_id, auth_plugin): """Delete a trust previously setup for the vitrage user.""" - client = get_client_on_behalf_user(conf, auth_plugin=auth_plugin) + client = get_client_on_behalf_user(auth_plugin) try: client.trusts.delete(trust_id) except ka_exception.NotFound: diff --git a/vitrage/tests/unit/graph/test_graph.py b/vitrage/tests/unit/graph/test_graph.py index 325132380..00fccc621 100644 --- a/vitrage/tests/unit/graph/test_graph.py +++ b/vitrage/tests/unit/graph/test_graph.py @@ -20,7 +20,6 @@ Tests for `vitrage` graph driver """ from vitrage.common.constants import EdgeProperties as EProps -from vitrage.common.constants import VertexProperties as VProps from vitrage.graph import Direction from vitrage.graph.filter import check_filter from vitrage.graph import utils diff --git a/vitrage_tempest_tests/tests/api/alarms/test_alarms.py b/vitrage_tempest_tests/tests/api/alarms/test_alarms.py index 33330c7bc..de9fa0ac4 100644 --- a/vitrage_tempest_tests/tests/api/alarms/test_alarms.py +++ b/vitrage_tempest_tests/tests/api/alarms/test_alarms.py @@ -55,7 +55,7 @@ class TestAlarms(BaseAlarmsTest): self._handle_exception(e) raise finally: - aodh_utils.delete_all_ceilometer_alarms() + aodh_utils.delete_all_aodh_alarms() nova_utils.delete_all_instances() def _compare_alarms_lists(self, api_alarms, cli_alarms,