Skip to content

Commit c11e0b8

Browse files
committed
Fix build: use reflection for protected ConfigKey.valueOf() in test
- NASBackupProviderTest.overrideConfigValue() was calling configKey.valueOf() directly, but valueOf() has protected access. Use Method.setAccessible(true) to invoke it via reflection instead. - nasbackup.sh: rewrite mount check as `if mount ...; then` to prevent set -e from bypassing custom error handling.
1 parent 3d65f34 commit c11e0b8

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

plugins/backup/nas/src/test/java/org/apache/cloudstack/backup/NASBackupProviderTest.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,14 +357,19 @@ public void testGetVMHypervisorHostFallbackToZoneWideKVMHost() {
357357

358358
private void overrideConfigValue(final ConfigKey configKey, final Object value) {
359359
try {
360+
// Use reflection to invoke protected valueOf()
361+
java.lang.reflect.Method valueOfMethod = ConfigKey.class.getDeclaredMethod("valueOf", String.class);
362+
valueOfMethod.setAccessible(true);
363+
Object typedValue = value != null ? valueOfMethod.invoke(configKey, String.valueOf(value)) : null;
364+
360365
// Set _value for value() calls
361366
Field f = ConfigKey.class.getDeclaredField("_value");
362367
f.setAccessible(true);
363-
f.set(configKey, value != null ? configKey.valueOf((String) value) : null);
368+
f.set(configKey, typedValue);
364369

365370
// Also set _defaultValue via Spring's ReflectionTestUtils (handles final fields)
366371
ReflectionTestUtils.setField(configKey, "_defaultValue", String.valueOf(value));
367-
} catch (IllegalAccessException | NoSuchFieldException e) {
372+
} catch (Exception e) {
368373
Assert.fail(e.getMessage());
369374
}
370375
}

scripts/vm/hypervisor/kvm/nasbackup.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,7 @@ mount_operation() {
314314
if [ ${NAS_TYPE} == "cifs" ]; then
315315
MOUNT_OPTS="${MOUNT_OPTS},nobrl"
316316
fi
317-
mount -t ${NAS_TYPE} ${NAS_ADDRESS} ${mount_point} $([[ ! -z "${MOUNT_OPTS}" ]] && echo -o ${MOUNT_OPTS}) >> "$logFile" 2>&1
318-
if [ $? -eq 0 ]; then
317+
if mount -t ${NAS_TYPE} ${NAS_ADDRESS} ${mount_point} $([[ ! -z "${MOUNT_OPTS}" ]] && echo -o ${MOUNT_OPTS}) >> "$logFile" 2>&1; then
319318
log -ne "Successfully mounted ${NAS_TYPE} store"
320319
else
321320
echo "Failed to mount ${NAS_TYPE} store"

0 commit comments

Comments
 (0)