Adding a app config file
Information related to apps can be added here. Change-Id: Ic022e342d3f11b3344eb7390615c1ee0477d0d88
This commit is contained in:
5
config/app/files/default.json5
Normal file
5
config/app/files/default.json5
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
base_application_path: "/usr/local/share/applications/helm/",
|
||||
istio_app_name: "istio",
|
||||
metric_server_app_name: "metrics-server"
|
||||
}
|
||||
49
config/app/objects/app_config.py
Normal file
49
config/app/objects/app_config.py
Normal file
@@ -0,0 +1,49 @@
|
||||
import json5
|
||||
|
||||
|
||||
class AppConfig:
|
||||
"""
|
||||
Class to hold App config
|
||||
"""
|
||||
|
||||
def __init__(self, config: str):
|
||||
try:
|
||||
json_data = open(config)
|
||||
except FileNotFoundError:
|
||||
print(f"Could not find the app config file: {config}")
|
||||
raise
|
||||
|
||||
app_dict = json5.load(json_data)
|
||||
self.base_application_path = app_dict["base_application_path"]
|
||||
self.istio_app_name = app_dict["istio_app_name"]
|
||||
self.metric_server_app_name = app_dict["metric_server_app_name"]
|
||||
|
||||
def get_base_application_path(self) -> str:
|
||||
"""
|
||||
Getter for base application path
|
||||
|
||||
Returns:
|
||||
str: the base application path
|
||||
|
||||
"""
|
||||
return self.base_application_path
|
||||
|
||||
def get_istio_app_name(self) -> str:
|
||||
"""
|
||||
Getter for istio app name
|
||||
|
||||
Returns:
|
||||
str: the istio app name path
|
||||
|
||||
"""
|
||||
return self.istio_app_name
|
||||
|
||||
def get_metric_server_app_name(self) -> str:
|
||||
"""
|
||||
Getter for metric server app name
|
||||
|
||||
Returns:
|
||||
str: the metric server app name
|
||||
|
||||
"""
|
||||
return self.metric_server_app_name
|
||||
@@ -19,6 +19,7 @@ class ConfigurationFileLocationsManager:
|
||||
self.rest_api_config_file = None
|
||||
self.security_config_file = None
|
||||
self.usm_config_file = None
|
||||
self.app_config_file = None
|
||||
|
||||
def set_configs_from_pytest_args(self, session: Session):
|
||||
"""
|
||||
@@ -70,6 +71,10 @@ class ConfigurationFileLocationsManager:
|
||||
if usm_config_file:
|
||||
self.set_security_config_file(usm_config_file)
|
||||
|
||||
app_config_file = session.config.getoption("--app_config_file")
|
||||
if app_config_file:
|
||||
self.set_app_config_file(app_config_file)
|
||||
|
||||
def set_configs_from_options_parser(self, parser: OptionParser = None):
|
||||
"""
|
||||
Sets the config files from options parser.
|
||||
@@ -124,6 +129,10 @@ class ConfigurationFileLocationsManager:
|
||||
if usm_config_file:
|
||||
self.set_usm_config_file(usm_config_file)
|
||||
|
||||
app_config_file = options.app_config_file
|
||||
if app_config_file:
|
||||
self.set_app_config_file(app_config_file)
|
||||
|
||||
def _add_options(self, parser: OptionParser):
|
||||
"""
|
||||
Adds the command line options we can expect.
|
||||
@@ -214,6 +223,14 @@ class ConfigurationFileLocationsManager:
|
||||
help="The Usm config file",
|
||||
)
|
||||
|
||||
parser.add_option(
|
||||
"--app_config_file",
|
||||
action="store",
|
||||
type="str",
|
||||
dest="app_config_file",
|
||||
help="The app config file",
|
||||
)
|
||||
|
||||
options, args = parser.parse_args()
|
||||
|
||||
return options
|
||||
@@ -425,3 +442,22 @@ class ConfigurationFileLocationsManager:
|
||||
|
||||
"""
|
||||
self.usm_config_file = usm_config_file
|
||||
|
||||
def get_app_config_file(self) -> str:
|
||||
"""
|
||||
Getter for app config file
|
||||
|
||||
Returns:
|
||||
str: the app config file
|
||||
"""
|
||||
return self.app_config_file
|
||||
|
||||
def set_app_config_file(self, app_config_file: str):
|
||||
"""
|
||||
Setter for app config file
|
||||
|
||||
Args:
|
||||
app_config_file (str): the app config file
|
||||
|
||||
"""
|
||||
self.app_config_file = app_config_file
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from config.app.objects.app_config import AppConfig
|
||||
from config.configuration_file_locations_manager import ConfigurationFileLocationsManager
|
||||
from config.database.objects.database_config import DatabaseConfig
|
||||
from config.docker.objects.docker_config import DockerConfig
|
||||
@@ -29,6 +30,7 @@ class ConfigurationManagerClass:
|
||||
self.rest_api_config: RestAPIConfig = None
|
||||
self.security_config: SecurityConfig = None
|
||||
self.usm_config: UsmConfig = None
|
||||
self.app_config: AppConfig = None
|
||||
self.configuration_locations_manager = None
|
||||
|
||||
def is_config_loaded(self) -> bool:
|
||||
@@ -96,6 +98,10 @@ class ConfigurationManagerClass:
|
||||
if not usm_config_file:
|
||||
usm_config_file = get_stx_resource_path("config/usm/files/default.json5")
|
||||
|
||||
app_config_file = config_file_locations.get_app_config_file()
|
||||
if not app_config_file:
|
||||
app_config_file = get_stx_resource_path("config/app/files/default.json5")
|
||||
|
||||
if not self.loaded:
|
||||
try:
|
||||
self.lab_config = LabConfig(lab_config_file)
|
||||
@@ -108,6 +114,7 @@ class ConfigurationManagerClass:
|
||||
self.rest_api_config = RestAPIConfig(rest_api_config_file)
|
||||
self.security_config = SecurityConfig(security_config_file)
|
||||
self.usm_config = UsmConfig(usm_config_file)
|
||||
self.app_config = AppConfig(app_config_file)
|
||||
self.loaded = True
|
||||
except FileNotFoundError as e:
|
||||
print(f"Unable to load the config using file: {str(e.filename)} ")
|
||||
@@ -213,6 +220,16 @@ class ConfigurationManagerClass:
|
||||
"""
|
||||
return self.usm_config
|
||||
|
||||
def get_app_config(self) -> AppConfig:
|
||||
"""
|
||||
Getter for app config
|
||||
|
||||
Returns:
|
||||
AppConfig: the app config
|
||||
|
||||
"""
|
||||
return self.app_config
|
||||
|
||||
def get_config_pytest_args(self) -> [str]:
|
||||
"""
|
||||
Returns the configuration file locations as pytest args.
|
||||
@@ -242,6 +259,8 @@ class ConfigurationManagerClass:
|
||||
pytest_config_args.append(f"--security_config_file={self.configuration_locations_manager.get_security_config_file()}")
|
||||
if self.configuration_locations_manager.usm_config_file:
|
||||
pytest_config_args.append(f"--usm_config_file={self.configuration_locations_manager.get_usm_config_file()}")
|
||||
if self.configuration_locations_manager.app_config_file:
|
||||
pytest_config_args.append(f"--app_config_file={self.configuration_locations_manager.get_app_config_file()}")
|
||||
|
||||
return pytest_config_args
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ def pytest_addoption(parser: Any):
|
||||
parser.addoption("--rest_api_config_file", action="store")
|
||||
parser.addoption("--security_config_file", action="store")
|
||||
parser.addoption("--usm_config_file", action="store")
|
||||
parser.addoption("--app_config_file", action="store")
|
||||
|
||||
|
||||
def pytest_sessionstart(session: Any):
|
||||
|
||||
35
unit_tests/config/app/app_config_test.py
Normal file
35
unit_tests/config/app/app_config_test.py
Normal file
@@ -0,0 +1,35 @@
|
||||
from config.configuration_file_locations_manager import ConfigurationFileLocationsManager
|
||||
from config.configuration_manager import ConfigurationManagerClass
|
||||
from framework.resources.resource_finder import get_stx_resource_path
|
||||
|
||||
|
||||
def test_default_app_config():
|
||||
"""
|
||||
Tests that the default app configuration is as expected.
|
||||
|
||||
"""
|
||||
configuration_manager = ConfigurationManagerClass()
|
||||
config_file_locations = ConfigurationFileLocationsManager()
|
||||
configuration_manager.load_configs(config_file_locations)
|
||||
default_config = configuration_manager.get_app_config()
|
||||
assert default_config is not None, "Default app config wasn't loaded successfully"
|
||||
assert default_config.get_base_application_path() == "/usr/local/share/applications/helm/", "default base path was incorrect"
|
||||
assert default_config.get_istio_app_name() == "istio", "istio default app name was incorrect"
|
||||
assert default_config.get_metric_server_app_name() == "metrics-server", "metric server default name was incorrect"
|
||||
|
||||
|
||||
def test_custom_app_config():
|
||||
"""
|
||||
Tests that we can load a custom app configuration.
|
||||
"""
|
||||
custom_file = get_stx_resource_path("unit_tests/config/app/custom_app_config.json5")
|
||||
configuration_manager = ConfigurationManagerClass()
|
||||
config_file_locations = ConfigurationFileLocationsManager()
|
||||
config_file_locations.set_app_config_file(custom_file)
|
||||
configuration_manager.load_configs(config_file_locations)
|
||||
|
||||
custom_config = configuration_manager.get_app_config()
|
||||
assert custom_config is not None, "Default app config wasn't loaded successfully"
|
||||
assert custom_config.get_base_application_path() == "fake_path", "custom base path was incorrect"
|
||||
assert custom_config.get_istio_app_name() == "istio_custom", "istio custom app name was incorrect"
|
||||
assert custom_config.get_metric_server_app_name() == "metrics-server_custom", "metric server custom name was incorrect"
|
||||
5
unit_tests/config/app/custom_app_config.json5
Normal file
5
unit_tests/config/app/custom_app_config.json5
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
base_application_path: "fake_path",
|
||||
istio_app_name: "istio_custom",
|
||||
metric_server_app_name: "metrics-server_custom"
|
||||
}
|
||||
Reference in New Issue
Block a user