From e245da8337246189549789fa1abeede0af6a781d Mon Sep 17 00:00:00 2001 From: yangchiu Date: Mon, 23 Oct 2023 07:11:22 +0000 Subject: [PATCH] Update testing docs Signed-off-by: yangchiu --- integration/backupstore.html | 93 ++++++++++++++++++++++++++++++++++++ integration/test_basic.html | 87 ++++++++++++++++++++++++++++++--- 2 files changed, 173 insertions(+), 7 deletions(-) diff --git a/integration/backupstore.html b/integration/backupstore.html index a304d0eeeb..413ff15345 100644 --- a/integration/backupstore.html +++ b/integration/backupstore.html @@ -51,6 +51,7 @@

Module tests.backupstore

from common import get_backupstore_poll_interval from common import get_backupstores from common import system_backups_cleanup +from common import get_custom_object_api_client BACKUPSTORE_BV_PREFIX = "/backupstore/volumes/" BACKUPSTORE_LOCK_DURATION = 150 @@ -60,6 +61,14 @@

Module tests.backupstore

BACKUPSTORE = get_backupstores() +@pytest.fixture +def backupstore_invalid(client): + set_backupstore_invalid(client) + yield + reset_backupstore_setting(client) + backup_cleanup() + + @pytest.fixture def backupstore_s3(client): set_backupstore_s3(client) @@ -103,6 +112,13 @@

Module tests.backupstore

client.update(backup_store_poll_interval, value="300") +def set_backupstore_invalid(client): + poll_interval = get_backupstore_poll_interval() + set_backupstore_url(client, "nfs://notexist:/opt/backupstore") + set_backupstore_credential_secret(client, "") + set_backupstore_poll_interval(client, poll_interval) + + def set_backupstore_s3(client): backupstores = get_backupstore_url() poll_interval = get_backupstore_poll_interval() @@ -166,6 +182,22 @@

Module tests.backupstore

subprocess.check_output(cmd) +def backup_cleanup(): + # Use k8s api to delete all backup especially backup in error state + # Because backup in error state does not have backup volume + api = get_custom_object_api_client() + backups = api.list_namespaced_custom_object("longhorn.io", + "v1beta2", + "longhorn-system", + "backups") + for backup in backups['items']: + api.delete_namespaced_custom_object("longhorn.io", + "v1beta2", + "longhorn-system", + "backups", + backup['metadata']['name']) + + def backupstore_cleanup(client): backup_volumes = client.list_backup_volume() @@ -711,6 +743,31 @@

Module tests.backupstore

Functions

+
+def backup_cleanup() +
+
+
+
+ +Expand source code + +
def backup_cleanup():
+    # Use k8s api to delete all backup especially backup in error state
+    # Because backup in error state does not have backup volume
+    api = get_custom_object_api_client()
+    backups = api.list_namespaced_custom_object("longhorn.io",
+                                                "v1beta2",
+                                                "longhorn-system",
+                                                "backups")
+    for backup in backups['items']:
+        api.delete_namespaced_custom_object("longhorn.io",
+                                            "v1beta2",
+                                            "longhorn-system",
+                                            "backups",
+                                            backup['metadata']['name'])
+
+
def backup_volume_path(volume_name)
@@ -1072,6 +1129,23 @@

Functions

raise NotImplementedError +
+def backupstore_invalid(client) +
+
+
+
+ +Expand source code + +
@pytest.fixture
+def backupstore_invalid(client):
+    set_backupstore_invalid(client)
+    yield
+    reset_backupstore_setting(client)
+    backup_cleanup()
+
+
def backupstore_nfs(client)
@@ -1745,6 +1819,22 @@

Functions

assert backup_target_credential_setting.value == credential_secret +
+def set_backupstore_invalid(client) +
+
+
+
+ +Expand source code + +
def set_backupstore_invalid(client):
+    poll_interval = get_backupstore_poll_interval()
+    set_backupstore_url(client, "nfs://notexist:/opt/backupstore")
+    set_backupstore_credential_secret(client, "")
+    set_backupstore_poll_interval(client, poll_interval)
+
+
def set_backupstore_nfs(client)
@@ -1880,6 +1970,7 @@

Index

  • Functions

      +
    • backup_cleanup
    • backup_volume_path
    • backupstore_cleanup
    • backupstore_corrupt_backup_cfg_file
    • @@ -1897,6 +1988,7 @@

      Index

    • backupstore_get_backup_volume_prefix
    • backupstore_get_secret
    • backupstore_get_volume_cfg_file_path
    • +
    • backupstore_invalid
    • backupstore_nfs
    • backupstore_s3
    • backupstore_wait_for_lock_expiration
    • @@ -1930,6 +2022,7 @@

      Index

    • nfs_write_backup_cfg_file
    • reset_backupstore_setting
    • set_backupstore_credential_secret
    • +
    • set_backupstore_invalid
    • set_backupstore_nfs
    • set_backupstore_poll_interval
    • set_backupstore_s3
    • diff --git a/integration/test_basic.html b/integration/test_basic.html index 379ab2db4f..66ee6076dc 100644 --- a/integration/test_basic.html +++ b/integration/test_basic.html @@ -126,6 +126,8 @@

      Module tests.test_basic

      from common import BACKUP_COMPRESSION_METHOD_LZ4 from common import BACKUP_COMPRESSION_METHOD_GZIP from common import BACKUP_COMPRESSION_METHOD_NONE +from common import create_and_wait_deployment +from common import get_custom_object_api_client from backupstore import backupstore_delete_volume_cfg_file from backupstore import backupstore_cleanup @@ -139,6 +141,7 @@

      Module tests.test_basic

      from backupstore import set_backupstore_url, set_backupstore_credential_secret, set_backupstore_poll_interval # NOQA from backupstore import reset_backupstore_setting # NOQA from backupstore import set_backupstore_s3, backupstore_get_secret # NOQA +from backupstore import backupstore_invalid # NOQA from kubernetes import client as k8sclient @@ -5529,8 +5532,14 @@

      Module tests.test_basic

      wait_for_volume_delete(client, test_volume_name) -@pytest.mark.skip(reason="TODO") -def test_backuptarget_invalid(): # NOQA +def test_backuptarget_invalid(apps_api, # NOQA + client, # NOQA + core_api, # NOQA + backupstore_invalid, # NOQA + make_deployment_with_pvc, # NOQA + pvc_name, # NOQA + request, # NOQA + volume_name): # NOQA """ Related issue : https://github.com/longhorn/longhorn/issues/1249 @@ -5550,7 +5559,36 @@

      Module tests.test_basic

      Then - Backup will be failed and the backup state is Error. """ - pass + volume = create_and_check_volume(client, volume_name) + pvc_name = volume_name + "-pvc" + create_pv_for_volume(client, core_api, volume, volume_name) + create_pvc_for_volume(client, core_api, volume, pvc_name) + + deployment_name = volume_name + "-dep" + deployment = make_deployment_with_pvc(deployment_name, pvc_name) + create_and_wait_deployment(apps_api, deployment) + + pod_names = common.get_deployment_pod_names(core_api, deployment) + write_pod_volume_random_data(core_api, pod_names[0], "/data/test", + DATA_SIZE_IN_MB_1) + + volume = client.by_id_volume(volume_name) + snap = create_snapshot(client, volume_name) + volume.snapshotBackup(name=snap.name) + + for i in range(RETRY_COMMAND_COUNT): + api = get_custom_object_api_client() + backups = api.list_namespaced_custom_object("longhorn.io", + "v1beta2", + "longhorn-system", + "backups") + + if backups["items"][0]["status"]["state"] != "": + break + time.sleep(RETRY_INTERVAL) + + assert backups["items"][0]["spec"]["snapshotName"] == snap.name + assert backups["items"][0]["status"]["state"] == "Error" @pytest.mark.volume_backup_restore # NOQA @@ -8584,7 +8622,7 @@

      Functions

      -def test_backuptarget_invalid() +def test_backuptarget_invalid(apps_api, client, core_api, backupstore_invalid, make_deployment_with_pvc, pvc_name, request, volume_name)

      Related issue : @@ -8603,8 +8641,14 @@

      Functions

      Expand source code -
      @pytest.mark.skip(reason="TODO")
      -def test_backuptarget_invalid(): # NOQA
      +
      def test_backuptarget_invalid(apps_api, # NOQA
      +                              client, # NOQA
      +                              core_api, # NOQA
      +                              backupstore_invalid, # NOQA
      +                              make_deployment_with_pvc, # NOQA
      +                              pvc_name, # NOQA
      +                              request, # NOQA
      +                              volume_name): # NOQA
           """
           Related issue :
           https://github.com/longhorn/longhorn/issues/1249
      @@ -8624,7 +8668,36 @@ 

      Functions

      Then - Backup will be failed and the backup state is Error. """ - pass
      + volume = create_and_check_volume(client, volume_name) + pvc_name = volume_name + "-pvc" + create_pv_for_volume(client, core_api, volume, volume_name) + create_pvc_for_volume(client, core_api, volume, pvc_name) + + deployment_name = volume_name + "-dep" + deployment = make_deployment_with_pvc(deployment_name, pvc_name) + create_and_wait_deployment(apps_api, deployment) + + pod_names = common.get_deployment_pod_names(core_api, deployment) + write_pod_volume_random_data(core_api, pod_names[0], "/data/test", + DATA_SIZE_IN_MB_1) + + volume = client.by_id_volume(volume_name) + snap = create_snapshot(client, volume_name) + volume.snapshotBackup(name=snap.name) + + for i in range(RETRY_COMMAND_COUNT): + api = get_custom_object_api_client() + backups = api.list_namespaced_custom_object("longhorn.io", + "v1beta2", + "longhorn-system", + "backups") + + if backups["items"][0]["status"]["state"] != "": + break + time.sleep(RETRY_INTERVAL) + + assert backups["items"][0]["spec"]["snapshotName"] == snap.name + assert backups["items"][0]["status"]["state"] == "Error"