Skip to content

Commit

Permalink
refactor(robot): generalize expand workload volume keyword
Browse files Browse the repository at this point in the history
longhorn/longhorn-6633

Signed-off-by: Chin-Ya Huang <[email protected]>
  • Loading branch information
c3y1huang committed Dec 9, 2024
1 parent 459aa23 commit 68edfba
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
4 changes: 0 additions & 4 deletions e2e/keywords/statefulset.resource
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ Scale up statefulset ${statefulset_id} to attach volume
${statefulset_name} = generate_name_with_suffix statefulset ${statefulset_id}
scale_statefulset_up ${statefulset_name}

Expand statefulset ${statefulset_id} volume by ${size} MiB
${statefulset_name} = generate_name_with_suffix statefulset ${statefulset_id}
expand_workload_claim_size_by_mib ${statefulset_name} ${size}

Write ${size} MB data to file ${file_name} in statefulset ${statefulset_id}
${statefulset_name} = generate_name_with_suffix statefulset ${statefulset_id}
write_workload_pod_random_data ${statefulset_name} ${size} ${file_name}
Expand Down
6 changes: 6 additions & 0 deletions e2e/keywords/workload.resource
Original file line number Diff line number Diff line change
Expand Up @@ -232,3 +232,9 @@ Check volume of ${workload_kind} ${workload_id} replica on node ${node_id} disk
${disk_uuid} = get_disk_uuid ${node_name} ${disk_name}
${replicas} = get_replicas volume_name=${volume_name} node_name=${node_name} disk_uuid=${disk_uuid}
Should Be True len(${replicas}) > 0

Expand ${workload_kind} ${workload_id} volume by ${size}
${workload_name} = generate_name_with_suffix ${workload_kind} ${workload_id}
${new_size} = convert_size_to_bytes ${size}

expand_workload_claim_size ${workload_name} ${new_size}
9 changes: 5 additions & 4 deletions e2e/libs/keywords/workload_keywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
from utility.constant import ANNOT_CHECKSUM
from utility.constant import ANNOT_EXPANDED_SIZE
from utility.constant import LABEL_LONGHORN_COMPONENT
from utility.utility import convert_size_to_bytes
from utility.utility import logging

from volume import Volume
from volume.constant import MEBIBYTE


class workload_keywords:
Expand Down Expand Up @@ -158,11 +158,12 @@ def wait_for_workload_volume_detached(self, workload_name):
logging(f'Waiting for {workload_name} volume {volume_name} to be detached')
self.volume.wait_for_volume_detached(volume_name)

def expand_workload_claim_size_by_mib(self, workload_name, size_in_mib, claim_index=0):
def expand_workload_claim_size(self, workload_name, size_in_byte, claim_index=0):
claim_name = get_workload_persistent_volume_claim_name(workload_name, index=claim_index)
size_in_byte = int(size_in_mib) * MEBIBYTE
current_size = self.persistentvolumeclaim.get(claim_name).spec.resources.requests['storage']
current_size_byte = convert_size_to_bytes(current_size)

logging(f'Expanding {workload_name} persistentvolumeclaim {claim_name} by {size_in_mib} MiB')
logging(f'Expanding {workload_name} persistentvolumeclaim {claim_name} from {current_size_byte} to {size_in_byte}')
self.persistentvolumeclaim.expand(claim_name, size_in_byte)

def wait_for_workload_claim_size_expanded(self, workload_name, claim_index=0):
Expand Down
15 changes: 15 additions & 0 deletions e2e/libs/utility/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,3 +338,18 @@ def get_name_suffix(*args):
if arg:
suffix += f"-{arg}"
return suffix


def convert_size_to_bytes(size):
size = size.replace(" ", "")

if size.endswith("GiB"):
return int(size[:-3]) * 1024 * 1024 * 1024

if size.endswith("MiB"):
return int(size[:-3]) * 1024 * 1024

if size.isdigit():
return int(size)

raise ValueError(f"Invalid size format: {size}")

0 comments on commit 68edfba

Please sign in to comment.