apache / cloudstack

Apache CloudStack is an opensource Infrastructure as a Service (IaaS) cloud computing platform
https://cloudstack.apache.org/
Apache License 2.0
2.1k stars 1.11k forks source link

API to validate Quota activation rule #9605

Open hsato03 opened 2 months ago

hsato03 commented 2 months ago

Description

When entering an activation rule during the creation and editing of Quota tariffs, the defined rule is not validated. This way, errors are only identified while processing the tariff.

Because of this, the quotaValidateActivationRule API was created, which informs whether the activation rule is valid or not. Also, the activation rule field was added when creating and editing the tariff via UI.

API parameters

Parameter Description Required
activationrule The activation rule that will be validated. Yes
quotaresourcetype tariff usage type to validate the variables used in the script. Yes

Example

🐱 > quota validateactivationrule activationrule="if (account.name == 'admin') { 0 } else { 300 }" usagetype=6
{
  "validactivationrule": {
    "activationrule": "if (account.name == 'admin') { 0 } else { 300 }",
    "isvalid": true,
    "message": "The script has no syntax errors and all variables are compatible with the given usage type.",
    "quotatype": "VOLUME"
  }
}

Types of changes

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

Bug Severity

Screenshots (if appropriate):

invalid-activation-rule

valid-activation-rule

How Has This Been Tested?

N° Test Valid activation rule
1 Activation rule with valid JS code and with variables compatible with the given usage type Yes
2 Activation rule with valid JS code and with variables that are not compatible with the given usage type No
3 Activation rule with invalid JS code No
hsato03 commented 2 months ago

@blueorangutan package

blueorangutan commented 2 months ago

@hsato03 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.

codecov[bot] commented 2 months ago

Codecov Report

Attention: Patch coverage is 78.29787% with 51 lines in your changes missing coverage. Please review.

Project coverage is 15.81%. Comparing base (04c428c) to head (83ad4d1). Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
.../cloudstack/jsinterpreter/JsInterpreterHelper.java 89.51% 10 Missing and 3 partials :warning:
...ck/api/command/QuotaValidateActivationRuleCmd.java 33.33% 12 Missing :warning:
.../response/QuotaValidateActivationRuleResponse.java 62.96% 9 Missing and 1 partial :warning:
...g/apache/cloudstack/quota/constant/QuotaTypes.java 0.00% 9 Missing :warning:
...ctivationrule/presetvariables/PresetVariables.java 0.00% 6 Missing :warning:
.../org/apache/cloudstack/quota/QuotaServiceImpl.java 0.00% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #9605 +/- ## ============================================ + Coverage 15.78% 15.81% +0.02% - Complexity 12551 12597 +46 ============================================ Files 5625 5628 +3 Lines 491958 492225 +267 Branches 63091 61373 -1718 ============================================ + Hits 77663 77847 +184 - Misses 405836 405916 +80 - Partials 8459 8462 +3 ``` | [Flag](https://app.codecov.io/gh/apache/cloudstack/pull/9605/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | | |---|---|---| | [uitests](https://app.codecov.io/gh/apache/cloudstack/pull/9605/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `4.03% <ø> (-0.01%)` | :arrow_down: | | [unittests](https://app.codecov.io/gh/apache/cloudstack/pull/9605/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `16.63% <78.29%> (+0.03%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

blueorangutan commented 2 months ago

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ debian ✔️ suse15. SL-JID 10872

github-actions[bot] commented 2 months ago

This pull request has merge conflicts. Dear author, please fix the conflicts and sync your branch with the base branch.

BryanMLima commented 1 month ago

@hsato03, the build is failing due to the logger variable in the VmwareHelper.java class, it should be fixed by #9714.

hsato03 commented 1 month ago

@blueorangutan package

blueorangutan commented 1 month ago

@hsato03 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.

blueorangutan commented 1 month ago

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ debian ✔️ suse15. SL-JID 11224

DaanHoogland commented 1 month ago

@blueorangutan test

blueorangutan commented 1 month ago

@DaanHoogland a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests

blueorangutan commented 1 month ago

[SF] Trillian test result (tid-11578) Environment: kvm-ol8 (x2), Advanced Networking with Mgmt server ol8 Total time taken: 69038 seconds Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr9605-t11578-kvm-ol8.zip Smoke tests completed. 134 look OK, 1 have errors, 6 did not run Only failed and skipped tests results shown below:

Test Result Time (s) Test File
ContextSuite context=TestISOUsage>:setup Error 0.00 test_usage.py
all_test_vpc_router_nics Skipped --- test_vpc_router_nics.py
all_test_vpc_vpn Skipped --- test_vpc_vpn.py
all_test_webhook_delivery Skipped --- test_webhook_delivery.py
all_test_webhook_lifecycle Skipped --- test_webhook_lifecycle.py
all_test_host_maintenance Skipped --- test_host_maintenance.py
all_test_hostha_kvm Skipped --- test_hostha_kvm.py
hsato03 commented 1 month ago

@DaanHoogland the test error logs don't seem to be related to the PR.

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/nose/suite.py", line 210, in run
    self.setUp()
  File "/usr/local/lib/python3.6/site-packages/nose/suite.py", line 293, in setUp
    self.setupContext(ancestor)
  File "/usr/local/lib/python3.6/site-packages/nose/suite.py", line 316, in setupContext
    try_run(context, names)
  File "/usr/local/lib/python3.6/site-packages/nose/util.py", line 471, in try_run
    return func()
  File "/marvin/tests/smoke/test_usage.py", line 1025, in setUpClass
    cls.iso.id
Exception: ISO download failed exception: Failed to download ISO: 2785331c-21e7-47d5-91d5-ffb46b2dbe32

Could you run the smoke tests again?

DaanHoogland commented 1 month ago

@blueorangutan package

blueorangutan commented 1 month ago

@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.

blueorangutan commented 1 month ago

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ debian ✔️ suse15. SL-JID 11280

DaanHoogland commented 1 month ago

@blueorangutan test

blueorangutan commented 1 month ago

@DaanHoogland a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests

blueorangutan commented 1 month ago

[SF] Trillian test result (tid-11617) Environment: kvm-ol8 (x2), Advanced Networking with Mgmt server ol8 Total time taken: 59990 seconds Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr9605-t11617-kvm-ol8.zip Smoke tests completed. 139 look OK, 0 have errors, 2 did not run Only failed and skipped tests results shown below:

Test Result Time (s) Test File
all_test_vm_strict_host_tags Skipped --- test_vm_strict_host_tags.py
all_test_vnf_templates Skipped --- test_vnf_templates.py