From 710154eef29874edf249e11c1aac32b251a20f5e Mon Sep 17 00:00:00 2001 From: James Lu Date: Thu, 5 Oct 2023 10:03:03 +0800 Subject: [PATCH] test: update a read-only setting Ref: 5989 Signed-off-by: James Lu --- manager/integration/tests/common.py | 7 +++--- manager/integration/tests/test_settings.py | 26 ++++++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/manager/integration/tests/common.py b/manager/integration/tests/common.py index a5a463331e..26e66ab507 100644 --- a/manager/integration/tests/common.py +++ b/manager/integration/tests/common.py @@ -159,6 +159,7 @@ SETTING_BACKUP_TARGET_CREDENTIAL_SECRET = "backup-target-credential-secret" SETTING_BACKUPSTORE_POLL_INTERVAL = "backupstore-poll-interval" SETTING_CREATE_DEFAULT_DISK_LABELED_NODES = "create-default-disk-labeled-nodes" +SETTING_CURRENT_LONGHORN_VERSION = "current-longhorn-version" SETTING_DEFAULT_DATA_LOCALITY = "default-data-locality" SETTING_DEFAULT_DATA_PATH = "default-data-path" SETTING_DEFAULT_LONGHORN_STATIC_SC = "default-longhorn-static-storage-class" @@ -5530,11 +5531,11 @@ def cleanup_all_support_bundles(client): Clean up all support bundles :param client: The Longhorn client to use in the request. """ - longhorn_version = client.by_id_setting('current-longhorn-version').value + lh_version = client.by_id_setting(SETTING_CURRENT_LONGHORN_VERSION).value version_doesnt_have_support_bundle_manager = ['v1.1', 'v1.2', 'v1.3'] - if any(_version in longhorn_version for + if any(_version in lh_version for _version in version_doesnt_have_support_bundle_manager): - print(f'{longhorn_version} doesn\'t have support bundle manager') + print(f'{lh_version} doesn\'t have support bundle manager') return support_bundles = client.list_support_bundle() diff --git a/manager/integration/tests/test_settings.py b/manager/integration/tests/test_settings.py index ce54a31b46..39a0fe0ca1 100644 --- a/manager/integration/tests/test_settings.py +++ b/manager/integration/tests/test_settings.py @@ -32,6 +32,7 @@ SETTING_DEFAULT_REPLICA_COUNT, SETTING_BACKUP_TARGET, SETTING_CONCURRENT_VOLUME_BACKUP_RESTORE, + SETTING_CURRENT_LONGHORN_VERSION, RETRY_COUNTS, RETRY_INTERVAL, RETRY_INTERVAL_LONG, update_setting, BACKING_IMAGE_QCOW2_URL, BACKING_IMAGE_NAME, create_backing_image_with_matching_url, BACKING_IMAGE_EXT4_SIZE, @@ -1241,3 +1242,28 @@ def test_setting_update_with_invalid_value_via_configmap(core_api, request): # ""]) cleanup_volume_by_name(client, vol_name) + +def test_setting_update_readonly(): # NOQA + """ + Test update read-only setting + + 1. Update read-only setting `current-longhorn-version` + 2. An exception is returned with substring `read-only` + 3. Update non-read-only setting `backup-target` and + it should be updated successfully + """ + client = get_longhorn_api_client() # NOQA + + setting = client.by_id_setting(SETTING_CURRENT_LONGHORN_VERSION) + assert setting.value != "" + + with pytest.raises(Exception) as e: + client.update(setting, value="v1.10.0-failed") + assert 'read-only' in str(e.value) + + bt_setting_value_str = "nfs://invalid/faked" + bt_setting = client.by_id_setting(SETTING_BACKUP_TARGET) + bt_setting = client.update(bt_setting, value=bt_setting_value_str) + assert bt_setting.value == bt_setting_value_str + bt_setting = client.update(bt_setting, value="") + assert bt_setting.value == ""