Cloud Platform Version Manager
Implementation of a Version Manager that allows users to get the sw_version of the Cloud Platform in an object that is easy to compare with other releases. The strong typing allows for easy usage check of each version. Change-Id: Idb100e05d118368bfb9cb7e9f1f380c31ecd7b07
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
from keywords.python.product_version import ProductVersion
|
||||
|
||||
|
||||
class CloudPlatformSoftwareVersion:
|
||||
"""
|
||||
This class enumerates the different versions of the Cloud Platform as well as their chronological release order.
|
||||
"""
|
||||
|
||||
STARLINGX_9_0 = ProductVersion("24.03", 0)
|
||||
STARLINGX_10_0 = ProductVersion("24.09", 1)
|
||||
|
||||
# Every new version must contain STARLINGX in the variable name.
|
||||
@@ -0,0 +1,70 @@
|
||||
from keywords.cloud_platform.rest.configuration.system.get_system_keywords import GetSystemKeywords
|
||||
from keywords.cloud_platform.version_info.cloud_platform_software_version import CloudPlatformSoftwareVersion
|
||||
from keywords.python.product_version import ProductVersion
|
||||
|
||||
|
||||
class CloudPlatformVersionManagerClass:
|
||||
"""
|
||||
Singleton Class that keeps track of the current sw_version of the Cloud Platform
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
"""
|
||||
Constructor
|
||||
"""
|
||||
self.sw_version: ProductVersion = None
|
||||
|
||||
def _get_product_version_object(self, version_name) -> ProductVersion:
|
||||
"""
|
||||
This function will find the Product Version object that matches the version_name provided.
|
||||
Args:
|
||||
version_name (str): The version_name as a String
|
||||
|
||||
Returns (ProductVersion): The value from CloudPlatformSoftwareVersion matching the version_name provided
|
||||
"""
|
||||
|
||||
# Build a list of all the ProductVersion available.
|
||||
cloud_platform_software_version_vars = vars(CloudPlatformSoftwareVersion)
|
||||
cloud_platform_product_version_names = [
|
||||
var_name for var_name in list(cloud_platform_software_version_vars.keys()) if "STARLINGX" in var_name
|
||||
]
|
||||
cloud_platform_product_versions = [cloud_platform_software_version_vars.get(version_name) for version_name in cloud_platform_product_version_names]
|
||||
|
||||
# If the version is not in the list of versions, create a default value.
|
||||
product_version = ProductVersion(version_name, 9999)
|
||||
|
||||
# Find and return the appropriate ProductVersion from the list if any.
|
||||
for version in cloud_platform_product_versions:
|
||||
if version_name == version.get_name():
|
||||
product_version = version
|
||||
break
|
||||
|
||||
return product_version
|
||||
|
||||
def _get_sw_version_from_system(self) -> ProductVersion:
|
||||
"""
|
||||
This function will run the isystems API call to get the sw_version from the lab under test.
|
||||
|
||||
Returns: The active ProductVersion.
|
||||
|
||||
"""
|
||||
|
||||
system_output = GetSystemKeywords().get_system()
|
||||
system_object = system_output.get_system_object()
|
||||
sw_version = system_object.get_software_version()
|
||||
product_version = self._get_product_version_object(sw_version)
|
||||
|
||||
return product_version
|
||||
|
||||
def get_sw_version(self) -> ProductVersion:
|
||||
"""
|
||||
This function will return the Cloud Software Version observed on the system.
|
||||
Returns:
|
||||
|
||||
"""
|
||||
if not self.sw_version:
|
||||
self.sw_version = self._get_sw_version_from_system()
|
||||
return self.sw_version
|
||||
|
||||
|
||||
CloudPlatformVersionManager = CloudPlatformVersionManagerClass()
|
||||
63
keywords/python/product_version.py
Normal file
63
keywords/python/product_version.py
Normal file
@@ -0,0 +1,63 @@
|
||||
class ProductVersion:
|
||||
"""
|
||||
This class models a ProductVersion as an object.
|
||||
ProductVersions have names and can also be compared chronologically.
|
||||
"""
|
||||
|
||||
def __init__(self, version_name: str, version_id: int):
|
||||
"""
|
||||
Constructor
|
||||
Args:
|
||||
version_name (str): The String name of the Product Version
|
||||
version_id (int) : Integers assigned for comparing release order
|
||||
"""
|
||||
self.version_name = version_name
|
||||
self.version_id = version_id
|
||||
|
||||
def __str__(self) -> str:
|
||||
return self.version_name
|
||||
|
||||
def __hash__(self):
|
||||
return hash(self.version_name)
|
||||
|
||||
def __eq__(self, other):
|
||||
return hash(self) == hash(other)
|
||||
|
||||
def get_name(self) -> str:
|
||||
"""
|
||||
Getter for the name of this version
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
return self.version_name
|
||||
|
||||
def get_id(self) -> int:
|
||||
"""
|
||||
Getter for the id of this version
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
return self.version_id
|
||||
|
||||
def is_before_or_equal_to(self, other_product_version) -> bool:
|
||||
"""
|
||||
Returns true if SELF <= other_product_version based on their id.
|
||||
Args:
|
||||
other_product_version (ProductVersion): The version of comparison
|
||||
|
||||
Returns (bool): SELF <= other_product_version based on their id.
|
||||
"""
|
||||
return self.version_id <= other_product_version.version_id
|
||||
|
||||
def is_after_or_equal_to(self, other_product_version) -> bool:
|
||||
"""
|
||||
Returns true if SELF >= other_product_version based on their id.
|
||||
Args:
|
||||
other_product_version (ProductVersion): The version of comparison
|
||||
|
||||
Returns (bool): SELF >= other_product_version based on their id.
|
||||
"""
|
||||
return self.version_id >= other_product_version.version_id
|
||||
|
||||
Reference in New Issue
Block a user