Remove useless glance api_servers define

According to nova's advice, api_servers is useless and
We should get rid of it[1].

[1]. https://review.opendev.org/#/c/682565/ PatchSet 16.

Co-Authored-By: zhurong <aaronzhu1121@gmail.com>
Change-Id: I84cb846561fba941b2b2cdff422a94928f9bfda1
This commit is contained in:
chenke 2019-09-29 09:54:50 +08:00
parent a835765471
commit 9fb411e860
6 changed files with 86 additions and 56 deletions

View File

@ -14,11 +14,12 @@
# under the License.
from oslo_config import cfg
from oslo_context import context
from oslo_serialization import jsonutils
from pecan import hooks
from cyborg.common import policy
from cyborg.common import exception
from cyborg.conductor import rpcapi
from cyborg import context
class ConfigHook(hooks.PecanHook):
@ -76,19 +77,25 @@ class ContextHook(hooks.PecanHook):
super(ContextHook, self).__init__()
def before(self, state):
headers = state.request.headers
req = state.request
creds = {
'user_name': headers.get('X-User-Name'),
'user': headers.get('X-User-Id'),
'project_name': headers.get('X-Project-Name'),
'tenant': headers.get('X-Project-Id'),
'domain': headers.get('X-User-Domain-Id'),
'domain_name': headers.get('X-User-Domain-Name'),
'auth_token': headers.get('X-Auth-Token'),
'roles': headers.get('X-Roles', '').split(','),
}
service_catalog = None
if req.headers.get('X_SERVICE_CATALOG') is not None:
try:
catalog_header = req.headers.get('X_SERVICE_CATALOG')
service_catalog = jsonutils.loads(catalog_header)
except ValueError:
raise exception.InvalidJsonType('service catalog')
is_admin = policy.authorize('is_admin', creds, creds)
state.request.context = context.RequestContext(
is_admin=is_admin, **creds)
# NOTE(jamielennox): This is a full auth plugin set by auth_token
# middleware in newer versions.
user_auth_plugin = req.environ.get('keystone.token_auth')
roles = req.headers.get('X-Roles', '').split(',')
is_admin = ('admin' in roles or 'administrator' in roles)
state.request.context = context.RequestContext.from_environ(
req.environ,
user_auth_plugin=user_auth_plugin,
is_admin=is_admin,
service_catalog=service_catalog)

View File

@ -469,3 +469,7 @@ class FactoryMixin(object):
return cls
LOG.info("Use default %s, do not find concrete class"
"by %s.", cls.__name__, typ)
def strtime(at):
return at.strftime("%Y-%m-%dT%H:%M:%S.%f")

View File

@ -26,23 +26,6 @@ glance_group = cfg.OptGroup(
help='Configuration options for the Image service')
glance_opts = [
# NOTE(sdague/efried): there is intentionally no default here. This
# requires configuration if ksa adapter config is not used.
cfg.ListOpt('api_servers',
help="""
List of glance api servers endpoints available to cyborg.
https is used for ssl-based glance api servers.
NOTE: The preferred mechanism for endpoint discovery is via keystoneauth1
loading options. Only use api_servers if you need multiple endpoints and are
unable to use a load balancer for some reason.
Possible values:
* A list of any fully qualified url of the form "scheme://hostname:port[/path]"
(i.e. "http://10.0.1.0:9292" or "https://my.glance.server/image").
"""),
cfg.IntOpt('num_retries',
default=0,
min=0,

View File

@ -23,6 +23,7 @@ from oslo_utils import timeutils
import six
from cyborg.common import exception
from cyborg.common import utils
class _ContextAuthPlugin(plugin.BaseAuthPlugin):
@ -108,6 +109,50 @@ class RequestContext(context.RequestContext):
else:
return _ContextAuthPlugin(self.auth_token, self.service_catalog)
def to_dict(self):
values = super(RequestContext, self).to_dict()
# FIXME(dims): defensive hasattr() checks need to be
# removed once we figure out why we are seeing stack
# traces
values.update({
'user_id': getattr(self, 'user_id', None),
'project_id': getattr(self, 'project_id', None),
'is_admin': getattr(self, 'is_admin', None),
'read_deleted': getattr(self, 'read_deleted', 'no'),
'remote_address': getattr(self, 'remote_address', None),
'timestamp': utils.strtime(self.timestamp) if hasattr(
self, 'timestamp') else None,
'request_id': getattr(self, 'request_id', None),
'quota_class': getattr(self, 'quota_class', None),
'user_name': getattr(self, 'user_name', None),
'service_catalog': getattr(self, 'service_catalog', None),
'project_name': getattr(self, 'project_name', None),
})
# NOTE(tonyb): This can be removed once we're certain to have a
# RequestContext contains 'is_admin_project', We can only get away with
# this because we "know" the default value of 'is_admin_project' which
# is very fragile.
values.update({
'is_admin_project': getattr(self, 'is_admin_project', True),
})
return values
@classmethod
def from_dict(cls, values):
return super(RequestContext, cls).from_dict(
values,
user_id=values.get('user_id'),
project_id=values.get('project_id'),
# TODO(sdague): oslo.context has show_deleted, if
# possible, we should migrate to that in the future so we
# don't need to be different here.
read_deleted=values.get('read_deleted', 'no'),
remote_address=values.get('remote_address'),
timestamp=values.get('timestamp'),
quota_class=values.get('quota_class'),
service_catalog=values.get('service_catalog'),
)
def get_context():
"""A helper method to get a blank context.

View File

@ -21,7 +21,6 @@ import copy
import inspect
import itertools
import os
import random
import re
import stat
import sys
@ -107,29 +106,22 @@ def generate_identity_headers(context, status='Confirmed'):
def get_api_servers(context):
"""Shuffle a list of service endpoints and return an iterator that will
"""Get a list of service endpoints and return an iterator that will
cycle through the list, looping around to the beginning if necessary.
"""
# NOTE(efried): utils.get_ksa_adapter().get_endpoint() is the preferred
# mechanism for endpoint discovery. Only use `api_servers` if you really
# need to shuffle multiple endpoints.
if CONF.glance.api_servers:
api_servers = CONF.glance.api_servers
random.shuffle(api_servers)
else:
sess, auth = _session_and_auth(context)
ksa_adap = utils.get_ksa_adapter(
cyborg.conf.glance.DEFAULT_SERVICE_TYPE,
ksa_auth=auth, ksa_session=sess,
min_version='2.0', max_version='2.latest')
endpoint = utils.get_endpoint(ksa_adap)
if endpoint:
# NOTE(mriedem): Due to python-glanceclient bug 1707995 we have
# to massage the endpoint URL otherwise it won't work properly.
# We can't use glanceclient.common.utils.strip_version because
# of bug 1748009.
endpoint = re.sub(r'/v\d+(\.\d+)?/?$', '/', endpoint)
api_servers = [endpoint]
sess, auth = _session_and_auth(context)
ksa_adap = utils.get_ksa_adapter(
cyborg.conf.glance.DEFAULT_SERVICE_TYPE,
ksa_auth=auth, ksa_session=sess,
min_version='2.0', max_version='2.latest')
endpoint = utils.get_endpoint(ksa_adap)
if endpoint:
# NOTE(mriedem): Due to python-glanceclient bug 1707995 we have
# to massage the endpoint URL otherwise it won't work properly.
# We can't use glanceclient.common.utils.strip_version because
# of bug 1748009.
endpoint = re.sub(r'/v\d+(\.\d+)?/?$', '/', endpoint)
api_servers = [endpoint]
return itertools.cycle(api_servers)

View File

@ -230,7 +230,6 @@ function configure_cyborg_glance {
iniset $CYBORG_CONF_FILE $section user_domain_name "$SERVICE_DOMAIN_NAME"
iniset $CYBORG_CONF_FILE $section project_name "$SERVICE_TENANT_NAME"
iniset $CYBORG_CONF_FILE $section project_domain_name "$SERVICE_DOMAIN_NAME"
iniset $CYBORG_CONF_FILE $section api_servers "$GLANCE_URL"
}
function configure_cyborg_nova {