cloudstack icon indicating copy to clipboard operation
cloudstack copied to clipboard

Rollback of changes with errors during the VM assign

Open stephankruggg opened this issue 2 years ago • 30 comments

Description

When assigning a VM to another account (assignVirtualMachine API), if a network error happens during the process, no rollback is executed; thus, leaving the DB in an inconsistent state.

This PR fixes this by processing all steps to change the ownership of a VM inside the transaction. It also refactors code related to this procedure.

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?

In a local lab, I created a VM and an account of user type. I then attempted to assign the admin's VM to the user by using a network not accessible to the user.

Before applying the changes, an error was raised, but the VM was listed as belonging to the user.

After applying the changes, an error was raised, and the VM was listed as belonging to the admin - no changes occurred.

stephankruggg avatar Jan 05 '23 13:01 stephankruggg

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 4.26%. Comparing base (21af134) to head (5846f71). Report is 44 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main   #7061       +/-   ##
============================================
- Coverage     15.28%   4.26%   -11.02%     
============================================
  Files          5425     363     -5062     
  Lines        474138   29565   -444573     
  Branches      58984    5190    -53794     
============================================
- Hits          72486    1262    -71224     
+ Misses       393584   28160   -365424     
+ Partials       8068     143     -7925     
Flag Coverage Δ
uitests 4.26% <ø> (ø)
unittests ?

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.

codecov[bot] avatar Jan 05 '23 14:01 codecov[bot]

lots of refactoring. I am not sure if the code is good or not. Maybe others can check.

@stephankruggg can you point out the key point of your change ?

@weizhouapache, when assigning a VM to another account (assignVirtualMachine API), if a network error happens during the process, no rollback is executed; thus, leaving the DB in an inconsistent state. This PR fixes this by processing all steps to change the ownership of a VM inside the transaction.

The refactoring is intended to make the code more testable, readable, and easier to maintain.

stephankruggg avatar Jan 05 '23 15:01 stephankruggg

lots of refactoring. I am not sure if the code is good or not. Maybe others can check. @stephankruggg can you point out the key point of your change ?

@weizhouapache, when assigning a VM to another account (assignVirtualMachine API), if a network error happens during the process, no rollback is executed; thus, leaving the DB in an inconsistent state. This PR fixes this by processing all steps to change the ownership of a VM inside the transaction.

The refactoring is intended to make the code more testable, readable, and easier to maintain.

@stephankruggg thanks.

it seems the key block is

        Transaction.execute(new TransactionCallbackNoReturn() {
            @Override
            public void doInTransactionWithoutResult(TransactionStatus status) {
                executeStepsToChangeOwnershipOfVm(cmd, caller, oldAccount, newAccount, vm, offering, volumes, template, domainId);
            }
        });

weizhouapache avatar Jan 05 '23 15:01 weizhouapache

@blueorangutan package

rohityadavcloud avatar Jan 18 '23 05:01 rohityadavcloud

@rohityadavcloud a Jenkins job has been kicked to build packages. It will be bundled with SystemVM template(s). I'll keep you posted as I make progress.

blueorangutan avatar Jan 18 '23 05:01 blueorangutan

Packaging result: :heavy_check_mark: el7 :heavy_check_mark: el8 :heavy_check_mark: el9 :heavy_check_mark: debian :heavy_check_mark: suse15. SL-JID 5302

blueorangutan avatar Jan 18 '23 05:01 blueorangutan

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

github-actions[bot] avatar Feb 08 '23 14:02 github-actions[bot]

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

github-actions[bot] avatar Mar 23 '23 15:03 github-actions[bot]

@stephankruggg can you look at the conflicts? (cc @BryanMLima )

DaanHoogland avatar Oct 31 '23 14:10 DaanHoogland

@stephankruggg is anybody looking at this (or should we postpone)?

DaanHoogland avatar Nov 15 '23 15:11 DaanHoogland

@stephankruggg is anybody looking at this (or should we postpone)?

@GaOrtiga can you take at this one, please?

stephankruggg avatar Nov 15 '23 15:11 stephankruggg

Hi guys, sorry for the delay.

@stephankruggg is anybody looking at this (or should we postpone)?

@GaOrtiga can you take at this one, please?

Yes.

@stephankruggg is anybody looking at this (or should we postpone)?

I have fixed the conflicts and will run some tests in the next few days before pushing the changes.

GaOrtiga avatar Nov 15 '23 15:11 GaOrtiga

@blueorangutan package

kiranchavala avatar Nov 21 '23 09:11 kiranchavala

@kiranchavala 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 avatar Nov 21 '23 09:11 blueorangutan

Packaging result [SF]: :heavy_multiplication_x: el7 :heavy_multiplication_x: el8 :heavy_multiplication_x: el9 :heavy_multiplication_x: debian :heavy_multiplication_x: suse15. SL-JID 7815

blueorangutan avatar Nov 21 '23 10:11 blueorangutan

@GaOrtiga (cc @stephankruggg ) see https://github.com/apache/cloudstack/actions/runs/6932958288/job/18881597883?pr=7061#step:7:7641

duplicate import

DaanHoogland avatar Nov 21 '23 10:11 DaanHoogland

@blueorangutan package

shwstppr avatar Nov 25 '23 11:11 shwstppr

@shwstppr 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 avatar Nov 25 '23 11:11 blueorangutan

Packaging result [SF]: :heavy_multiplication_x: el7 :heavy_multiplication_x: el8 :heavy_multiplication_x: el9 :heavy_multiplication_x: debian :heavy_multiplication_x: suse15. SL-JID 7829

blueorangutan avatar Nov 25 '23 12:11 blueorangutan

@stephankruggg have a look at https://github.com/apache/cloudstack/actions/runs/6981605172/job/18999868361?pr=7061#step:7:7641

DaanHoogland avatar Nov 25 '23 17:11 DaanHoogland

@blueorangutan package

shwstppr avatar Dec 01 '23 10:12 shwstppr

@shwstppr 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 avatar Dec 01 '23 10:12 blueorangutan

Packaging result [SF]: :heavy_check_mark: el7 :heavy_check_mark: el8 :heavy_check_mark: el9 :heavy_check_mark: debian :heavy_check_mark: suse15. SL-JID 7885

blueorangutan avatar Dec 01 '23 12:12 blueorangutan

@blueorangutan test

DaanHoogland avatar Dec 01 '23 14:12 DaanHoogland

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

blueorangutan avatar Dec 01 '23 14:12 blueorangutan

[SF] Trillian test result (tid-8447) Environment: kvm-centos7 (x2), Advanced Networking with Mgmt server 7 Total time taken: 54089 seconds Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr7061-t8447-kvm-centos7.zip Smoke tests completed. 118 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_invalid_upgrade_kubernetes_cluster Failure 3612.14 test_kubernetes_clusters.py
test_02_upgrade_kubernetes_cluster Failure 3622.98 test_kubernetes_clusters.py
test_03_deploy_and_scale_kubernetes_cluster Failure 0.04 test_kubernetes_clusters.py
test_04_autoscale_kubernetes_cluster Failure 0.04 test_kubernetes_clusters.py
test_05_basic_lifecycle_kubernetes_cluster Failure 0.04 test_kubernetes_clusters.py
test_06_delete_kubernetes_cluster Failure 0.05 test_kubernetes_clusters.py
test_07_deploy_kubernetes_ha_cluster Failure 0.04 test_kubernetes_clusters.py
test_08_upgrade_kubernetes_ha_cluster Failure 0.05 test_kubernetes_clusters.py
test_09_delete_kubernetes_ha_cluster Failure 0.04 test_kubernetes_clusters.py
test_10_vpc_tier_kubernetes_cluster Failure 50.94 test_kubernetes_clusters.py
test_11_test_unmanaged_cluster_lifecycle Error 1.26 test_kubernetes_clusters.py
ContextSuite context=TestKubernetesCluster>:teardown Error 72.05 test_kubernetes_clusters.py

blueorangutan avatar Dec 02 '23 05:12 blueorangutan

@GaOrtiga what is the status on this

DaanHoogland avatar Dec 04 '23 07:12 DaanHoogland

@DaanHoogland I ran into some issues with the integration tests, manually doing what the tests do (for example assigning a VM to an account in another domain) works, but the tests fail. I think we should postpone this PR to a later release.

GaOrtiga avatar Dec 04 '23 12:12 GaOrtiga

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

github-actions[bot] avatar Dec 07 '23 07:12 github-actions[bot]