Skip to content

Fix issue with Assign VM operation #10834

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

Fix issue with Assign VM operation #10834

wants to merge 1 commit into from

Conversation

Pearl1594
Copy link
Contributor

@Pearl1594 Pearl1594 commented May 8, 2025

Description

This PR fixes: #10825
Caused by: #7061

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):

How Has This Been Tested?

~/cloudstack$ nosetests --with-xunit --xunit-file=results.xml --with-marvin --marvin-config=setup/dev/advanced.cfg -s -a tags=advanced --hypervisor=simulator test/integration/component/test_assign_vm.py 

==== Marvin Init Started ====

=== Marvin Parse Config Successful ===

=== Marvin Setting TestData Successful===

==== Log Folder Path: /tmp/MarvinLogs/May_08_2025_15_04_54_PRXZT8 All logs will be available here ====

=== Marvin Init Logging Successful===

==== Marvin Init Successful ====
=== TestName: test_01_move_across_different_domains | Status : SUCCESS ===

=== TestName: test_02_move_across_subdomains | Status : SUCCESS ===

=== TestName: test_03_move_from_domain_to_subdomain | Status : SUCCESS ===

=== TestName: test_04_move_from_domain_to_sub_of_subdomain | Status : SUCCESS ===

=== TestName: test_05_move_to_domain_from_sub_of_subdomain | Status : SUCCESS ===

=== TestName: test_06_move_to_domain_from_subdomain | Status : SUCCESS ===

=== TestName: test_07_move_across_subdomain | Status : SUCCESS ===

=== TestName: test_08_move_across_subdomain_network_create | Status : SUCCESS ===

=== TestName: test_09_move_across_subdomain | Status : SUCCESS ===

=== TestName: test_10_move_across_subdomain_vm_running | Status : SUCCESS ===

=== TestName: test_11_move_across_subdomain_vm_pfrule | Status : SUCCESS ===

=== TestName: test_12_move_across_subdomain_vm_volumes | Status : SUCCESS ===

=== TestName: test_13_move_across_subdomain_vm_snapshot | Status : SUCCESS ===

=== TestName: test_14_move_across_subdomain_vm_project | Status : SUCCESS ===

=== TestName: test_15_move_across_subdomain_account_limit | Status : SUCCESS ===

=== TestName: test_16_move_across_subdomain_volume_and_account_limit | Status : SUCCESS ===

=== Final results are now copied to: /tmp/MarvinLogs/test_assign_vm_ZSOBNZ ===

I also simulated a scenario where an exception occurs after the network is created in the new account, and confirmed that the network is properly cleaned up — thereby preserving atomicity.

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

Copy link

codecov bot commented May 8, 2025

Codecov Report

Attention: Patch coverage is 71.42857% with 2 lines in your changes missing coverage. Please review.

Project coverage is 16.13%. Comparing base (f6d0590) to head (23482e4).
Report is 4 commits behind head on 4.20.

Files with missing lines Patch % Lines
.../src/main/java/com/cloud/vm/UserVmManagerImpl.java 71.42% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##               4.20   #10834   +/-   ##
=========================================
  Coverage     16.13%   16.13%           
  Complexity    13220    13220           
=========================================
  Files          5651     5651           
  Lines        496740   496797   +57     
  Branches      60183    60190    +7     
=========================================
+ Hits          80148    80161   +13     
- Misses       407674   407712   +38     
- Partials       8918     8924    +6     
Flag Coverage Δ
uitests 4.00% <ø> (-0.01%) ⬇️
unittests 16.98% <71.42%> (+<0.01%) ⬆️

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.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

sonarqubecloud bot commented May 8, 2025

Copy link
Contributor

@shwstppr shwstppr left a comment

Choose a reason for hiding this comment

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

Somehow changes doesn't look right to me. @Pearl1594 could there be a better way to handle errors?

if (networkVOS.size() == 1) {
_networkDao.remove(networkVOS.get(0).getId());
}
_accountMgr.getActiveAccountByName(newAccount.getAccountName() + "-network", newAccount.getDomainId());
Copy link
Contributor

Choose a reason for hiding this comment

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

Why this? name won't be null with current code. Do we expect domainId to return null and then throw InvalidParameterValueException?

Copy link
Contributor Author

@Pearl1594 Pearl1594 May 8, 2025

Choose a reason for hiding this comment

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

that's by mistake

Comment on lines +7598 to +7601
List<NetworkVO> networkVOS = _networkDao.listByAccountIdNetworkName(newAccountId, newAccount.getAccountName() + "-network");
if (networkVOS.size() == 1) {
_networkDao.remove(networkVOS.get(0).getId());
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can network be in implemented state or something? Do we really want to mark it as removed directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not ready for review - stil working on a way to see if the network was created during the assignVM operation and only then remove it

@@ -7961,7 +7967,10 @@ protected void selectApplicableNetworkToCreateVm(Account caller, Account newAcco
NetworkVO defaultNetwork;
List<? extends Network> virtualNetworks = _networkModel.listNetworksForAccount(newAccount.getId(), zone.getId(), Network.GuestType.Isolated);
if (virtualNetworks.isEmpty()) {
defaultNetwork = createApplicableNetworkToCreateVm(caller, newAccount, zone, firstRequiredOffering);
try (TransactionLegacy txn = TransactionLegacy.open("CreateNetworkTxn")) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Transaction.execute() won't work here?

@Pearl1594 Pearl1594 closed this May 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants