From 60b24e4f23aed823e0cb4fefab5d34c44fcfc0c6 Mon Sep 17 00:00:00 2001 From: Chin-Ya Huang Date: Thu, 5 Dec 2024 18:00:22 +0800 Subject: [PATCH] refactor(robot): add storage_size for pvc creation longhorn/longhorn-6633 Signed-off-by: Chin-Ya Huang --- e2e/keywords/persistentvolumeclaim.resource | 3 ++- e2e/libs/keywords/persistentvolumeclaim_keywords.py | 4 ++-- e2e/libs/persistentvolumeclaim/persistentvolumeclaim.py | 8 +++++++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/e2e/keywords/persistentvolumeclaim.resource b/e2e/keywords/persistentvolumeclaim.resource index 1ad2318cf5..73d5b25e65 100644 --- a/e2e/keywords/persistentvolumeclaim.resource +++ b/e2e/keywords/persistentvolumeclaim.resource @@ -8,8 +8,9 @@ Library ../libs/keywords/volume_keywords.py *** Keywords *** Create persistentvolumeclaim ${claim_id} using ${volume_type} volume + [Arguments] &{config} ${claim_name} = generate_name_with_suffix claim ${claim_id} - create_persistentvolumeclaim ${claim_name} ${volume_type} + create_persistentvolumeclaim ${claim_name} ${volume_type} &{config} Create persistentvolumeclaim ${claim_id} using ${volume_type} volume with ${sc_name} storageclass ${claim_name} = generate_name_with_suffix claim ${claim_id} diff --git a/e2e/libs/keywords/persistentvolumeclaim_keywords.py b/e2e/libs/keywords/persistentvolumeclaim_keywords.py index 0a49fe9fec..912950251b 100644 --- a/e2e/libs/keywords/persistentvolumeclaim_keywords.py +++ b/e2e/libs/keywords/persistentvolumeclaim_keywords.py @@ -20,9 +20,9 @@ def cleanup_persistentvolumeclaims(self): for claim in claims.items: self.delete_persistentvolumeclaim(claim.metadata.name) - def create_persistentvolumeclaim(self, name, volume_type="RWO", sc_name="longhorn"): + def create_persistentvolumeclaim(self, name, volume_type="RWO", sc_name="longhorn", storage_size="3Gi"): logging(f'Creating {volume_type} persistentvolumeclaim {name} with {sc_name} storageclass') - return self.claim.create(name, volume_type, sc_name) + return self.claim.create(name, volume_type, sc_name, storage_size) def delete_persistentvolumeclaim(self, name): logging(f'Deleting persistentvolumeclaim {name}') diff --git a/e2e/libs/persistentvolumeclaim/persistentvolumeclaim.py b/e2e/libs/persistentvolumeclaim/persistentvolumeclaim.py index 513ff3efe1..5822770c25 100644 --- a/e2e/libs/persistentvolumeclaim/persistentvolumeclaim.py +++ b/e2e/libs/persistentvolumeclaim/persistentvolumeclaim.py @@ -11,6 +11,7 @@ from utility.constant import ANNOT_EXPANDED_SIZE from utility.constant import LABEL_TEST from utility.constant import LABEL_TEST_VALUE +from utility.utility import convert_size_to_bytes from utility.utility import get_retry_count_and_interval from utility.utility import logging @@ -23,7 +24,9 @@ def __init__(self): if self._strategy == LonghornOperationStrategy.CRD: self.claim = CRD() - def create(self, name, volume_type, sc_name): + def create(self, name, volume_type, sc_name, storage_size="3GiB"): + storage_size_bytes = convert_size_to_bytes(storage_size) + filepath = "./templates/workload/pvc.yaml" with open(filepath, 'r') as f: namespace = 'default' @@ -38,6 +41,9 @@ def create(self, name, volume_type, sc_name): # correct storageclass name manifest_dict['spec']['storageClassName'] = sc_name + # correct storage request + manifest_dict['spec']['resources']['requests']['storage'] = storage_size_bytes + # correct access mode` if volume_type == 'RWX': manifest_dict['spec']['accessModes'][0] = 'ReadWriteMany'