Skip to content

Commit

Permalink
refactor(robot): improve keyword readability for volume expansion
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 4ab6850 commit 43a1a09
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 10 deletions.
8 changes: 7 additions & 1 deletion e2e/keywords/workload.resource
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,18 @@ Check volume of ${workload_kind} ${workload_id} replica on node ${node_id} disk
${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}
Expand ${workload_kind} ${workload_id} volume to ${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}

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

expand_workload_claim_size_with_additional_bytes ${workload_name} ${new_size}

Expand ${workload_kind} ${workload_id} volume more than storage maximum size should fail
${workload_name} = generate_name_with_suffix ${workload_kind} ${workload_id}
${volume_name} = get_workload_volume_name ${workload_name}
Expand Down
8 changes: 8 additions & 0 deletions e2e/libs/keywords/workload_keywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,14 @@ def expand_workload_claim_size(self, workload_name, size_in_byte, claim_index=0,
logging(f'Expanding {workload_name} persistentvolumeclaim {claim_name} from {current_size_byte} to {size_in_byte}')
self.persistentvolumeclaim.expand(claim_name, size_in_byte, skip_retry=skip_retry)

def expand_workload_claim_size_with_additional_bytes(self, workload_name, size_in_byte, claim_index=0, skip_retry=False):
claim_name = get_workload_persistent_volume_claim_name(workload_name, index=claim_index)
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} current size {current_size_byte} with additional {size_in_byte}')
self.persistentvolumeclaim.expand_with_additional_bytes(claim_name, size_in_byte, skip_retry=skip_retry)

def wait_for_workload_claim_size_expanded(self, workload_name, claim_index=0):
claim_name = get_workload_persistent_volume_claim_name(workload_name, index=claim_index)
expanded_size = self.persistentvolumeclaim.get_annotation_value(claim_name, ANNOT_EXPANDED_SIZE)
Expand Down
2 changes: 1 addition & 1 deletion e2e/libs/persistentvolumeclaim/crd.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def get_volume_name(self, claim_name, claim_namespace="default"):
def expand(self, claim_name, size, namespace="default", skip_retry=False):
retry_count = 1 if skip_retry else self.retry_count
for i in range(retry_count):
logging(f"Trying to expand pvc {claim_name} to size {size} ... ({i})")
logging(f"Trying to expand PVC {claim_name} to size {size} ... ({i})")
try:
self.core_v1_api.patch_namespaced_persistent_volume_claim(
name=claim_name,
Expand Down
5 changes: 4 additions & 1 deletion e2e/libs/persistentvolumeclaim/persistentvolumeclaim.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,13 @@ def get_volume_name(self, claim_name):
return self.claim.get_volume_name(claim_name)

def expand(self, claim_name, size_in_byte, skip_retry=False):
expanded_size = self.claim.expand(claim_name, size_in_byte, skip_retry=skip_retry)
self.set_annotation(claim_name, ANNOT_EXPANDED_SIZE, str(expanded_size))

def expand_with_additional_bytes(self, claim_name, size_in_byte, skip_retry=False):
pvc = self.claim.get(claim_name)
current_size = int(pvc.spec.resources.requests['storage'])

target_size = current_size + size_in_byte
logging(f"Expanding PVC {claim_name} from {current_size} to {target_size}")
expanded_size = self.claim.expand(claim_name, target_size, skip_retry=skip_retry)
self.set_annotation(claim_name, ANNOT_EXPANDED_SIZE, str(expanded_size))
4 changes: 2 additions & 2 deletions e2e/tests/negative/stress_cpu.robot
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Stress Volume Node CPU When Volume Is Online Expanding
FOR ${i} IN RANGE ${LOOP_COUNT}
And Stress CPU of volume nodes

When Expand statefulset 0 volume by 100 MiB
When Expand statefulset 0 volume with additional 100 MiB
Then Wait for statefulset 0 volume size expanded

And Check statefulset 0 data in file 0.txt is intact
Expand All @@ -64,7 +64,7 @@ Stress Volume Node CPU When Volume Is Offline Expanding
And Scale down statefulset 0 to detach volume
And Stress CPU of all worker nodes

When Expand statefulset 0 volume by 100 MiB
When Expand statefulset 0 volume with additional 100 MiB

Then Wait for statefulset 0 volume size expanded
And Wait for statefulset 0 volume detached
Expand Down
4 changes: 2 additions & 2 deletions e2e/tests/negative/stress_filesystem.robot
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Stress Volume Node Filesystem When Volume Is Online Expanding
And Stress filesystem of statefulset 0 volume node

FOR ${i} IN RANGE ${LOOP_COUNT}
When Expand statefulset 0 volume by 100 MiB
When Expand statefulset 0 volume with additional 100 MiB
Then Wait for statefulset 0 volume size expanded

And Check statefulset 0 data in file data.txt is intact
Expand All @@ -63,7 +63,7 @@ Stress Volume Node Filesystem When Volume Is Offline Expanding
FOR ${i} IN RANGE ${LOOP_COUNT}
And Scale down statefulset 0 to detach volume

When Expand statefulset 0 volume by 100 MiB
When Expand statefulset 0 volume with additional 100 MiB
Then Wait for statefulset 0 volume size expanded
And Wait for statefulset 0 volume detached
And Scale up statefulset 0 to attach volume
Expand Down
4 changes: 2 additions & 2 deletions e2e/tests/negative/stress_memory.robot
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Stress Volume Node Memory When Volume Is Online Expanding
FOR ${i} IN RANGE ${LOOP_COUNT}
And Stress memory of volume nodes

When Expand statefulset 0 volume by 100 MiB
When Expand statefulset 0 volume with additional 100 MiB

Then Wait for statefulset 0 volume size expanded
And Check statefulset 0 data in file 0.txt is intact
Expand All @@ -65,7 +65,7 @@ Stress Volume Node Memory When Volume Is Offline Expanding
And Scale down statefulset 0 to detach volume
And Stress memory of all worker nodes

When Expand statefulset 0 volume by 100 MiB
When Expand statefulset 0 volume with additional 100 MiB

Then Wait for statefulset 0 volume size expanded
And Wait for statefulset 0 volume detached
Expand Down
2 changes: 1 addition & 1 deletion e2e/tests/regression/test_persistentvolumeclaim.robot
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Test persistentvolumeclaim expand more than storage maximum size should fail
And Assert persistentvolumeclaim 0 requested size remains 2GiB for at least 5 seconds
And Check deployment 0 data in file data.txt is intact

When Expand deployment 0 volume by 1 GiB
When Expand deployment 0 volume to 3 GiB
Then Assert persistentvolumeclaim 0 requested size remains 3GiB for at least 5 seconds
And Assert volume size of deployment 0 remains 3GiB for at least 5 seconds
And Check deployment 0 data in file data.txt is intact
Expand Down

0 comments on commit 43a1a09

Please sign in to comment.