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 6, 2024
1 parent 998bb9f commit 7a479ea
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
4 changes: 0 additions & 4 deletions e2e/keywords/statefulset.resource
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,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 @@ -213,3 +213,9 @@ Delete Longhorn ${workload_kind} ${workload_name} pod
${pod_name} = get_workload_pod_name ${workload_name} longhorn-system
Log ${pod_name}
delete_pod ${pod_name} longhorn-system

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}
8 changes: 5 additions & 3 deletions e2e/libs/keywords/workload_keywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
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
Expand Down Expand Up @@ -158,11 +159,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)

assert False, f"Invalid size format: {size}"

0 comments on commit 7a479ea

Please sign in to comment.