Skip to content

Commit

Permalink
* roles_mapping -> feature_mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
sbbroot committed May 12, 2022
1 parent 0794ef3 commit ab3e070
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,9 @@ def __print_parsed_manifest_data(self, output: Dict[str, Any]):

lines.append('')

lines.append('Services detected:')
for service in output['detected-services']:
lines.append(f'- {service}')
lines.append('Features detected:')
for feature in output['detected-features']:
lines.append(f'- {feature}')

lines.append('-' * self.__LINE_SIZE)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ManifestReader:
def __init__(self, dest_manifest: Path):
self.__dest_manifest = dest_manifest
self.__detected_components: Set = set()
self.__detected_services: Set = set()
self.__detected_features: Set = set()

def __parse_cluster_info(self, cluster_doc: Dict):
"""
Expand All @@ -42,24 +42,24 @@ def __parse_cluster_info(self, cluster_doc: Dict):
if components[component]['count'] > 0:
self.__detected_components.add(component)

def __parse_roles_mapping_info(self, roles_mapping_doc: Dict):
def __parse_feature_mappings_info(self, feature_mappings_doc: Dict):
"""
Parse `configuration/roles-mapping` document and extract only used services (based on `epiphany-cluster` doc).
Parse `configuration/feature-mappings` document and extract only used features (based on `epiphany-cluster` doc).
:param roles_mapping_doc: handler to a `configuration/roles-mapping` document
:param feature_mappings_doc: handler to a `configuration/feature-mappings` document
"""
roles = roles_mapping_doc['specification']['roles']
for role in roles.keys() & self.__detected_components:
for service in roles[role]:
self.__detected_services.add(service)
mappings = feature_mappings_doc['specification']['mappings']
for mapping in mappings.keys() & self.__detected_components:
for feature in mappings[mapping]:
self.__detected_features.add(feature)

def parse_manifest(self) -> Dict[str, Any]:
"""
Load the manifest file, call parsers on required docs and return formatted output.
"""
parse_doc: Dict[str, Callable] = {
'epiphany-cluster': self.__parse_cluster_info,
'configuration/roles-mapping': self.__parse_roles_mapping_info
'epiphany-cluster': self.__parse_cluster_info,
'configuration/feature-mappings': self.__parse_feature_mappings_info
}

parsed_docs: Set[str] = set()
Expand All @@ -75,4 +75,4 @@ def parse_manifest(self) -> Dict[str, Any]:
raise CriticalError(f'ManifestReader - could not find documents: {parsed_docs ^ parse_doc.keys()}')

return {'detected-components': sorted(list(self.__detected_components)),
'detected-services': sorted(list(self.__detected_services))}
'detected-features': sorted(list(self.__detected_features))}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

from src.config.config import Config
from tests.data.config import EXPECTED_VERBOSE_OUTPUT
from tests.data.manifest_reader import INPUT_MANIFEST_ROLES_MAPPING
from tests.data.manifest_reader import INPUT_MANIFEST_FEATURE_MAPPINGS


def test_manifest_verbose_output(mocker, caplog):
''' Check output produced when running download-requirements script with the `-v|--verbose` flag and with provided `-m|--manifest` '''

mocker.patch('src.config.manifest_reader.load_yaml_file_all', return_value=yaml.safe_load_all(INPUT_MANIFEST_ROLES_MAPPING))
mocker.patch('src.config.manifest_reader.load_yaml_file_all', return_value=yaml.safe_load_all(INPUT_MANIFEST_FEATURE_MAPPINGS))
caplog.set_level(logging.INFO)

# mock Config's init methods:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import yaml

from src.config.manifest_reader import ManifestReader
from tests.data.manifest_reader import EXPECTED_ROLES_MAPPING, INPUT_MANIFEST_ROLES_MAPPING
from tests.data.manifest_reader import EXPECTED_FEATURE_MAPPINGS, INPUT_MANIFEST_FEATURE_MAPPINGS

def test_parse_manifest(mocker):
''' Check manifest file parsing '''
mocker.patch('src.config.manifest_reader.load_yaml_file_all', return_value=yaml.safe_load_all(INPUT_MANIFEST_ROLES_MAPPING))
mocker.patch('src.config.manifest_reader.load_yaml_file_all', return_value=yaml.safe_load_all(INPUT_MANIFEST_FEATURE_MAPPINGS))

mreader = ManifestReader(Path('/some/path'))
assert mreader.parse_manifest() == EXPECTED_ROLES_MAPPING
assert mreader.parse_manifest() == EXPECTED_FEATURE_MAPPINGS
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
- monitoring
- repository
Services detected:
Features detected:
- filebeat
- firewall
- grafana
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
INPUT_MANIFEST_ROLES_MAPPING = """
INPUT_MANIFEST_FEATURE_MAPPINGS = """
---
kind: epiphany-cluster
title: Epiphany cluster Config
provider: any
Expand Down Expand Up @@ -31,11 +32,11 @@
count: 0
version: 2.0.0dev
---
kind: configuration/roles-mapping
kind: configuration/feature-mappings
title: Feature mapping to roles
name: default
specification:
roles:
mappings:
kafka:
- zookeeper
- jmx-exporter
Expand Down Expand Up @@ -125,9 +126,9 @@
"""


EXPECTED_ROLES_MAPPING = {
EXPECTED_FEATURE_MAPPINGS = {
'detected-components': ['kafka', 'monitoring', 'repository'],
'detected-services': ['filebeat',
'detected-features': ['filebeat',
'firewall',
'grafana',
'image-registry',
Expand Down

0 comments on commit ab3e070

Please sign in to comment.