Skip to content

Commit

Permalink
test case test_rwx_offline_expansion
Browse files Browse the repository at this point in the history
ref: 2484

Signed-off-by: Chris <[email protected]>
  • Loading branch information
chriscchien authored and David Ko committed Sep 18, 2023
1 parent e76fd5d commit 1e6f404
Showing 1 changed file with 65 additions and 4 deletions.
69 changes: 65 additions & 4 deletions manager/integration/tests/test_rwx.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
from common import wait_for_pod_phase
from common import core_api, statefulset, pvc, pod, client # NOQA
from common import RETRY_COUNTS, RETRY_INTERVAL
from common import EXPANDED_VOLUME_SIZE
from common import expand_and_wait_for_pvc, wait_for_volume_expansion
from common import wait_deployment_replica_ready, wait_for_volume_healthy
from backupstore import set_random_backupstore # NOQA
from multiprocessing import Pool

Expand Down Expand Up @@ -543,8 +546,7 @@ def test_rwx_onine_expansion(): # NOQA
pass


@pytest.mark.skip(reason="TODO")
def test_rwx_offline_expansion(): # NOQA
def test_rwx_offline_expansion(client, core_api, pvc, make_deployment_with_pvc): # NOQA
"""
Related issue :
https://github.com/longhorn/longhorn/issues/2181
Expand All @@ -560,7 +562,7 @@ def test_rwx_offline_expansion(): # NOQA
- Atach it to a workload (deployment) and write some data.
- Scale down the workload, wait volume detached
- Share manager pod will terminate automatically
- Expand the volume to 5 Gi, wait exoansion complete
- Expand the volume to 4 Gi, wait exoansion complete
When
- Scale up workload
Expand All @@ -572,4 +574,63 @@ def test_rwx_offline_expansion(): # NOQA
And
- 1.5 Gi of data is successfully written to the expanded volume
"""
pass
pvc_name = 'pvc-deployment-rwx-expand-test'
pvc['metadata']['name'] = pvc_name
pvc['spec']['storageClassName'] = 'longhorn'
pvc['spec']['accessModes'] = ['ReadWriteMany']
pvc['spec']['resources']['requests']['storage'] = str(1 * Gi)

core_api.create_namespaced_persistent_volume_claim(
body=pvc, namespace='default')

deployment = make_deployment_with_pvc(
'deployment-rwx-expand-test', pvc_name, replicas=1)
apps_api = get_apps_api_client()
create_and_wait_deployment(apps_api, deployment)

pv_name = get_volume_name(core_api, pvc_name)
deployment_label_selector = "name=" + \
deployment["metadata"]["labels"]["name"]

deployment_pod_list = \
core_api.list_namespaced_pod(namespace="default",
label_selector=deployment_label_selector)

pod_name = deployment_pod_list.items[0].metadata.name
test_data = generate_random_data(VOLUME_RWTEST_SIZE)
write_pod_volume_data(core_api, pod_name, test_data, filename='test')

deployment['spec']['replicas'] = 0
apps_api.patch_namespaced_deployment(body=deployment,
namespace='default',
name=deployment["metadata"]["name"])

wait_for_volume_detached(client, pv_name)
expand_and_wait_for_pvc(core_api, pvc, EXPANDED_VOLUME_SIZE*Gi)
wait_for_volume_expansion(client, pv_name)
wait_for_volume_detached(client, pv_name)

deployment['spec']['replicas'] = 1
apps_api.patch_namespaced_deployment(body=deployment,
namespace='default',
name=deployment["metadata"]["name"])
wait_deployment_replica_ready(apps_api, deployment["metadata"]["name"], 1)
wait_for_volume_healthy(client, pv_name)

deployment_pod_list = \
core_api.list_namespaced_pod(namespace="default",
label_selector=deployment_label_selector)
pod_name = deployment_pod_list.items[0].metadata.name

# check data written before expansion
resp = read_volume_data(core_api, pod_name, "test")
assert resp == test_data

data_size_in_mb = 1536
write_pod_volume_random_data(core_api, pod_name, "/data/test2",
data_size_in_mb)
command = 'stat -c \"%s\" /data/test2'
data_size_in_pod = exec_command_in_pod(core_api, command,
pod_name,
'default')
assert int(data_size_in_pod)/1024/1024 == data_size_in_mb

0 comments on commit 1e6f404

Please sign in to comment.