inspect.getargspec is deprecated in py3

Change-Id: I1bc61174fcce278689ed426a1a8382541bc3bd59
This commit is contained in:
Eyal 2019-04-14 17:17:37 +03:00
parent 6aa6fd0626
commit 809f2fb553
4 changed files with 30 additions and 7 deletions

View File

@ -21,7 +21,6 @@
import ast
import datetime
import functools
import inspect
from oslo_utils import strutils
from oslo_utils import timeutils
@ -31,6 +30,7 @@ import wsme
from wsme import types as wtypes
from aodh.i18n import _
from aodh.utils import get_func_valid_keys
operation_kind = ('lt', 'le', 'eq', 'ne', 'ge', 'gt')
@ -87,7 +87,7 @@ class Base(wtypes.DynamicBase):
return cls(links=links, **(m.as_dict()))
def as_dict(self, db_model):
valid_keys = inspect.getargspec(db_model.__init__)[0]
valid_keys = get_func_valid_keys(db_model.__init__)
if 'self' in valid_keys:
valid_keys.remove('self')
return self.as_dict_from_keys(valid_keys)

View File

@ -20,7 +20,6 @@
import copy
import datetime
import inspect
from oslo_utils import timeutils
import pecan
@ -30,6 +29,7 @@ import wsme
from aodh.api.controllers.v2 import base
from aodh.api import rbac
from aodh.utils import get_func_valid_keys
def get_auth_project(on_behalf_of=None):
@ -64,7 +64,7 @@ def sanitize_query(query, db_func, on_behalf_of=None):
_verify_query_segregation(q, auth_project)
proj_q = [i for i in q if i.field == 'project_id']
valid_keys = inspect.getargspec(db_func)[0]
valid_keys = get_func_valid_keys(db_func)
if not proj_q and 'on_behalf_of' not in valid_keys:
# The user is restricted, but they didn't specify a project
# so add it for them.
@ -113,7 +113,7 @@ def validate_query(query, db_func, internal_keys=None,
internal_keys = internal_keys or []
_verify_query_segregation(query)
valid_keys = inspect.getargspec(db_func)[0]
valid_keys = get_func_valid_keys(db_func)
if 'alarm_type' in valid_keys:
valid_keys.remove('alarm_type')
valid_keys.append('type')

View File

@ -15,11 +15,11 @@
"""Base classes for storage engines
"""
import copy
import inspect
import six
import aodh
from aodh.utils import get_func_valid_keys
def update_nested(original_dict, updates):
@ -64,7 +64,7 @@ class Model(object):
@classmethod
def get_field_names(cls):
fields = inspect.getargspec(cls.__init__)[0]
fields = get_func_valid_keys(cls.__init__)
return set(fields) - set(["self"])

23
aodh/utils.py Normal file
View File

@ -0,0 +1,23 @@
# Copyright 2019 - Nokia Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import inspect
import six
def get_func_valid_keys(func):
if six.PY2:
return inspect.getargspec(func)[0]
else:
return inspect.getfullargspec(func)[0]