Skip to content

Global setting to allow/disallow users to force stop a vm#9569

Merged
yadvr merged 6 commits into
apache:mainfrom
abh1sar:stop-vm
Sep 5, 2024
Merged

Global setting to allow/disallow users to force stop a vm#9569
yadvr merged 6 commits into
apache:mainfrom
abh1sar:stop-vm

Conversation

@abh1sar

@abh1sar abh1sar commented Aug 22, 2024

Copy link
Copy Markdown
Contributor

Description

Fixes #6629

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • 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
  • test (unit or integration test code)

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • Major
  • Minor

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

Screenshot from 2024-08-22 15-27-42
Screenshot from 2024-08-22 15-27-57
Screenshot from 2024-08-22 15-33-36

How Has This Been Tested?

How did you try to break this feature and the system with this change?

@codecov

codecov Bot commented Aug 22, 2024

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 15.38462% with 11 lines in your changes missing coverage. Please review.

Project coverage is 15.57%. Comparing base (1e12a80) to head (1ccb94f).
Report is 60 commits behind head on main.

Files with missing lines Patch % Lines
.../src/main/java/com/cloud/vm/UserVmManagerImpl.java 16.66% 5 Missing ⚠️
.../cloudstack/api/response/CapabilitiesResponse.java 0.00% 3 Missing ⚠️
...in/java/com/cloud/server/ManagementServerImpl.java 0.00% 2 Missing ⚠️
...k/api/command/user/config/ListCapabilitiesCmd.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #9569      +/-   ##
============================================
+ Coverage     15.55%   15.57%   +0.02%     
- Complexity    12011    12056      +45     
============================================
  Files          5500     5506       +6     
  Lines        481889   482919    +1030     
  Branches      62240    61451     -789     
============================================
+ Hits          74966    75231     +265     
- Misses       398637   399376     +739     
- Partials       8286     8312      +26     
Flag Coverage Δ
uitests 4.17% <ø> (-0.01%) ⬇️
unittests 16.35% <15.38%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@vishesh92 vishesh92 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clgtm. didn't test.

@abh1sar

abh1sar commented Aug 22, 2024

Copy link
Copy Markdown
Contributor Author

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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

@DaanHoogland

Copy link
Copy Markdown
Contributor

@blueorangutan test

@blueorangutan

Copy link
Copy Markdown

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

@blueorangutan

Copy link
Copy Markdown

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

Test Result Time (s) Test File
test_01_isolate_network_FW_PF_default_routes_egress_true Failure 109.38 test_routers_network_ops.py

@shwstppr shwstppr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functionality looks okay, left some comments

@Param(description = "true if users can see all accounts within the same domain, false otherwise")
private boolean allowUserViewAllDomainAccounts;

@SerializedName("allowuserforcestopvm")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to define it in ApiConstants

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

response.setAllowUserExpungeRecoverVM((Boolean)capabilities.get("allowUserExpungeRecoverVM"));
response.setAllowUserExpungeRecoverVolume((Boolean)capabilities.get("allowUserExpungeRecoverVolume"));
response.setAllowUserViewAllDomainAccounts((Boolean)capabilities.get("allowUserViewAllDomainAccounts"));
response.setAllowUserForceStopVM((Boolean)capabilities.get("allowUserForceStopVM"));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use key from ApiConstants?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

capabilities.put("allowUserExpungeRecoverVM", allowUserExpungeRecoverVM);
capabilities.put("allowUserExpungeRecoverVolume", allowUserExpungeRecoverVolume);
capabilities.put("allowUserViewAllDomainAccounts", allowUserViewAllDomainAccounts);
capabilities.put("allowUserForceStopVM", allowUserForceStopVM);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as previous comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@abh1sar

abh1sar commented Aug 23, 2024

Copy link
Copy Markdown
Contributor Author

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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

@abh1sar

abh1sar commented Aug 23, 2024

Copy link
Copy Markdown
Contributor Author

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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

@DaanHoogland

Copy link
Copy Markdown
Contributor

@blueorangutan test

@blueorangutan

Copy link
Copy Markdown

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

@blueorangutan

Copy link
Copy Markdown

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

Test Result Time (s) Test File

Comment thread server/src/main/java/com/cloud/vm/UserVmManagerImpl.java Outdated

@sureshanaparti sureshanaparti left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor comment, changes lgtm

Co-authored-by: Suresh Kumar Anaparti <sureshkumar.anaparti@gmail.com>

@bernardodemarco bernardodemarco left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, manually tested in a local environment, here are the test descriptions.

Test Descriptions

I created two User accounts, u1 and u2. Then, I set the allow.user.force.stop.vm setting to true for the u1 account and to false for the u2 account.

Tests with u1 account

UI

I selected the option to stop a running VM and, as expected, the Force input field was rendered on the confirmation form.

image

CloudMonkey

I executed the stopVirtualMachine API, with the parameter forced set to true, and the virtual machine was stopped successfully.

Tests with u2 account

UI

I selected the option to stop a running VM and, as expected, the Force input field was not rendered on the confirmation form.

image

CloudMonkey

I executed the stopVirtualMachine API, with the parameter forced set to true, and received the following response:

(localcloud) 🐱 > stop virtualmachine id="de80cbfc-e736-413d-be78-113e093955de" forced="true"
{
  "account": "u2",
  "accountid": "80cc6bd6-6bc5-43d7-85b9-84557ef7501f",
  "cmd": "org.apache.cloudstack.api.command.user.vm.StopVMCmd",
  "completed": "2024-09-01T13:55:56+0000",
  "created": "2024-09-01T13:55:56+0000",
  "domainid": "6b5335fb-4b6f-11ef-87b4-cec422422af1",
  "domainpath": "ROOT",
  "jobid": "f47b1388-6ed5-4c6b-b6f8-9754fbae3863",
  "jobinstanceid": "de80cbfc-e736-413d-be78-113e093955de",
  "jobinstancetype": "VirtualMachine",
  "jobprocstatus": 0,
  "jobresult": {
    "errorcode": 530,
    "errortext": "Account does not have the permission to force stop the vm."
  },
  "jobresultcode": 530,
  "jobresulttype": "object",
  "jobstatus": 2,
  "userid": "852c7737-b9eb-479c-8613-e366e165b6e2"
}
🙈 Error: async API failed for job f47b1388-6ed5-4c6b-b6f8-9754fbae3863

As can be seen, the operation was not completed successfully, which is the expected behavior.

Comment thread server/src/main/java/com/cloud/vm/UserVmManagerImpl.java Outdated
@yadvr yadvr added this to the 4.20.0.0 milestone Sep 5, 2024
Co-authored-by: Bernardo De Marco Gonçalves <bernardomg2004@gmail.com>
@yadvr yadvr merged commit b7a2b04 into apache:main Sep 5, 2024
dhslove pushed a commit to ablecloud-team/ablestack-cloud that referenced this pull request Sep 6, 2024
…ache#9569)

Global setting to allow/disallow users to force stop a vm

Fixes apache#6629

Co-authored-by: Suresh Kumar Anaparti <sureshkumar.anaparti@gmail.com>
Co-authored-by: Rohit Yadav <rohityadav89@gmail.com>
Co-authored-by: Bernardo De Marco Gonçalves <bernardomg2004@gmail.com>
@abh1sar abh1sar deleted the stop-vm branch April 18, 2026 01:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a permission for force stopping a vm

8 participants