Reject local backup creation test case

This commit introduces a test to reject local backup
creation due to lack of space in the subcloud.

Change-Id: Id2b311d12d5359086dbc1f7c09d24c362030eaca
Signed-off-by: Gustavo Pereira <gustavo.lyrapereira@windriver.com>
This commit is contained in:
Gustavo Pereira
2025-09-01 15:50:47 -03:00
parent 6b92d7118e
commit dc440c42b3
3 changed files with 98 additions and 3 deletions

View File

@@ -102,8 +102,8 @@ class DcManagerSubcloudBackupKeywords(BaseKeyword):
self,
con_ssh: SSHConnection,
subcloud: Optional[str],
check_interval: int = 3,
timeout: int = 10,
check_interval: int = 30,
timeout: int = 120,
) -> None:
"""
Waits for backup operation to fail
@@ -112,7 +112,7 @@ class DcManagerSubcloudBackupKeywords(BaseKeyword):
con_ssh (SSHConnection): SSH connection to execute the command (central_ssh or subcloud_ssh).
subcloud (Optional[str]): The name of the subcloud to check.
check_interval (int): Time interval (in seconds) to check for file creation. Defaults to 30.
timeout (int): Maximum time (in seconds) to wait for file creation. Defaults to 600.
timeout (int): Maximum time (in seconds) to wait for file creation. Defaults to 120.
Returns:
None:

View File

@@ -1,8 +1,10 @@
import time
import math
from framework.exceptions.keyword_exception import KeywordException
from framework.logging.automation_logger import get_logger
from framework.ssh.ssh_connection import SSHConnection
from framework.validation.validation import validate_greater_than, validate_equals
from keywords.base_keyword import BaseKeyword
@@ -332,3 +334,24 @@ class FileKeywords(BaseKeyword):
dest_file (str): The destination file path.
"""
self.ssh_connection.send(f"cp {src_file} {dest_file}")
def create_file_to_fill_disk_space(self, dest_dir: str = "/home/sysadmin"):
"""Creates a file with the available space of the desired directory.
Args:
dest_dir (str): Directory where the file is created. Default to home dir.
Returns:
path_to_file (str): Created file path.
"""
available_space = self.ssh_connection.send(f"echo $(($(stat -f --format=\"%a*%S\" {dest_dir})))| awk '{{print $1 / (1024*1024*1024) }}'")[0].strip("\n")
rounded_size = math.ceil(float(available_space))
file_size_to_be_created = math.trunc(1023 * float(rounded_size))
get_logger().log_info(f"Creating file 'test' with size {file_size_to_be_created}.")
self.ssh_connection.send(f"dd if=/dev/zero of=giant_test_file bs=1M count={file_size_to_be_created}")
remaining_space = self.ssh_connection.send(f"echo $(($(stat -f --format=\"%a*%S\" {dest_dir})))| awk '{{print $1 / (1024*1024*1024) }}'")[0].strip("\n")
remaining_space = math.trunc(float(remaining_space))
validate_equals(remaining_space, 0, "Validate that the remaining space on local is 0.")
path_to_file = f"{dest_dir}/giant_test_file"
return path_to_file

View File

@@ -0,0 +1,72 @@
from pytest import mark
from config.configuration_manager import ConfigurationManager
from config.lab.objects.lab_type_enum import LabTypeEnum
from framework.logging.automation_logger import get_logger
from keywords.cloud_platform.dcmanager.dcmanager_subcloud_backup_keywords import DcManagerSubcloudBackupKeywords
from keywords.cloud_platform.dcmanager.dcmanager_subcloud_list_keywords import DcManagerSubcloudListKeywords
from keywords.cloud_platform.health.health_keywords import HealthKeywords
from keywords.cloud_platform.ssh.lab_connection_keywords import LabConnectionKeywords
from keywords.files.file_keywords import FileKeywords
def backup_create_failure_local(subcloud_name: str):
"""Function to run backup operation for local back up.
Args:
subcloud_name (str): subcloud name to back up.
"""
central_ssh = LabConnectionKeywords().get_active_controller_ssh()
lab_config = ConfigurationManager.get_lab_config().get_subcloud(subcloud_name)
subcloud_password = lab_config.get_admin_credentials().get_password()
dc_manager_backup = DcManagerSubcloudBackupKeywords(central_ssh)
# Create a subcloud backup and verify the subcloud backup fails.
get_logger().log_info(f"Attempt creation of {subcloud_name} backup on local.")
dc_manager_backup.create_subcloud_backup_expect_fail(subcloud_password, central_ssh, subcloud=subcloud_name, local_only=True)
def teardown_local(subcloud_name: str, created_file_path: str):
"""Teardown function for local backup.
Args:
subcloud_name (str): subcloud name
created_file_path (str): Created file path.
"""
central_ssh = LabConnectionKeywords().get_active_controller_ssh()
subcloud_ssh = LabConnectionKeywords().get_subcloud_ssh(subcloud_name)
get_logger().log_info("Removing test files")
FileKeywords(central_ssh).delete_folder_with_sudo("subcloud_backup.yaml")
FileKeywords(subcloud_ssh).delete_folder_with_sudo(f"{subcloud_name}_platform_backup_*.tgz")
FileKeywords(subcloud_ssh).delete_file(created_file_path)
@mark.p0
@mark.subcloud_lab_is_simplex
def test_verify_backup_space_failure(request):
"""Forced failure of a subcloud backup due to lack of space on local storage.
Test Steps:
- Attempt subcloud backup with no space left on local storage.
"""
central_ssh = LabConnectionKeywords().get_active_controller_ssh()
dcm_sc_list_kw = DcManagerSubcloudListKeywords(central_ssh)
subcloud = dcm_sc_list_kw.get_dcmanager_subcloud_list().get_healthy_subcloud_by_type(LabTypeEnum.SIMPLEX.value)
subcloud_name = subcloud.get_name()
# get subcloud ssh
subcloud_ssh = LabConnectionKeywords().get_subcloud_ssh(subcloud_name)
# Prechecks Before Back-Up:
get_logger().log_info(f"Performing pre-checks on {subcloud_name}")
obj_health = HealthKeywords(subcloud_ssh)
obj_health.validate_healty_cluster() # Checks alarms, pods, app health
created_file_path = FileKeywords(subcloud_ssh).create_file_to_fill_disk_space("/home/sysadmin")
def teardown():
teardown_local(subcloud.get_name(), created_file_path)
request.addfinalizer(teardown)
backup_create_failure_local(subcloud_name)