From a680283ac348d5438aef6acecfa59bf1f6e285af Mon Sep 17 00:00:00 2001 From: Chin-Ya Huang Date: Mon, 10 Jul 2023 16:49:02 +0800 Subject: [PATCH] test(support-bundle): should not timeout ref: 6256 Signed-off-by: Chin-Ya Huang --- manager/integration/deploy/test.yaml | 3 + .../integration/tests/test_support_bundle.py | 98 +++++++++++++++++++ 2 files changed, 101 insertions(+) diff --git a/manager/integration/deploy/test.yaml b/manager/integration/deploy/test.yaml index 69031b814d..1abcf9bdae 100644 --- a/manager/integration/deploy/test.yaml +++ b/manager/integration/deploy/test.yaml @@ -37,6 +37,9 @@ rules: - apiGroups: ["batch"] resources: ["cronjobs"] verbs: ["*"] +- apiGroups: ["longhorn.io"] + resources: ["supportbundles", "supportbundles/status"] + verbs: ["*"] --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding diff --git a/manager/integration/tests/test_support_bundle.py b/manager/integration/tests/test_support_bundle.py index be2cc1f7dc..1e5764cc11 100644 --- a/manager/integration/tests/test_support_bundle.py +++ b/manager/integration/tests/test_support_bundle.py @@ -1,7 +1,11 @@ import pytest + import os +import time import zipfile +from kubernetes.stream import stream + from tempfile import TemporaryDirectory from node import taint_nodes_exclude_self # NOQA @@ -15,11 +19,16 @@ from common import delete_and_wait_deployment from common import download_support_bundle from common import get_all_support_bundle_manager_deployments +from common import get_custom_object_api_client +from common import timeout from common import set_k8s_node_label from common import update_setting from common import wait_for_support_bundle_cleanup from common import wait_for_support_bundle_state +from common import LONGHORN_NAMESPACE +from common import RETRY_COUNTS +from common import RETRY_INTERVAL from common import SETTING_NODE_SELECTOR from common import SETTING_SUPPORT_BUNDLE_FAILED_LIMIT from common import SETTING_TAINT_TOLERATION @@ -303,3 +312,92 @@ def test_support_bundle_should_replace_existing_ready_support_bundle(client): # wait_for_support_bundle_cleanup(client) check_all_support_bundle_managers_deleted() + + +@pytest.mark.support_bundle # NOQA +def test_support_bundle_should_not_timeout(client, core_api): # NOQA + """ + Scenario: test support bundle should not timeout + + Issue: https://github.com/longhorn/longhorn/issues/6256 + + Given support bundle created + And support bundle state is (ReadyForDownload) + And replace support bundle zip file with a large file (5GB) + And support bundle file size is updated to the size of the large file + + When download support bundle + + Then support bundle should be downloaded successfully + And support bundle should be deleted + And support bundle manager should be deleted + """ + resp = create_support_bundle(client) + node_id = resp['id'] + support_bundle_name = resp['name'] + + wait_for_support_bundle_state( + "ReadyForDownload", node_id, support_bundle_name, client + ) + + for _ in range(RETRY_COUNTS): + time.sleep(RETRY_INTERVAL) + label = f"rancher/supportbundle={support_bundle_name}" + pods = core_api.list_pod_for_all_namespaces(label_selector=label, + watch=False) + if len(pods.items) == 1: + break + assert len(pods.items) == 1, \ + f'Expect 1 support bundle manager pod, got {len(pods.items)}' + + pod_name = pods.items[0].metadata.name + + bundle = "/tmp/mock-support-bundle" + cmd = [ + "bash", "-c", + f"bundle=`ls /tmp/support-bundle-kit/ | grep zip` &&\ + rm -f /tmp/support-bundle-kit/$bundle &&\ + dd if=/dev/urandom of={bundle} bs=1G count=5 > /dev/null 2>&1 &&\ + zip /tmp/support-bundle-kit/$bundle {bundle} > /dev/null 2>&1 &&\ + rm -f {bundle} &&\ + stat -c \"%s\" /tmp/support-bundle-kit/$bundle", + ] + with timeout(seconds=600, error_message='Timeout on executing command'): + zip_size = stream(core_api.connect_get_namespaced_pod_exec, + pod_name, LONGHORN_NAMESPACE, + command=cmd, stderr=True, stdin=False, stdout=True, + tty=False) + zip_size = zip_size.replace('\n', '') + + custom_obj_api = get_custom_object_api_client() + + # Define the resource details + group = "longhorn.io" + version = "v1beta2" + plural = "supportbundles" + + # Retrieve the current state of the SupportBundle + support_bundle = custom_obj_api.get_namespaced_custom_object( + group=group, + version=version, + namespace=LONGHORN_NAMESPACE, + plural=plural, + name=support_bundle_name + ) + + # Update the file size in the SupportBundle status + support_bundle["status"]["filesize"] = int(zip_size) + + # Update the SupportBundle with the modified status + custom_obj_api.replace_namespaced_custom_object_status( + group=group, + version=version, + namespace=LONGHORN_NAMESPACE, + plural=plural, + name=support_bundle_name, + body=support_bundle + ) + + download_support_bundle(node_id, support_bundle_name, client) + wait_for_support_bundle_cleanup(client) + check_all_support_bundle_managers_deleted()