Merge "Adding Usm Related Configuration"

This commit is contained in:
Zuul
2025-03-07 18:41:48 +00:00
committed by Gerrit Code Review
6 changed files with 303 additions and 0 deletions

View File

@@ -18,6 +18,7 @@ class ConfigurationFileLocationsManager:
self.database_config_file = None
self.rest_api_config_file = None
self.security_config_file = None
self.usm_config_file = None
def set_configs_from_pytest_args(self, session: Session):
"""
@@ -65,6 +66,10 @@ class ConfigurationFileLocationsManager:
if security_config_file:
self.set_security_config_file(security_config_file)
usm_config_file = session.config.getoption("--usm_config_file")
if usm_config_file:
self.set_security_config_file(usm_config_file)
def set_configs_from_options_parser(self, parser: OptionParser = None):
"""
Sets the config files from options parser.
@@ -115,6 +120,10 @@ class ConfigurationFileLocationsManager:
if security_config_file:
self.set_security_config_file(security_config_file)
usm_config_file = options.usm_config_file
if usm_config_file:
self.set_usm_config_file(usm_config_file)
def _add_options(self, parser: OptionParser):
"""
Adds the command line options we can expect.
@@ -197,6 +206,14 @@ class ConfigurationFileLocationsManager:
help="The security config file",
)
parser.add_option(
"--usm_config_file",
action="store",
type="str",
dest="usm_config_file",
help="The Usm config file",
)
options, args = parser.parse_args()
return options
@@ -388,3 +405,23 @@ class ConfigurationFileLocationsManager:
"""
self.security_config_file = security_config_file
def get_usm_config_file(self) -> str:
"""
Getter for usm config file
Returns:
str: the usm config file
"""
return self.usm_config_file
def set_usm_config_file(self, usm_config_file: str):
"""
Setter for usm config file
Args:
usm_config_file (str): the usm config file
"""
self.usm_config_file = usm_config_file

View File

@@ -7,6 +7,7 @@ from config.logger.objects.logger_config import LoggerConfig
from config.ptp.objects.ptp_config import PTPConfig
from config.rest_api.objects.rest_api_config import RestAPIConfig
from config.security.objects.security_config import SecurityConfig
from config.usm.objects.usm_config import UsmConfig
from config.web.objects.web_config import WebConfig
from framework.resources.resource_finder import get_stx_resource_path
@@ -27,6 +28,7 @@ class ConfigurationManagerClass:
self.database_config: DatabaseConfig = None
self.rest_api_config: RestAPIConfig = None
self.security_config: SecurityConfig = None
self.usm_config: UsmConfig = None
self.configuration_locations_manager = None
def is_config_loaded(self) -> bool:
@@ -90,6 +92,10 @@ class ConfigurationManagerClass:
if not security_config_file:
security_config_file = get_stx_resource_path("config/security/files/default.json5")
usm_config_file = config_file_locations.get_usm_config_file()
if not usm_config_file:
usm_config_file = get_stx_resource_path("config/usm/files/default.json5")
if not self.loaded:
try:
self.lab_config = LabConfig(lab_config_file)
@@ -101,6 +107,7 @@ class ConfigurationManagerClass:
self.database_config = DatabaseConfig(database_config_file)
self.rest_api_config = RestAPIConfig(rest_api_config_file)
self.security_config = SecurityConfig(security_config_file)
self.usm_config = UsmConfig(usm_config_file)
self.loaded = True
except FileNotFoundError as e:
print(f"Unable to load the config using file: {str(e.filename)} ")
@@ -197,6 +204,15 @@ class ConfigurationManagerClass:
"""
return self.security_config
def get_usm_config(self) -> UsmConfig:
"""
Getter for usm config
Returns:
UsmConfig: the usm config
"""
return self.usm_config
def get_config_pytest_args(self) -> [str]:
"""
Returns the configuration file locations as pytest args.
@@ -224,6 +240,8 @@ class ConfigurationManagerClass:
pytest_config_args.append(f"--rest_api_config_file={self.configuration_locations_manager.get_rest_api_config_file()}")
if self.configuration_locations_manager.security_config_file:
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()}")
return pytest_config_args

View File

@@ -0,0 +1,44 @@
{
// Indicates the current operation is for Major rel upgrade
"usm_is_upgrade": "",
// Indicates the current operation is patching the system.
"usm_is_patch": "",
// Absolute path to ISO for Major rel upgrade
"iso_path": "/path/to/iso/file",
// Absolute path to the Signature path for Major rel upgrade.
"upgrade_license": "",
// Absolute path to the .patch file for Patching.
"patch_path": "",
// Path of directory where one or more .patch files are located.
"patch_dir": "",
// Directory on the lab where the files need to be stored.
"dest_dir": "",
// Address of the server where the iso/patch files are located.
"build_server": "",
// Username to authenticate to build_server
"build_server_username": "",
// Password to authenticate to build_server
"build_server_password": "",
// Arguments for upgrade/patching testing
"upgrade_arguments": "",
// Release ids (one or more) to which the system is upgraded.
// Used for either multiple patches or major release + patch(es)
"to_release_ids": "",
// Some extra attributes for patching USM, config
"extra_attributes": {
"": "",
},
}

View File

@@ -0,0 +1,172 @@
import json5
class UsmConfig:
"""
Class to hold configuration for USM upgrade/patch tests.
"""
def __init__(self, config):
try:
json_data = open(config)
except FileNotFoundError:
print(f"Could not find the USM config file: {config}")
raise
usm_dict = json5.load(json_data)
self.usm_is_upgrade = usm_dict.get("usm_is_upgrade", None)
self.usm_is_patch = usm_dict.get("usm_is_patch", None)
self.iso_path = usm_dict.get("iso_path", None)
self.upgrade_license = usm_dict.get("upgrade_license", None)
self.patch_path = usm_dict.get("patch_path", None)
self.patch_dir = usm_dict.get("patch_dir", None)
self.dest_dir = usm_dict.get("dest_dir", None)
self.build_server = usm_dict.get("build_server", None)
self.build_server_username = usm_dict.get("build_server_username", None)
self.build_server_password = usm_dict.get("build_server_password", None)
self.upgrade_arguments = usm_dict.get("upgrade_arguments", None)
self.to_release_ids = usm_dict.get("to_release_ids", None)
self.extra_attributes = usm_dict.get("extra_attributes", {})
def get_usm_is_upgrade(self) -> str:
"""
Getter for the usm_is_upgrade
Indicates the current operation is for Major rel upgrade
Returns:
str: the usm_is_upgrade
"""
return self.usm_is_upgrade
def get_usm_is_patch(self) -> str:
"""
Getter for the usm_is_patch
Indicates the current operation is patching the system.
Returns:
str: the usm_is_patch
"""
return self.usm_is_patch
def get_iso_path(self) -> str:
"""
Getter for the iso_path
Absolute path to ISO for Major rel upgrade
Returns:
str: the iso_path
"""
return self.iso_path
def get_upgrade_license(self) -> str:
"""
Getter for the upgrade_license
Absolute path to the Signature path for Major rel upgrade.
Returns:
str: the upgrade_license
"""
return self.upgrade_license
def get_patch_path(self) -> str:
"""
Getter for the patch_path
Absolute path to the .patch file for Patching.
Returns:
str: the patch_path
"""
return self.patch_path
def get_patch_dir(self) -> str:
"""
Getter for the patch_dir
Path of directory where one or more .patch files are located.
Returns:
str: the patch_dir
"""
return self.patch_dir
def get_dest_dir(self) -> str:
"""
Getter for the dest_dir
Directory on the lab where the files need to be stored.
Returns:
str: the dest_dir
"""
return self.dest_dir
def get_build_server(self) -> str:
"""
Getter for the build_server
Address of the server where the iso/patch files are located.
Returns:
str: the build_server
"""
return self.build_server
def get_build_server_username(self) -> str:
"""
Getter for the build_server_username
Username to authenticate to build_server
Returns:
str: the build_server_username
"""
return self.build_server_username
def get_build_server_password(self) -> str:
"""
Getter for the build_server_password
Password to authenticate to build_server
Returns:
str: the build_server_password
"""
return self.build_server_password
def get_upgrade_arguments(self) -> str:
"""
Getter for the upgrade_arguments
Arguments for upgrade/patching testing
Returns:
str: the upgrade_arguments
"""
return self.upgrade_arguments
def get_to_release_ids(self) -> str:
"""
Getter for the to_release_ids
Release ids (one or more) to which the system is upgraded. Used for either multiple patches or major release + patch(es)
Returns:
str: the to_release_ids
"""
return self.to_release_ids
def get_extra_attributes(self) -> dict:
"""
Getter for the extra_attributes
Some extra attributes for patching USM, config
Returns:
dict: the extra_attributes
"""
return self.extra_attributes

View File

@@ -24,6 +24,7 @@ def pytest_addoption(parser: Any):
parser.addoption("--database_config_file", action="store")
parser.addoption("--rest_api_config_file", action="store")
parser.addoption("--security_config_file", action="store")
parser.addoption("--usm_config_file", action="store")
def pytest_sessionstart(session: Any):

View File

@@ -0,0 +1,31 @@
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_usm_config():
"""
Tests that the default usm configuration is as expected.
"""
configuration_manager = ConfigurationManagerClass()
config_file_locations = ConfigurationFileLocationsManager()
configuration_manager.load_configs(config_file_locations)
default_config = configuration_manager.get_usm_config()
assert default_config is not None, "Default usm config wasn't loaded successfully"
assert default_config.get_iso_path() == "/path/to/iso/file", "path/to/file was incorrect"
def test_custom_usm_config():
"""
Tests that we can load a custom usm configuration.
"""
custom_file = get_stx_resource_path("config/usm/files/default.json5")
configuration_manager = ConfigurationManagerClass()
config_file_locations = ConfigurationFileLocationsManager()
config_file_locations.set_usm_config_file(custom_file)
configuration_manager.load_configs(config_file_locations)
custom_config = configuration_manager.get_usm_config()
assert custom_config is not None, "Custom usm config wasn't loaded successfully"
assert custom_config.get_iso_path() == "/path/to/iso/file", "path/to/file was incorrect"