Skip to content

Conversation

abh1sar
Copy link
Collaborator

@abh1sar abh1sar commented Sep 2, 2025

Description

In continuation of #10140 , this PR adds the functionality that a new Instance can be created on a different Zone from which the backup was taken.
Doc PR: apache/cloudstack-documentation#556

  • Supported backup Providers are NAS and Dummy.
  • The two zones have to be on the same CloudStack Installation
  • The backup repository still needs to be added only for the Zone where backup will be taken.
  • A new parameter DRaaS Enabled should be checked while creating the backup repository if it is to be used for creating instance in other zones.
    (The operator should ensure that the backup repository is accessible in other the Zones as well.)
  • Added updateBackupRepository api with parameters name, address, mountopts and draasenabled.

Other changes done:

  1. Throw relevant errors to the end user. i.e, if backup repository is not accessible or the backup files are not present or corrupted.
    Added a timeout to mount operation so that restore fails early if backup repository is not accessible. Current behaviour is that mount will block indefinitely until libvirt times out the command after 1 hour.

  2. Changes to decrease the RTO: Earlier, the new Instance had to be started (to create volumes), stopped, restored and started again. The start-stop cycle takes a long time. The whole process took around 200s on my local env with 15 GB of volume size.
    I have added a new param VirtualMachineProfile.Param.ReturnAfterVolumePrepare which creates the volume but doesn't start the VM in orchestrateStart. So one Stop and one Start is avoided during the Instance creation. The whole process finished within 60s with this change.

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 2025-09-02 16-06-21 Screenshot from 2025-09-04 09-24-18

How Has This Been Tested?

  1. Error thrown when tmp directory was not present in the kvm host
Screenshot from 2025-09-04 08-43-46
  1. Error thrown when the repository was not accessible and mount failed
Screenshot from 2025-09-04 08-44-55
  1. Error thrown when backup file was not present
Screenshot from 2025-09-04 08-54-44
  1. Error thrown when the backup file was not a valid qcow2 disk
Screenshot from 2025-09-04 08-53-27

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

Copy link

codecov bot commented Sep 2, 2025

Codecov Report

❌ Patch coverage is 49.40239% with 127 lines in your changes missing coverage. Please review.
✅ Project coverage is 17.39%. Comparing base (3d6ec29) to head (0df7f8d).

Files with missing lines Patch % Lines
...r/backup/repository/UpdateBackupRepositoryCmd.java 0.00% 35 Missing ⚠️
...rg/apache/cloudstack/backup/NASBackupProvider.java 62.16% 12 Missing and 2 partials ⚠️
...rg/apache/cloudstack/backup/BackupManagerImpl.java 53.57% 12 Missing and 1 partial ⚠️
...n/java/com/cloud/vm/VirtualMachineManagerImpl.java 0.00% 9 Missing ⚠️
...g/apache/cloudstack/backup/BackupRepositoryVO.java 10.00% 9 Missing ⚠️
...ce/wrapper/LibvirtRestoreBackupCommandWrapper.java 82.00% 5 Missing and 4 partials ⚠️
.../src/main/java/com/cloud/vm/UserVmManagerImpl.java 63.15% 3 Missing and 4 partials ⚠️
...udstack/api/response/BackupRepositoryResponse.java 0.00% 6 Missing ⚠️
...apache/cloudstack/backup/RestoreBackupCommand.java 0.00% 6 Missing ⚠️
...che/cloudstack/backup/NetworkerBackupProvider.java 0.00% 5 Missing ⚠️
... and 5 more
Additional details and impacted files
@@             Coverage Diff              @@
##               main   #11560      +/-   ##
============================================
+ Coverage     17.36%   17.39%   +0.02%     
- Complexity    15237    15277      +40     
============================================
  Files          5888     5889       +1     
  Lines        525741   525906     +165     
  Branches      64164    64186      +22     
============================================
+ Hits          91274    91458     +184     
+ Misses       424167   424140      -27     
- Partials      10300    10308       +8     
Flag Coverage Δ
uitests 3.63% <ø> (-0.01%) ⬇️
unittests 18.43% <49.40%> (+0.03%) ⬆️

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

github-actions bot commented Sep 4, 2025

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

@abh1sar abh1sar changed the title Create Instance from backup on another Zone Create Instance from backup on another Zone (DRaaS use case) Sep 4, 2025
} else {
clusterId = getClusterIdFromRootVolume(vm);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fyi - hostId won't be set for create Instance from Backup. But we can get the clusterId from the root volume which is already created.

mount += " -o " + mountOptions;
}

int exitValue = Script.runSimpleBashScriptForExitValue(mount, mountTimeout, false);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fiy - runSimpleBashScript doesn't return any exception. just a return value. So no need to keep it inside try-catch. So, checking the return value instead.

} catch (Exception e) {
throw new CloudRuntimeException(String.format("Failed to unmount backup directory: %s", backupDirectory), e);
String umountCmd = String.format(UMOUNT_COMMAND, backupDirectory);
int exitValue = Script.runSimpleBashScriptForExitValue(umountCmd);
Copy link
Collaborator Author

@abh1sar abh1sar Sep 4, 2025

Choose a reason for hiding this comment

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

fyi - same here. runSimpleBashScript doesn't throw any exception.

String error_msg = String.format("Failed to create Instance [%s] from backup [%s] due to: %s.", vm.getInstanceName(), backupDetailsInMessage, result.second());
logger.error(error_msg);
processRestoreBackupToVMFailure(vm, backup, eventId);
throw new CloudRuntimeException(error_msg);
Copy link
Collaborator Author

@abh1sar abh1sar Sep 4, 2025

Choose a reason for hiding this comment

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

fyi - this is done to pass on the error passed by the provider.

Copy link
Contributor

@harikrishna-patnala harikrishna-patnala left a comment

Choose a reason for hiding this comment

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

overall looking good, can you please clarify me with few questions I've raised @abh1sar thank you

@harikrishna-patnala
Copy link
Contributor

@abh1sar also can you please check the failures in simulator CI run

@abh1sar
Copy link
Collaborator Author

abh1sar commented Sep 9, 2025

@abh1sar also can you please check the failures in simulator CI run

Thanks @harikrishna-patnala. I have fixed the issue and addressed other comments.

Copy link
Contributor

@harikrishna-patnala harikrishna-patnala left a comment

Choose a reason for hiding this comment

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

code LGTM

@harikrishna-patnala
Copy link
Contributor

@blueorangutan package

1 similar comment
@abh1sar
Copy link
Collaborator Author

abh1sar commented Sep 9, 2025

@blueorangutan package

@blueorangutan
Copy link

@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

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

@abh1sar
Copy link
Collaborator Author

abh1sar commented Sep 10, 2025

@blueorangutan test

@blueorangutan
Copy link

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

@blueorangutan
Copy link

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

Test Result Time (s) Test File

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

3 participants