cloudstack
cloudstack copied to clipboard
Quota email configuration
Description
Currently, users have no control on whether they receive Quota emails or not. If the Quota plugin is enabled, they will receive all applicable emails.
Furthermore, there is currently no way to set the (min_balance
) configuration without adding credits to the account. That value acts as a threshold for the QUOTA_LOW email template. However, there should be a way to easily configure it.
To address the described problems, this PR creates a new API (quotaConfigureEmail
) which will has the following parameters: (accountid:String, emailTemplateName:String, enable:Boolean, minBalance:Integer
).
- Regarding the API parameters:
- (
accountid
) is required, since all configurations will only be in the accounts scope. - (
emailTemplateName
) is not required, unless the (enable
) parameter is informed. - (
enable
) is not required, unless the (emailTemplateName
) parameter is informed. - (
minBalance
) is not required. When informed, it will set the (minBalance
) attribute in the (quota_account
) table.
- (
- Regarding the API functionality:
- When the (
accountid, emailTemplateName, enable
) parameters are informed, the email referenced by (emailTemplateName
) will be enabled/disabled based on (enable
) for account referenced by (accountid
). - When the (
accountid, minBalance
) parameters are informed, the (min_balance
) of the account referenced by (accountid
) will be set. - While a email template is not configured for a given account using this API, the default behavior will be maintained, that is, the email template will be considered as enabled.
- When the (
Furthermore, a second API (quotaListEmailConfiguration
) was created, which has a single parameter: (accountid:String
).
- Regarding the API functionality:
- The API lists all the email template configurations for the given account.
To improve the user experience, the account-level setting quota.enable.emails
was also created, which defines whether or not Quota emails will be sent to the account. By default, the setting has the value true
. When the setting is enabled, it is possible to disable sending specific email types (QUOTA_EMPTY
, QUOTA_LOW
, QUOTA_STATEMENT
and QUOTA_UNLOCK_ACCOUNT
) to the account via the quotaConfigureEmail
API.
Types of changes
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
- [X] New feature (non-breaking change which adds functionality)
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] Enhancement (improves an existing feature and functionality)
- [ ] Cleanup (Code refactoring and cleanup, that may add test cases)
- [ ] build/CI
Feature/Enhancement Scale or Bug Severity
Feature/Enhancement Scale
- [ ] Major
- [X] Minor
How Has This Been Tested?
Testing the quotaConfigureEmail
API
No. | Test | Result | Expected result? |
---|---|---|---|
1 | Call the API passing accountid |
Exception thrown | yes |
2 | Call the API passing accountid and templatename |
Exception thrown | yes |
3 | Call the API passing accountid , templatename and enable for an account that does not have a Quota account |
Exception thrown | yes |
4 | Call the API passing accountid , templatename , enable and minbalance for an account that does not have a Quota account |
Exception thrown | yes |
5 | Call the API passing accountid , templatename and enable |
Configuration generated and persisted in the database | yes |
6 | Call the API passing accountid and minbalance |
minbalance updated |
yes |
7 | Call the API passing accountid , templatename , enable and minbalance |
Configuration generated and persisted in the database, and minbalance updated |
yes |
Testing the quotaListConfiguration
API
No. | Test | Result | Expected result? |
---|---|---|---|
1 | Call the API passing accountid of an account that does not have email settings |
Empty Response | yes |
2 | Call the API passing accountid of an account that has email settings |
Response with email settings | yes |
Feature tests:
- Without configuring the emails, I tested reaching all alert email thresholds, all emails were sent correctly.
- Enabling all emails, I tested reaching all alert email thresholds, all emails were sent correctly.
- Disabling all emails, I tested reaching all alert email thresholds, none of the emails were sent.
Codecov Report
Attention: Patch coverage is 42.00000%
with 116 lines
in your changes are missing coverage. Please review.
Project coverage is 31.12%. Comparing base (
e87c6cf
) to head (9200140
).
Additional details and impacted files
@@ Coverage Diff @@
## main #8307 +/- ##
============================================
+ Coverage 31.08% 31.12% +0.04%
- Complexity 33887 33953 +66
============================================
Files 5397 5402 +5
Lines 379499 379658 +159
Branches 55373 55381 +8
============================================
+ Hits 117955 118170 +215
+ Misses 245899 245825 -74
- Partials 15645 15663 +18
Flag | Coverage Δ | |
---|---|---|
simulator-marvin-tests | 24.74% <9.00%> (+0.07%) |
:arrow_up: |
uitests | 4.34% <ø> (ø) |
|
unit-tests | 16.88% <34.00%> (+<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.
This pull request has merge conflicts. Dear author, please fix the conflicts and sync your branch with the base branch.
This pull request has merge conflicts. Dear author, please fix the conflicts and sync your branch with the base branch.
This pull request has merge conflicts. Dear author, please fix the conflicts and sync your branch with the base branch.
@blueorangutan package
@JoaoJandre 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 8726
This pull request has merge conflicts. Dear author, please fix the conflicts and sync your branch with the base branch.
@GutoVeronezi @BryanMLima @winterhazel Could someone review this PR?
This pull request has merge conflicts. Dear author, please fix the conflicts and sync your branch with the base branch.
I tested the feature introduced in this PR. It seems to be working as intended.
First, I configured Quota to send e-mails. I also created an account with my e-mail, added 9 credits to it in order to enable Quota and configured its minimum balance to 10. To receive the e-mails at any time, I would set both cloud_usage.quota_account.
quota_alert_date
/quota_statement_date
to NULL
and execute quotaUpdate
.
-
I set
quota.enable.emails
totrue
for the account. -
I enabled all e-mails for the account through the API
quotaConfigureEmail
.API Response
(admin) 🐱 > quota configureemail enable=true accountid=0ee4c6d5-f3b0-479b-8a16-40a57f22525f templatename=QUOTA_EMPTY { "quotaconfigureemail": { "account": "0ee4c6d5-f3b0-479b-8a16-40a57f22525f", "enabled": true, "templatename": "QUOTA_EMPTY" } } (admin) 🐱 > quota configureemail enable=true accountid=0ee4c6d5-f3b0-479b-8a16-40a57f22525f templatename=QUOTA_LOW { "quotaconfigureemail": { "account": "0ee4c6d5-f3b0-479b-8a16-40a57f22525f", "enabled": true, "templatename": "QUOTA_LOW" } } (admin) 🐱 > quota configureemail enable=true accountid=0ee4c6d5-f3b0-479b-8a16-40a57f22525f templatename=QUOTA_STATEMENT { "quotaconfigureemail": { "account": "0ee4c6d5-f3b0-479b-8a16-40a57f22525f", "enabled": true, "templatename": "QUOTA_STATEMENT" } } (admin) 🐱 > quota configureemail enable=true accountid=0ee4c6d5-f3b0-479b-8a16-40a57f22525f templatename=QUOTA_UNLOCK_ACCOUNT { "quotaconfigureemail": { "account": "0ee4c6d5-f3b0-479b-8a16-40a57f22525f", "enabled": true, "templatename": "QUOTA_UNLOCK_ACCOUNT" } }
-
Using
quotaListEmailConfiguration
, I verified that the e-mails had been enabled for the account.API Response
(admin) 🐱 > quota listemailconfiguration accountid=0ee4c6d5-f3b0-479b-8a16-40a57f22525f { "count": 4, "quotaconfigureemail": [ { "account": "0ee4c6d5-f3b0-479b-8a16-40a57f22525f", "enabled": true, "minbalance": 10, "templatename": "QUOTA_LOW" }, { "account": "0ee4c6d5-f3b0-479b-8a16-40a57f22525f", "enabled": true, "minbalance": 10, "templatename": "QUOTA_EMPTY" }, { "account": "0ee4c6d5-f3b0-479b-8a16-40a57f22525f", "enabled": true, "minbalance": 10, "templatename": "QUOTA_UNLOCK_ACCOUNT" }, { "account": "0ee4c6d5-f3b0-479b-8a16-40a57f22525f", "enabled": true, "minbalance": 10, "templatename": "QUOTA_STATEMENT" } ] }
-
I executed
quotaUpdate
and verified that I receivedQUOTA_LOW
andQUOTA_STATEMENT
e-mails. -
I emptied the account's credits (by adding -9 credits to it) and executed
quotaUpdate
. I verified that I receivedQUOTA_EMPTY
andQUOTA_STATEMENT
e-mails. -
I disabled the
QUOTA_EMPTY
e-mail through the APIquotaConfigureEmail
.API Response
(admin) 🐱 > quota configureemail enable=false accountid=0ee4c6d5-f3b0-479b-8a16-40a57f22525f templatename=QUOTA_EMPTY { "quotaconfigureemail": { "account": "0ee4c6d5-f3b0-479b-8a16-40a57f22525f", "enabled": false, "templatename": "QUOTA_EMPTY" } }
-
Using
quotaListEmailConfiguration
, I verified thatQUOTA_EMPTY
had been disabled.API Response
(admin) 🐱 > quota listemailconfiguration accountid=0ee4c6d5-f3b0-479b-8a16-40a57f22525f { "count": 4, "quotaconfigureemail": [ { "account": "0ee4c6d5-f3b0-479b-8a16-40a57f22525f", "enabled": true, "minbalance": 10, "templatename": "QUOTA_LOW" }, { "account": "0ee4c6d5-f3b0-479b-8a16-40a57f22525f", "enabled": false, "minbalance": 10, "templatename": "QUOTA_EMPTY" }, { "account": "0ee4c6d5-f3b0-479b-8a16-40a57f22525f", "enabled": true, "minbalance": 10, "templatename": "QUOTA_UNLOCK_ACCOUNT" }, { "account": "0ee4c6d5-f3b0-479b-8a16-40a57f22525f", "enabled": true, "minbalance": 10, "templatename": "QUOTA_STATEMENT" } ] }
-
I executed
quotaUpdate
and verified that I only received theQUOTA_STATEMENT
e-mail. -
I set
quota.enable.emails
tofalse
for the account. Then, I executedquotaUpdate
and verified that I did not receive any e-mails.
Thank you for testing @winterhazel
This pull request has merge conflicts. Dear author, please fix the conflicts and sync your branch with the base branch.
This pull request has merge conflicts. Dear author, please fix the conflicts and sync your branch with the base branch.
@blueorangutan package
@JoaoJandre 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 8937
@DaanHoogland @rohityadavcloud @shwstppr could we run the CI on this one?
@blueorangutan test
@shwstppr a [SL] Trillian-Jenkins test job (centos7 mgmt + kvm-centos7) has been kicked to run smoke tests
[SF] Trillian test result (tid-9489) Environment: kvm-centos7 (x2), Advanced Networking with Mgmt server 7 Total time taken: 53759 seconds Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr8307-t9489-kvm-centos7.zip Smoke tests completed. 129 look OK, 0 have errors, 0 did not run Only failed and skipped tests results shown below:
Test | Result | Time (s) | Test File |
---|
Merging based on approvals, manual test results and CI results.