Remove dead config substitution code
This PS removes some dead config substitution code from Promenade's config.py module. This code became dead in the following PS: https://review.gerrithub.io/#/c/394615/ which migrated over to Deckhand-based substitution, causing Promenade's former substitution code to no longer be used anywhere. Change-Id: Ic96e522557101310db289712068db9528fd040d6
This commit is contained in:
parent
810f69a64b
commit
753576a89b
@ -1,6 +1,5 @@
|
||||
from . import exceptions, logging, validation
|
||||
from .design_ref import get_documents
|
||||
import copy
|
||||
import jinja2
|
||||
import jsonpath_ng
|
||||
import yaml
|
||||
@ -190,43 +189,6 @@ def _get(documents, kind=None, schema=None, name=None):
|
||||
return document
|
||||
|
||||
|
||||
def _substitute(documents):
|
||||
result = []
|
||||
|
||||
for document in documents:
|
||||
dest_schema = document.get('schema')
|
||||
dest_name = _mg(document, 'name')
|
||||
LOG.debug('Checking for substitutions in schema=%s metadata.name=%s',
|
||||
dest_schema, dest_name)
|
||||
final_doc = copy.deepcopy(document)
|
||||
for substitution in _mg(document, 'substitutions', []):
|
||||
source_schema = substitution['src']['schema']
|
||||
source_name = substitution['src']['name']
|
||||
source_path = substitution['src']['path']
|
||||
dest_path = substitution['dest']['path']
|
||||
LOG.debug('Substituting from schema=%s name=%s src_path=%s '
|
||||
'into dest_path=%s', source_schema, source_name,
|
||||
source_path, dest_path)
|
||||
source_document = _get(
|
||||
documents, schema=source_schema, name=source_name)
|
||||
if source_document is None:
|
||||
msg = 'Failed to find source document for subsitution. ' \
|
||||
'dest_schema=%s dest_name=%s ' \
|
||||
'source_schema=%s source_name=%s' \
|
||||
% (dest_schema, dest_name, source_schema, source_name)
|
||||
LOG.critical(msg)
|
||||
raise exceptions.ValidationException(msg)
|
||||
|
||||
source_value = _extract(source_document['data'],
|
||||
substitution['src']['path'])
|
||||
final_doc['data'] = _replace(final_doc['data'], source_value,
|
||||
substitution['dest']['path'])
|
||||
|
||||
result.append(final_doc)
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def _extract(document, jsonpath):
|
||||
p = jsonpath_ng.parse(jsonpath)
|
||||
matches = p.find(document)
|
||||
@ -234,10 +196,5 @@ def _extract(document, jsonpath):
|
||||
return matches[0].value
|
||||
|
||||
|
||||
def _replace(document, value, jsonpath):
|
||||
p = jsonpath_ng.parse(jsonpath)
|
||||
return p.update(document, value)
|
||||
|
||||
|
||||
def _mg(document, field, default=None):
|
||||
return document.get('metadata', {}).get(field, default)
|
||||
|
Loading…
Reference in New Issue
Block a user