diff --git a/manager/integration/tests/common.py b/manager/integration/tests/common.py index 28503ae13e..c7cc9d7343 100644 --- a/manager/integration/tests/common.py +++ b/manager/integration/tests/common.py @@ -161,6 +161,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" @@ -5643,11 +5644,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 1f025b2fae..9f022b9683 100644 --- a/manager/integration/tests/test_settings.py +++ b/manager/integration/tests/test_settings.py @@ -8,7 +8,7 @@ from common import ( # NOQA get_longhorn_api_client, get_self_host_id, - get_core_api_client, get_apps_api_client, + get_core_api_client, get_apps_api_client, get_custom_object_api_client, create_and_check_volume, cleanup_volume, wait_for_volume_healthy, wait_for_volume_detached, write_volume_random_data, check_volume_data, @@ -33,6 +33,7 @@ SETTING_BACKUP_TARGET, SETTING_CONCURRENT_VOLUME_BACKUP_RESTORE, SETTING_V1_DATA_ENGINE, + 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, @@ -1293,3 +1294,93 @@ def finalizer(): # Step 6 volume.attach(hostId=get_self_host_id()) volume = wait_for_volume_healthy(client, volume_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 + """ + custom_obj_api = get_custom_object_api_client() + + # Define the resource details + group = "longhorn.io" + version = "v1beta2" + plural = "settings" + + # Get the Setting content + setting = custom_obj_api.get_namespaced_custom_object( + group=group, + version=version, + namespace=LONGHORN_NAMESPACE, + plural=plural, + name=SETTING_CURRENT_LONGHORN_VERSION + ) + assert setting["value"] != "" + setting_value = setting["value"] + + # Update a Read-Only Setting with the modified value + setting["value"] = "v1.10.0-failed" + with pytest.raises(Exception) as e: + custom_obj_api.patch_namespaced_custom_object( + group=group, + version=version, + namespace=LONGHORN_NAMESPACE, + plural=plural, + name=SETTING_CURRENT_LONGHORN_VERSION, + body=setting + ) + assert 'read-only' in str(e.value) + + setting = custom_obj_api.get_namespaced_custom_object( + group=group, + version=version, + namespace=LONGHORN_NAMESPACE, + plural=plural, + name=SETTING_CURRENT_LONGHORN_VERSION + ) + assert setting["value"] != "" and setting["value"] == setting_value + + # Update a common Setting with the modified value + bt_setting = custom_obj_api.get_namespaced_custom_object( + group=group, + version=version, + namespace=LONGHORN_NAMESPACE, + plural=plural, + name=SETTING_BACKUP_TARGET + ) + + bt_fake_url = "nfs://invalid/faked" + bt_setting["value"] = bt_fake_url + # Update the Setting with the modified value + custom_obj_api.patch_namespaced_custom_object( + group=group, + version=version, + namespace=LONGHORN_NAMESPACE, + plural=plural, + name=SETTING_BACKUP_TARGET, + body=bt_setting + ) + + bt_setting = custom_obj_api.get_namespaced_custom_object( + group=group, + version=version, + namespace=LONGHORN_NAMESPACE, + plural=plural, + name=SETTING_BACKUP_TARGET + ) + assert bt_setting["value"] == bt_fake_url + + bt_setting["value"] = "" + custom_obj_api.patch_namespaced_custom_object( + group=group, + version=version, + namespace=LONGHORN_NAMESPACE, + plural=plural, + name=SETTING_BACKUP_TARGET, + body=bt_setting + )