Cleanup token checking in uploader and add a variation of xpath like mechanism for objects
This commit is contained in:
parent
7622ca99fc
commit
2d14a6b1db
@ -561,8 +561,7 @@ class ProgramRuntime(ComponentBase):
|
||||
# Adjust the program options now that we have real locations
|
||||
program_opts = utils.param_replace_list(self._get_app_options(app_name), self._get_param_map(app_name))
|
||||
# Start it with the given settings
|
||||
LOG.debug("Starting %r with options (%s) using %r",
|
||||
app_name, ", ".join(program_opts), run_type)
|
||||
LOG.debug("Starting %r using %r", app_name, run_type)
|
||||
details_fn = instance.start(app_name,
|
||||
app_pth=app_pth, app_dir=app_dir, opts=program_opts)
|
||||
LOG.info("Started %r details are in %r", app_name, details_fn)
|
||||
@ -578,6 +577,7 @@ class ProgramRuntime(ComponentBase):
|
||||
killcls = None
|
||||
try:
|
||||
killcls = importer.import_entry_point(how)
|
||||
LOG.debug("Stopping %r using %r", app_name, how)
|
||||
except RuntimeError as e:
|
||||
LOG.warn("Could not load class %r which should be used to stop %r: %s", how, app_name, e)
|
||||
if killcls in killer_instances:
|
||||
|
@ -338,21 +338,13 @@ class Service:
|
||||
LOG.debug("With headers %s" % (headers))
|
||||
|
||||
response = urllib2.urlopen(request)
|
||||
|
||||
token = json.loads(response.read())
|
||||
|
||||
# TODO is there a better way to validate???
|
||||
if (not token or not type(token) is dict or
|
||||
not token.get('access') or not type(token.get('access')) is dict or
|
||||
not token.get('access').get('token') or not type(token.get('access').get('token')) is dict or
|
||||
not token.get('access').get('token').get('id')):
|
||||
token = utils.get_from_path(json.loads(response.read()), "access/token/id")
|
||||
if not token:
|
||||
msg = "Response from url %r did not match expected json format." % (keystone_token_url)
|
||||
raise IOError(msg)
|
||||
|
||||
# Basic checks passed, extract it!
|
||||
tok = token['access']['token']['id']
|
||||
LOG.debug("Got token %r" % (tok))
|
||||
return tok
|
||||
LOG.debug("Got token %r" % (token))
|
||||
return token
|
||||
|
||||
def install(self):
|
||||
LOG.info("Setting up any specified images in glance.")
|
||||
|
@ -94,6 +94,41 @@ def make_bool(val):
|
||||
return False
|
||||
|
||||
|
||||
def get_from_path(items, path, quiet=True):
|
||||
|
||||
(first_token, sep, remainder) = path.partition('/')
|
||||
|
||||
if len(path) == 0:
|
||||
return items
|
||||
|
||||
LOG.debug("Looking up %r in %s" % (path, items))
|
||||
|
||||
if len(first_token) == 0:
|
||||
if not quiet:
|
||||
raise RuntimeError("Invalid first token found in %s" % (path))
|
||||
else:
|
||||
return None
|
||||
|
||||
if isinstance(items, list):
|
||||
index = int(first_token)
|
||||
ok_use = (index < len(items) and index >= 0)
|
||||
if quiet and not ok_use:
|
||||
return None
|
||||
else:
|
||||
LOG.debug("Looking up index %s in list %s" % (index, items))
|
||||
return get_from_path(items[index], remainder)
|
||||
else:
|
||||
get_method = getattr(items, 'get', None)
|
||||
if not get_method:
|
||||
if not quiet:
|
||||
raise RuntimeError("Can not figure out how to extract an item from %s" % (items))
|
||||
else:
|
||||
return None
|
||||
else:
|
||||
LOG.debug("Looking up %r in object %s with method %s" % (first_token, items, get_method))
|
||||
return get_from_path(get_method(first_token), remainder)
|
||||
|
||||
|
||||
def configure_logging(log_level, cli_args):
|
||||
root_logger = logging.getLogger().logger
|
||||
console_logger = logging.StreamHandler(sys.stdout)
|
||||
|
Loading…
x
Reference in New Issue
Block a user