Refactor type and range validation in configuration update process
Description
The configuration update process mixes type validation with range validation in com.cloud.configuration.ConfigurationManagerImpl#validateConfigurationValue. To improve this process, this PR splits these validations into two methods (validateValueType and validateValueRange) and cleans up the code.
Furthermore, this PR also fixes an issue that allows non-numeric values to be inserted into Double configurations, such as zone.virtualnetwork.ipv6subnet.capacity.notificationthreshold.
Types of changes
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
- [ ] New feature (non-breaking change which adds functionality)
- [X] Bug fix (non-breaking change which fixes an issue)
- [ ] Enhancement (improves an existing feature and functionality)
- [X] Cleanup (Code refactoring and cleanup, that may add test cases)
Feature/Enhancement Scale or Bug Severity
Bug Severity
- [ ] BLOCKER
- [ ] Critical
- [ ] Major
- [X] Minor
- [ ] Trivial
How Has This Been Tested?
I manually verified the behavior of trying to update configurations of the following types, and compared them with the previous version to ensure the result was expected:
String-quota.currency.symbolandalert.email.addresses(that is, one that does not havenullas a valid value and another that does);Boolean-admin.is.allowed.to.deploy.anywhere;Integer-storage.cleanup.interval. (the validations for this type also apply toShortandLong);Float-cpu.overprovisioning.factor(also applies toDouble).
| Number | Test | Result | Expected result (Y/N)? |
|---|---|---|---|
| 1 | Value "null" in a String that does not have null as a valid value |
The value is updated in the database, but the default value is used | Y |
| 2 | Value "1" in a String that does not have null as a valid value |
Success | Y |
| 3 | Value "1.1" in a String that does not have null as a valid value |
Success | Y |
| 4 | Value "test" in a String that does not have null as a valid value |
Success | Y |
| 5 | Value "null" in a String that has null as a valid value |
Success | Y |
| 6 | Value "1" in a String that has null as a valid value |
Success | Y |
| 7 | Value "1.1" in a String that has null as a valid value |
Success | Y |
| 8 | Value "test" in a String that has null as a valid value |
Success | Y |
| 9 | Value "null" in a Boolean |
Exception | Y |
| 10 | Value "1" in a Boolean |
Exception | Y |
| 11 | Value "1.1" in a Boolean |
Exception | Y |
| 12 | Value "test" in a Boolean |
Exception | Y |
| 13 | Value "true" in a Boolean |
Success | Y |
| 14 | Value "false" in a Boolean |
Success | Y |
| 15 | Value "fALse" in a Boolean |
Exception | Y |
| 16 | Value "null" in an Integer |
Exception | Y |
| 17 | Value "1" in an Integer |
Success | Y |
| 18 | Value "1.1" in an Integer |
Exception | Y |
| 19 | Value "test" in an Integer |
Exception | Y |
| 20 | Value "null" in a Float |
Exception | Y |
| 21 | Value "1" in a Float |
Success | Y |
| 22 | Value "1.1" in a Float |
Success | Y |
| 23 | Value "test" in a Float |
Exception | Y |
@blueorangutan package
@winterhazel a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.
Packaging result [SF]: ✔️ el7 ✔️ el8 ✔️ el9 ✔️ debian ✔️ suse15. SL-JID 9670
Codecov Report
Attention: Patch coverage is 72.28916% with 23 lines in your changes missing coverage. Please review.
Project coverage is 15.58%. Comparing base (
b155e3d) to head (ef851d8). Report is 23 commits behind head on main.
| Files with missing lines | Patch % | Lines |
|---|---|---|
| .../cloud/configuration/ConfigurationManagerImpl.java | 72.28% | 13 Missing and 10 partials :warning: |
Additional details and impacted files
@@ Coverage Diff @@
## main #9107 +/- ##
============================================
+ Coverage 15.57% 15.58% +0.01%
- Complexity 12051 12075 +24
============================================
Files 5505 5505
Lines 482738 482725 -13
Branches 61341 62781 +1440
============================================
+ Hits 75202 75251 +49
+ Misses 399227 399166 -61
+ Partials 8309 8308 -1
| Flag | Coverage Δ | |
|---|---|---|
| uitests | 4.17% <ø> (ø) |
|
| unittests | 16.37% <72.28%> (+0.01%) |
:arrow_up: |
Flags with carried forward coverage won't be shown. Click here to find out more.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
This pull request has merge conflicts. Dear author, please fix the conflicts and sync your branch with the base branch.
@blueorangutan package
@winterhazel a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.
Packaging result [SF]: ✔️ el7 ✔️ el8 ✔️ el9 ✔️ debian ✔️ suse15. SL-JID 10169
This pull request has merge conflicts. Dear author, please fix the conflicts and sync your branch with the base branch.
@blueorangutan package
@winterhazel a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.
Packaging result [SF]: ✖️ el7 ✖️ el8 ✖️ el9 ✖️ debian ✖️ suse15. SL-JID 10226
@blueorangutan package
@winterhazel a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.
Packaging result [SF]: ✔️ el7 ✔️ el8 ✔️ el9 ✖️ debian ✔️ suse15. SL-JID 10228
@blueorangutan package
@winterhazel a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.
Packaging result [SF]: ✔️ el7 ✔️ el8 ✔️ el9 ✔️ debian ✔️ suse15. SL-JID 10471
@blueorangutan package
@DaanHoogland a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.
Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ debian ✔️ suse15. SL-JID 10616
@blueorangutan test
@DaanHoogland a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests
[SF] Trillian Build Failed (tid-11061)
Hey @winterhazel
I did some testing, overall it looks good, but I've found one case that I think we should address in this PR.
| Number | Config | Value | Result |
|---|---|---|---|
| 1 | storage.cleanup.interval | oasij | Error |
| 2 | storage.cleanup.interval | . | Error |
| 3 | storage.cleanup.interval | ( | Error |
| 4 | storage.cleanup.interval | 102938120381209381203981239128 | Error |
| 5 | storage.cleanup.interval | Error | |
| 6 | storage.cleanup.interval | "" | Error |
| 7 | storage.cleanup.interval | 86400 | Ok |
| 8 | cpu.overprovisioning.factor | a | Error |
| 9 | cpu.overprovisioning.factor | ^ | Error |
| 10 | cpu.overprovisioning.factor | 1.1.1 | Error |
| 11 | cpu.overprovisioning.factor | 10928091283012830123810293 | OK |
| 12 | cpu.overprovisioning.factor | 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 | OK, but this should not be |
| 13 | admin.is.allowed.to.deploy.anywhere | 1 | Error |
| 14 | admin.is.allowed.to.deploy.anywhere | 0 | Error |
| 15 | admin.is.allowed.to.deploy.anywhere | a | Error |
| 16 | admin.is.allowed.to.deploy.anywhere | FALSE | Error |
| 17 | admin.is.allowed.to.deploy.anywhere | TRUE | Error |
| 18 | admin.is.allowed.to.deploy.anywhere | true | OK |
| 19 | admin.is.allowed.to.deploy.anywhere | false | OK |
Test 12 was sucessful, but the number informed is bigger than the maximum value of Floats and Doubles. Double.parseDouble() returns Infinity if the number being parsed would overflow. We should not allow this config value, we should return an error, like what is done in test 4.
Thanks for testing @JoaoJandre. I addressed the issue you pointed out.
@blueorangutan package
@winterhazel a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.
Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ debian ✔️ suse15. SL-JID 10764
@blueorangutan test