Merge "Support multiple capabilities in system_storage_backend_object"
This commit is contained in:
@@ -4,43 +4,66 @@ class StorageCapabilities:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
self.deployment_model = None
|
||||||
self.replication: int = -1
|
self.replication: int = -1
|
||||||
self.min_replication: int = -1
|
self.min_replication: int = -1
|
||||||
|
|
||||||
def set_replication(self, replication: int):
|
def set_replication(self, replication: int):
|
||||||
"""
|
"""
|
||||||
Setter for replication
|
Setter for replication
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
replication:
|
replication(int): replication number
|
||||||
|
|
||||||
Returns:
|
|
||||||
|
|
||||||
|
Returns: None
|
||||||
"""
|
"""
|
||||||
self.replication = replication
|
self.replication = replication
|
||||||
|
|
||||||
def get_replication(self) -> int:
|
def get_replication(self) -> int:
|
||||||
"""
|
"""
|
||||||
Getter for replication
|
Getter for replication
|
||||||
Returns:
|
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
int: replication number
|
||||||
"""
|
"""
|
||||||
return self.replication
|
return self.replication
|
||||||
|
|
||||||
def set_min_replication(self, min_replication: int):
|
def set_min_replication(self, min_replication: int):
|
||||||
"""
|
"""
|
||||||
Setter for min_replication
|
Setter for min_replication
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
min_replication:
|
min_replication (int): min_replication number
|
||||||
|
|
||||||
Returns:
|
|
||||||
|
|
||||||
|
Returns: None
|
||||||
"""
|
"""
|
||||||
self.min_replication = min_replication
|
self.min_replication = min_replication
|
||||||
|
|
||||||
def get_min_replication(self) -> int:
|
def get_min_replication(self) -> int:
|
||||||
"""
|
"""
|
||||||
Getter for min_replication
|
Getter for min_replication
|
||||||
Returns:
|
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
int: min_replication number
|
||||||
"""
|
"""
|
||||||
return self.min_replication
|
return self.min_replication
|
||||||
|
|
||||||
|
def set_deployment_model(self, deployment_model: str):
|
||||||
|
"""
|
||||||
|
Setter for deployment_model
|
||||||
|
|
||||||
|
Args:
|
||||||
|
deployment_model (str): deployment_model
|
||||||
|
|
||||||
|
Returns: None
|
||||||
|
"""
|
||||||
|
self.deployment_model = deployment_model
|
||||||
|
|
||||||
|
def get_deployment_model(self) -> str:
|
||||||
|
"""
|
||||||
|
Getter for deployment_model
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str: deployment_model
|
||||||
|
"""
|
||||||
|
return self.deployment_model
|
||||||
|
|||||||
@@ -1,9 +1,14 @@
|
|||||||
from keywords.cloud_platform.system.host.objects.storage_capabilities_object import StorageCapabilities
|
import re
|
||||||
|
|
||||||
|
from keywords.cloud_platform.system.host.objects.storage_capabilities_object import (
|
||||||
|
StorageCapabilities,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class SystemStorageBackendObject:
|
class SystemStorageBackendObject:
|
||||||
"""
|
"""
|
||||||
This class represents a Storage Backend as an object.
|
This class represents a Storage Backend as an object.
|
||||||
|
|
||||||
This is typically a line in the system storage-backend-list output table.
|
This is typically a line in the system storage-backend-list output table.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@@ -19,137 +24,162 @@ class SystemStorageBackendObject:
|
|||||||
def get_name(self) -> str:
|
def get_name(self) -> str:
|
||||||
"""
|
"""
|
||||||
Getter for this storage's name
|
Getter for this storage's name
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str: name
|
||||||
"""
|
"""
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
def set_uuid(self, uuid: str):
|
def set_uuid(self, uuid: str):
|
||||||
"""
|
"""
|
||||||
Setter for uuid
|
Setter for uuid
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
uuid:
|
uuid(str) : uuid
|
||||||
|
|
||||||
Returns:
|
|
||||||
|
|
||||||
|
Returns: None
|
||||||
"""
|
"""
|
||||||
self.uuid = uuid
|
self.uuid = uuid
|
||||||
|
|
||||||
def get_uuid(self) -> str:
|
def get_uuid(self) -> str:
|
||||||
"""
|
"""
|
||||||
Getter for uuid
|
Getter for uuid
|
||||||
Returns:
|
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str: uuid
|
||||||
"""
|
"""
|
||||||
return self.uuid
|
return self.uuid
|
||||||
|
|
||||||
def set_backend(self, backend: str):
|
def set_backend(self, backend: str):
|
||||||
"""
|
"""
|
||||||
Setter for backend
|
Setter for backend
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
backend:
|
backend(str) : backend
|
||||||
|
|
||||||
Returns:
|
|
||||||
|
|
||||||
|
Returns: None
|
||||||
"""
|
"""
|
||||||
self.backend = backend
|
self.backend = backend
|
||||||
|
|
||||||
def get_backend(self) -> str:
|
def get_backend(self) -> str:
|
||||||
"""
|
"""
|
||||||
Getter for backend
|
Getter for backend
|
||||||
Returns:
|
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str: backend
|
||||||
"""
|
"""
|
||||||
return self.backend
|
return self.backend
|
||||||
|
|
||||||
def set_state(self, state: str):
|
def set_state(self, state: str):
|
||||||
"""
|
"""
|
||||||
Setter for state
|
Setter for state
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
state:
|
state(str) : state
|
||||||
|
|
||||||
Returns:
|
|
||||||
|
|
||||||
|
Returns: None
|
||||||
"""
|
"""
|
||||||
self.state = state
|
self.state = state
|
||||||
|
|
||||||
def get_state(self) -> str:
|
def get_state(self) -> str:
|
||||||
"""
|
"""
|
||||||
Getter for state
|
Getter for state
|
||||||
Returns:
|
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str: state
|
||||||
"""
|
"""
|
||||||
return self.state
|
return self.state
|
||||||
|
|
||||||
def set_task(self, task: str):
|
def set_task(self, task: str):
|
||||||
"""
|
"""
|
||||||
Setter for task
|
Setter for task
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
task:
|
task(str) : task
|
||||||
|
|
||||||
Returns:
|
|
||||||
|
|
||||||
|
Returns: None
|
||||||
"""
|
"""
|
||||||
self.task = task
|
self.task = task
|
||||||
|
|
||||||
def get_task(self) -> str:
|
def get_task(self) -> str:
|
||||||
"""
|
"""
|
||||||
Getter for task
|
Getter for task
|
||||||
Returns:
|
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str: task
|
||||||
"""
|
"""
|
||||||
return self.task
|
return self.task
|
||||||
|
|
||||||
def set_services(self, services: str):
|
def set_services(self, services: str):
|
||||||
"""
|
"""
|
||||||
Setter for services
|
Setter for services
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
services:
|
services(str) : services
|
||||||
|
|
||||||
Returns:
|
|
||||||
|
|
||||||
|
Returns: None
|
||||||
"""
|
"""
|
||||||
self.services = services
|
self.services = services
|
||||||
|
|
||||||
def get_services(self) -> str:
|
def get_services(self) -> str:
|
||||||
"""
|
"""
|
||||||
Getter for services
|
Getter for services
|
||||||
Returns:
|
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str: service
|
||||||
"""
|
"""
|
||||||
return self.services
|
return self.services
|
||||||
|
|
||||||
def add_capabilities(self, capabilities_output: str):
|
def add_capabilities(self, capabilities_output: str):
|
||||||
"""
|
"""
|
||||||
Setter for storage capabilities
|
Setter for storage capabilities or adds capabilities to existing object if it is already set.
|
||||||
Adds capabilities to existing object if it is already set.
|
|
||||||
Args:
|
Args:
|
||||||
capabilities_output (): the string of capabilities from the system storage-backend-list command
|
capabilities_output(str): capabilities_output
|
||||||
e.g. "replication: 1", "min_replication: 1"
|
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
ValueError: If the capabilities output items is not an even number
|
||||||
|
Raises:
|
||||||
|
ValueError: If the key name not either replication or min_replication
|
||||||
Returns: None
|
Returns: None
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if not self.capabilities:
|
if not self.capabilities:
|
||||||
self.capabilities = StorageCapabilities()
|
self.capabilities = StorageCapabilities()
|
||||||
|
|
||||||
tokenized_capability = capabilities_output.split(":")
|
# str "capabilities_output" is like "replication: 2min_replication: 1"
|
||||||
if len(tokenized_capability) != 2:
|
# Add space after a number if followed by a non-number
|
||||||
|
capabilities_output = re.sub(r"([0-9]+)([a-zA-Z]+)", r"\1 \2", capabilities_output)
|
||||||
|
|
||||||
|
# Add space before "replication" unless preceded by "_" to avoid change for "min_replication"
|
||||||
|
capabilities_output = re.sub(r"(?<!_)replication", r" replication", capabilities_output)
|
||||||
|
|
||||||
|
# Add space before "min_replication"
|
||||||
|
capabilities_output = re.sub(r"min_", r" min_", capabilities_output)
|
||||||
|
|
||||||
|
# Add space before "deployment_model"
|
||||||
|
capabilities_output = re.sub(r"deploy", r" deploy", capabilities_output)
|
||||||
|
|
||||||
|
# remove all colon
|
||||||
|
capabilities_output = capabilities_output.replace(":", "")
|
||||||
|
|
||||||
|
tokenized_capability = capabilities_output.split()
|
||||||
|
if len(tokenized_capability) % 2 != 0:
|
||||||
raise ValueError(f"Unexpected format for add_capabilities {capabilities_output}. Expecting 'key:value' pair.")
|
raise ValueError(f"Unexpected format for add_capabilities {capabilities_output}. Expecting 'key:value' pair.")
|
||||||
|
|
||||||
key = tokenized_capability[0].strip()
|
for i in range(0, len(tokenized_capability), 2):
|
||||||
value = tokenized_capability[1].strip()
|
key = tokenized_capability[i]
|
||||||
|
value = tokenized_capability[i + 1]
|
||||||
if key == 'replication':
|
if key == "replication":
|
||||||
self.capabilities.set_replication(int(value))
|
self.capabilities.set_replication(int(value))
|
||||||
elif key == 'min_replication':
|
elif key == "min_replication":
|
||||||
self.capabilities.set_min_replication(int(value))
|
self.capabilities.set_min_replication(int(value))
|
||||||
else:
|
elif key == "deployment_model":
|
||||||
raise ValueError("Cannot set value of StorageCapability for key: {key}")
|
self.capabilities.set_deployment_model(value)
|
||||||
|
else:
|
||||||
|
raise ValueError("Cannot set value of StorageCapability for key: {key}")
|
||||||
|
|
||||||
def get_capabilities(self) -> StorageCapabilities:
|
def get_capabilities(self) -> StorageCapabilities:
|
||||||
"""
|
"""
|
||||||
Getter for capabilities
|
Getter for capabilities
|
||||||
Returns:
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
return self.capabilities
|
return self.capabilities
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
from framework.exceptions.keyword_exception import KeywordException
|
from framework.exceptions.keyword_exception import KeywordException
|
||||||
from keywords.cloud_platform.system.storage.objects.system_storage_backend_object import SystemStorageBackendObject
|
from keywords.cloud_platform.system.storage.objects.system_storage_backend_object import (
|
||||||
|
SystemStorageBackendObject,
|
||||||
|
)
|
||||||
from keywords.cloud_platform.system.system_table_parser import SystemTableParser
|
from keywords.cloud_platform.system.system_table_parser import SystemTableParser
|
||||||
|
|
||||||
|
|
||||||
@@ -23,7 +25,6 @@ class SystemStorageBackendOutput:
|
|||||||
'+--------------------------------------+------------+---------+------------+------+----------+--------------------+\n']
|
'+--------------------------------------+------------+---------+------------+------+----------+--------------------+\n']
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
self.system_storage_backends: [SystemStorageBackendObject] = []
|
self.system_storage_backends: [SystemStorageBackendObject] = []
|
||||||
system_table_parser = SystemTableParser(system_storage_backend_list_output)
|
system_table_parser = SystemTableParser(system_storage_backend_list_output)
|
||||||
output_values = system_table_parser.get_output_values_list()
|
output_values = system_table_parser.get_output_values_list()
|
||||||
@@ -31,48 +32,64 @@ class SystemStorageBackendOutput:
|
|||||||
system_storage_backend_object = None
|
system_storage_backend_object = None
|
||||||
for value in output_values:
|
for value in output_values:
|
||||||
|
|
||||||
if 'name' not in value:
|
if "name" not in value:
|
||||||
raise KeywordException(f"The output line {value} was not valid because it is missing an 'name'.")
|
raise KeywordException(f"The output line {value} was not valid because it is missing an 'name'.")
|
||||||
|
|
||||||
if not value['name']:
|
if not value["name"]:
|
||||||
# If there is no name, then this line contains extra info about the last line.
|
# If there is no name, then this line contains extra info about the last line.
|
||||||
# We should add the capabilities to the last entry.
|
# We should add the capabilities to the last entry.
|
||||||
if 'capabilities' in value:
|
if "capabilities" in value:
|
||||||
system_storage_backend_object.add_capabilities(value['capabilities'])
|
system_storage_backend_object.add_capabilities(value["capabilities"])
|
||||||
continue
|
continue
|
||||||
|
|
||||||
system_storage_backend_object = SystemStorageBackendObject(value['name'])
|
system_storage_backend_object = SystemStorageBackendObject(value["name"])
|
||||||
|
|
||||||
if 'uuid' in value:
|
if "uuid" in value:
|
||||||
system_storage_backend_object.set_uuid(value['uuid'])
|
system_storage_backend_object.set_uuid(value["uuid"])
|
||||||
|
|
||||||
if 'backend' in value:
|
if "backend" in value:
|
||||||
system_storage_backend_object.set_backend(value['backend'])
|
system_storage_backend_object.set_backend(value["backend"])
|
||||||
|
|
||||||
if 'state' in value:
|
if "state" in value:
|
||||||
system_storage_backend_object.set_state(value['state'])
|
system_storage_backend_object.set_state(value["state"])
|
||||||
|
|
||||||
if 'task' in value:
|
if "task" in value:
|
||||||
system_storage_backend_object.set_task(value['task'])
|
system_storage_backend_object.set_task(value["task"])
|
||||||
|
|
||||||
if 'services' in value:
|
if "services" in value:
|
||||||
system_storage_backend_object.set_services(value['services'])
|
system_storage_backend_object.set_services(value["services"])
|
||||||
|
|
||||||
if 'capabilities' in value:
|
if "capabilities" in value:
|
||||||
system_storage_backend_object.add_capabilities(value['capabilities'])
|
system_storage_backend_object.add_capabilities(value["capabilities"])
|
||||||
|
|
||||||
self.system_storage_backends.append(system_storage_backend_object)
|
self.system_storage_backends.append(system_storage_backend_object)
|
||||||
|
|
||||||
def get_system_storage_backends(self) -> list[SystemStorageBackendObject]:
|
def get_system_storage_backends(self) -> list[SystemStorageBackendObject]:
|
||||||
"""
|
"""
|
||||||
Returns a list of objects representing each row of the table displayed as the result of executing the
|
Returns a list of objects representing each row of the table displayed as the result of executing the 'system storage-backend-list' command.
|
||||||
'system storage-backend-list' command.
|
|
||||||
|
|
||||||
Args: None.
|
Args: None.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
list[SystemStorageBackendObject]: list of objects representing each row of the table displayed as the result of executing the
|
list[SystemStorageBackendObject]: list of objects representing each row of the table displayed as the result of executing the
|
||||||
'system storage-backend-list' command.
|
'system storage-backend-list' command.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
return self.system_storage_backends
|
return self.system_storage_backends
|
||||||
|
|
||||||
|
def get_system_storage_backend(self, backend: str) -> SystemStorageBackendObject:
|
||||||
|
"""
|
||||||
|
Gets the given backend
|
||||||
|
|
||||||
|
Args:
|
||||||
|
backend (str): the name of the backend ceph or ceph-rook
|
||||||
|
|
||||||
|
Raises:
|
||||||
|
KeywordException: the given name is not exist
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
SystemStorageBackendObject: the given backend object
|
||||||
|
"""
|
||||||
|
backends = list(filter(lambda item: item.get_backend() == backend, self.system_storage_backends))
|
||||||
|
if len(backends) == 0:
|
||||||
|
raise KeywordException(f"No application with name {backend} was found.")
|
||||||
|
return backends[0]
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
from keywords.cloud_platform.system.storage.objects.system_storage_backend_output import (
|
||||||
|
SystemStorageBackendOutput,
|
||||||
|
)
|
||||||
|
from keywords.cloud_platform.system.system_table_parser import SystemTableParser
|
||||||
|
|
||||||
|
storage_backend_list_ceph_output = ["+--------------------------------------+------------+---------+------------+------+----------+--------------------+\n", "| uuid | name | backend | state | task | services | capabilities |\n", "+--------------------------------------+------------+---------+------------+------+----------+--------------------+\n", "| b3655f85-5e16-471e-b994-c9f910c53f00 | ceph-store | ceph | configured | None | None | replication: 2 |\n", "| | | | | | | min_replication: 1 |\n", "+--------------------------------------+------------+---------+------------+------+----------+--------------------+\n"]
|
||||||
|
|
||||||
|
|
||||||
|
def test_storage_backend_table_parser():
|
||||||
|
"""
|
||||||
|
Tests the "system storage_backend_list" table parser
|
||||||
|
|
||||||
|
Returns:None
|
||||||
|
"""
|
||||||
|
system_table_parser = SystemTableParser(storage_backend_list_ceph_output)
|
||||||
|
output_values = system_table_parser.get_output_values_list()
|
||||||
|
assert len(output_values) == 1
|
||||||
|
|
||||||
|
output = output_values[0]
|
||||||
|
assert output["uuid"] == "b3655f85-5e16-471e-b994-c9f910c53f00"
|
||||||
|
assert output["name"] == "ceph-store"
|
||||||
|
assert output["backend"] == "ceph"
|
||||||
|
assert output["state"] == "configured"
|
||||||
|
assert output["task"] == "None"
|
||||||
|
assert output["services"] == "None"
|
||||||
|
assert output["capabilities"] == "replication: 2min_replication: 1"
|
||||||
|
|
||||||
|
system_storage_backend_output = SystemStorageBackendOutput(storage_backend_list_ceph_output)
|
||||||
|
backend_object = system_storage_backend_output.get_system_storage_backend("ceph")
|
||||||
|
assert backend_object.get_uuid() == "b3655f85-5e16-471e-b994-c9f910c53f00"
|
||||||
|
assert backend_object.get_name() == "ceph-store"
|
||||||
|
assert backend_object.get_backend() == "ceph"
|
||||||
|
assert backend_object.get_state() == "configured"
|
||||||
|
assert backend_object.get_task() == "None"
|
||||||
|
assert backend_object.get_services() == "None"
|
||||||
|
assert backend_object.get_capabilities().get_replication() == 2
|
||||||
|
assert backend_object.get_capabilities().get_min_replication() == 1
|
||||||
Reference in New Issue
Block a user