Skip to content

Conversation

@sureshanaparti
Copy link
Contributor

@sureshanaparti sureshanaparti commented Nov 13, 2025

Description

This PR includes the following deployment plan fixes for VM with last host, and last host in maintenance.

  • Consider last host when it is not in maintenance
  • Continue deployment with other hosts when user requests for last host consideration and last host doesn't exists or in maintenance

Fixes #12045

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?

Tested with 4 x KVM hosts on a single cluster. Able to put a host in maintenance when 2 hosts are already in maintenance. VMs choose the available host for migration, and VMs are not stopped.

All Hosts are Up =>

mysql> SELECT id, uuid, name, status, resource_state FROM cloud.host WHERE type = 'Routing' AND removed IS NULL;
+----+--------------------------------------+------------------------------------------+--------+----------------+
| id | uuid                                 | name                                     | status | resource_state |
+----+--------------------------------------+------------------------------------------+--------+----------------+
|  1 | dfa467a0-fadf-4cfb-ad36-cdbfa57f0e17 | ref-trl-10139-k-Mr8-suresh-anaparti-kvm1 | Up     | Enabled        |
|  2 | d0463494-995c-463a-9d4b-72eb37dca9be | ref-trl-10139-k-Mr8-suresh-anaparti-kvm2 | Up     | Enabled        |
|  3 | 69054cd3-296e-4040-a3e9-7889274fde63 | ref-trl-10139-k-Mr8-suresh-anaparti-kvm3 | Up     | Enabled        |
|  4 | cd369b58-72a1-46f1-b5ac-158c2717776e | ref-trl-10139-k-Mr8-suresh-anaparti-kvm4 | Up     | Enabled        |
+----+--------------------------------------+------------------------------------------+--------+----------------+
4 rows in set (0.00 sec)

mysql> SELECT id, uuid, name, instance_name, host_id, last_host_id, state, power_state FROM cloud.vm_instance WHERE type = 'User' AND removed IS NULL;
+----+--------------------------------------+----------+---------------+---------+--------------+---------+-------------+
| id | uuid                                 | name     | instance_name | host_id | last_host_id | state   | power_state |
+----+--------------------------------------+----------+---------------+---------+--------------+---------+-------------+
|  4 | a5ec3d7d-aca5-4c20-b682-55f5ebacc8e3 | testvm01 | i-2-4-VM      |       1 |            1 | Running | PowerOn     |
|  6 | 791dec0a-cb68-4e22-a84d-1e0b76950766 | testvm02 | i-2-6-VM      |       4 |            4 | Running | PowerOn     |
|  7 | b5124b1e-b28f-4124-a7c3-8b268aa95188 | testvm04 | i-2-7-VM      |       2 |            2 | Running | PowerOn     |
|  9 | 7dc7aa3d-bf05-405d-8023-03550ce79548 | testvm03 | i-2-9-VM      |       2 |            2 | Running | PowerOn     |
| 10 | 4ff51ad8-cf79-4ef9-9a96-6a2bc1b58329 | testvm05 | i-2-10-VM     |       1 |            1 | Running | PowerOn     |
| 11 | ace7067a-2772-432d-9fd3-6d652551d78e | testvm06 | i-2-11-VM     |       1 |            1 | Running | PowerOn     |
+----+--------------------------------------+----------+---------------+---------+--------------+---------+-------------+
6 rows in set (0.00 sec)

Host 2 in Maintenance =>

mysql> SELECT id, uuid, name, status, resource_state FROM cloud.host WHERE type = 'Routing' AND removed IS NULL;
+----+--------------------------------------+------------------------------------------+--------+----------------+
| id | uuid                                 | name                                     | status | resource_state |
+----+--------------------------------------+------------------------------------------+--------+----------------+
|  1 | dfa467a0-fadf-4cfb-ad36-cdbfa57f0e17 | ref-trl-10139-k-Mr8-suresh-anaparti-kvm1 | Up     | Enabled        |
|  2 | d0463494-995c-463a-9d4b-72eb37dca9be | ref-trl-10139-k-Mr8-suresh-anaparti-kvm2 | Up     | Maintenance    |
|  3 | 69054cd3-296e-4040-a3e9-7889274fde63 | ref-trl-10139-k-Mr8-suresh-anaparti-kvm3 | Up     | Enabled        |
|  4 | cd369b58-72a1-46f1-b5ac-158c2717776e | ref-trl-10139-k-Mr8-suresh-anaparti-kvm4 | Up     | Enabled        |
+----+--------------------------------------+------------------------------------------+--------+----------------+
4 rows in set (0.00 sec)

mysql> SELECT id, uuid, name, instance_name, host_id, last_host_id, state, power_state FROM cloud.vm_instance WHERE type = 'User' AND removed IS NULL;
+----+--------------------------------------+----------+---------------+---------+--------------+---------+-------------+
| id | uuid                                 | name     | instance_name | host_id | last_host_id | state   | power_state |
+----+--------------------------------------+----------+---------------+---------+--------------+---------+-------------+
|  4 | a5ec3d7d-aca5-4c20-b682-55f5ebacc8e3 | testvm01 | i-2-4-VM      |       1 |            1 | Running | PowerOn     |
|  6 | 791dec0a-cb68-4e22-a84d-1e0b76950766 | testvm02 | i-2-6-VM      |       4 |            4 | Running | PowerOn     |
|  7 | b5124b1e-b28f-4124-a7c3-8b268aa95188 | testvm04 | i-2-7-VM      |       1 |            2 | Running | PowerOn     |
|  9 | 7dc7aa3d-bf05-405d-8023-03550ce79548 | testvm03 | i-2-9-VM      |       1 |            2 | Running | PowerOn     |
| 10 | 4ff51ad8-cf79-4ef9-9a96-6a2bc1b58329 | testvm05 | i-2-10-VM     |       1 |            1 | Running | PowerOn     |
| 11 | ace7067a-2772-432d-9fd3-6d652551d78e | testvm06 | i-2-11-VM     |       1 |            1 | Running | PowerOn     |
+----+--------------------------------------+----------+---------------+---------+--------------+---------+-------------+
6 rows in set (0.00 sec)

Host 4 in Maintenance =>

mysql> SELECT id, uuid, name, status, resource_state FROM cloud.host WHERE type = 'Routing' AND removed IS NULL;
+----+--------------------------------------+------------------------------------------+--------+----------------+
| id | uuid                                 | name                                     | status | resource_state |
+----+--------------------------------------+------------------------------------------+--------+----------------+
|  1 | dfa467a0-fadf-4cfb-ad36-cdbfa57f0e17 | ref-trl-10139-k-Mr8-suresh-anaparti-kvm1 | Up     | Enabled        |
|  2 | d0463494-995c-463a-9d4b-72eb37dca9be | ref-trl-10139-k-Mr8-suresh-anaparti-kvm2 | Up     | Maintenance    |
|  3 | 69054cd3-296e-4040-a3e9-7889274fde63 | ref-trl-10139-k-Mr8-suresh-anaparti-kvm3 | Up     | Enabled        |
|  4 | cd369b58-72a1-46f1-b5ac-158c2717776e | ref-trl-10139-k-Mr8-suresh-anaparti-kvm4 | Up     | Maintenance    |
+----+--------------------------------------+------------------------------------------+--------+----------------+
4 rows in set (0.00 sec)

mysql> SELECT id, uuid, name, instance_name, host_id, last_host_id, state, power_state FROM cloud.vm_instance WHERE type = 'User' AND removed IS NULL;
+----+--------------------------------------+----------+---------------+---------+--------------+---------+-------------+
| id | uuid                                 | name     | instance_name | host_id | last_host_id | state   | power_state |
+----+--------------------------------------+----------+---------------+---------+--------------+---------+-------------+
|  4 | a5ec3d7d-aca5-4c20-b682-55f5ebacc8e3 | testvm01 | i-2-4-VM      |       1 |            1 | Running | PowerOn     |
|  6 | 791dec0a-cb68-4e22-a84d-1e0b76950766 | testvm02 | i-2-6-VM      |       1 |            4 | Running | PowerOn     |
|  7 | b5124b1e-b28f-4124-a7c3-8b268aa95188 | testvm04 | i-2-7-VM      |       1 |            2 | Running | PowerOn     |
|  9 | 7dc7aa3d-bf05-405d-8023-03550ce79548 | testvm03 | i-2-9-VM      |       1 |            2 | Running | PowerOn     |
| 10 | 4ff51ad8-cf79-4ef9-9a96-6a2bc1b58329 | testvm05 | i-2-10-VM     |       1 |            1 | Running | PowerOn     |
| 11 | ace7067a-2772-432d-9fd3-6d652551d78e | testvm06 | i-2-11-VM     |       1 |            1 | Running | PowerOn     |
+----+--------------------------------------+----------+---------------+---------+--------------+---------+-------------+
6 rows in set (0.00 sec)

Host 1 in Maintenance =>

mysql> SELECT id, uuid, name, status, resource_state FROM cloud.host WHERE type = 'Routing' AND removed IS NULL;
+----+--------------------------------------+------------------------------------------+--------+----------------+
| id | uuid                                 | name                                     | status | resource_state |
+----+--------------------------------------+------------------------------------------+--------+----------------+
|  1 | dfa467a0-fadf-4cfb-ad36-cdbfa57f0e17 | ref-trl-10139-k-Mr8-suresh-anaparti-kvm1 | Up     | Maintenance    |
|  2 | d0463494-995c-463a-9d4b-72eb37dca9be | ref-trl-10139-k-Mr8-suresh-anaparti-kvm2 | Up     | Maintenance    |
|  3 | 69054cd3-296e-4040-a3e9-7889274fde63 | ref-trl-10139-k-Mr8-suresh-anaparti-kvm3 | Up     | Enabled        |
|  4 | cd369b58-72a1-46f1-b5ac-158c2717776e | ref-trl-10139-k-Mr8-suresh-anaparti-kvm4 | Up     | Maintenance    |
+----+--------------------------------------+------------------------------------------+--------+----------------+
4 rows in set (0.00 sec)

mysql> SELECT id, uuid, name, instance_name, host_id, last_host_id, state, power_state FROM cloud.vm_instance WHERE type = 'User' AND removed IS NULL;
+----+--------------------------------------+----------+---------------+---------+--------------+---------+-------------+
| id | uuid                                 | name     | instance_name | host_id | last_host_id | state   | power_state |
+----+--------------------------------------+----------+---------------+---------+--------------+---------+-------------+
|  4 | a5ec3d7d-aca5-4c20-b682-55f5ebacc8e3 | testvm01 | i-2-4-VM      |       3 |            1 | Running | PowerOn     |
|  6 | 791dec0a-cb68-4e22-a84d-1e0b76950766 | testvm02 | i-2-6-VM      |       3 |            1 | Running | PowerOn     |
|  7 | b5124b1e-b28f-4124-a7c3-8b268aa95188 | testvm04 | i-2-7-VM      |       3 |            1 | Running | PowerOn     |
|  9 | 7dc7aa3d-bf05-405d-8023-03550ce79548 | testvm03 | i-2-9-VM      |       3 |            1 | Running | PowerOn     |
| 10 | 4ff51ad8-cf79-4ef9-9a96-6a2bc1b58329 | testvm05 | i-2-10-VM     |       3 |            1 | Running | PowerOn     |
| 11 | ace7067a-2772-432d-9fd3-6d652551d78e | testvm06 | i-2-11-VM     |       3 |            1 | Running | PowerOn     |
+----+--------------------------------------+----------+---------------+---------+--------------+---------+-------------+
6 rows in set (0.00 sec)
HostsInMaintenance InstancesRunningAfterMaintenance

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

@codecov
Copy link

codecov bot commented Nov 13, 2025

Codecov Report

❌ Patch coverage is 15.38462% with 33 lines in your changes missing coverage. Please review.
✅ Project coverage is 16.24%. Comparing base (243f566) to head (9b3f526).
⚠️ Report is 77 commits behind head on 4.20.

Files with missing lines Patch % Lines
...om/cloud/deploy/DeploymentPlanningManagerImpl.java 16.21% 28 Missing and 3 partials ⚠️
...java/com/cloud/ha/HighAvailabilityManagerImpl.java 0.00% 1 Missing ⚠️
...n/java/com/cloud/resource/ResourceManagerImpl.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               4.20   #12062      +/-   ##
============================================
+ Coverage     16.18%   16.24%   +0.06%     
- Complexity    13301    13401     +100     
============================================
  Files          5657     5658       +1     
  Lines        498473   499275     +802     
  Branches      60501    60601     +100     
============================================
+ Hits          80663    81128     +465     
- Misses       408830   409100     +270     
- Partials       8980     9047      +67     
Flag Coverage Δ
uitests 4.03% <ø> (+0.02%) ⬆️
unittests 17.10% <15.38%> (+0.07%) ⬆️

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
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes deployment planning logic for VMs with last host by ensuring the last host is considered only when it exists and is not in maintenance mode. When users explicitly request last host consideration and the host doesn't exist or is in maintenance, deployment now fails with a clear error message.

Key Changes:

  • Added validation to check if last host exists and is not in maintenance before attempting deployment
  • When ConsiderLastHost is explicitly set to "true", deployment now fails with an exception if the last host is unavailable
  • Fixed minor logging inconsistencies and typos across multiple files

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
server/src/main/java/com/cloud/deploy/DeploymentPlanningManagerImpl.java Core logic changes to validate last host existence and maintenance state, with error handling when explicitly requested; also fixed a typo in a log message
server/src/main/java/com/cloud/ha/HighAvailabilityManagerImpl.java Minor log message formatting improvements for migration attempts (removed extra space)
server/src/main/java/com/cloud/resource/ResourceManagerImpl.java Updated log message format for consistency during maintenance operations

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@sureshanaparti
Copy link
Contributor Author

@blueorangutan package

@blueorangutan
Copy link

@sureshanaparti 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.

@sureshanaparti sureshanaparti force-pushed the vm-deployment-with-last-host-improvements branch from 5ec03de to 6aa828b Compare November 13, 2025 10:05
@sureshanaparti
Copy link
Contributor Author

@blueorangutan package

@blueorangutan
Copy link

@sureshanaparti 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 15747

@sureshanaparti sureshanaparti marked this pull request as ready for review November 14, 2025 05:40
@sureshanaparti
Copy link
Contributor Author

@blueorangutan test

@blueorangutan
Copy link

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

@sureshanaparti sureshanaparti changed the title Deployment plan fixes for VM with last host Deployment plan fixes for VM with last host, and last host in maintenance Nov 14, 2025
@sureshanaparti
Copy link
Contributor Author

@blueorangutan package

@blueorangutan
Copy link

@sureshanaparti 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 15770

Copy link
Contributor

@DaanHoogland DaanHoogland left a comment

Choose a reason for hiding this comment

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

clgtm, only possible snatch may be afinity, but on the other hand, it is only a “when all else fails” scenario. We should be good like this.

@blueorangutan
Copy link

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

Test Result Time (s) Test File

- Consider last host when it is not in maintenance
- Fail deployment when user requests for last host consideration and last host doesn't exists or in maintenance
@sureshanaparti sureshanaparti force-pushed the vm-deployment-with-last-host-improvements branch from da2b6d9 to 51cf988 Compare December 2, 2025 10:46
@sureshanaparti
Copy link
Contributor Author

@blueorangutan package

@blueorangutan
Copy link

@sureshanaparti 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 15887

@sureshanaparti
Copy link
Contributor Author

@blueorangutan test

@blueorangutan
Copy link

@sureshanaparti 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-14901)
Environment: kvm-ol8 (x2), zone: Advanced Networking with Mgmt server ol8
Total time taken: 55740 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr12062-t14901-kvm-ol8.zip
Smoke tests completed. 141 look OK, 0 have errors, 0 did not run
Only failed and skipped tests results shown below:

Test Result Time (s) Test File

@DaanHoogland DaanHoogland added this to the 4.20.3 milestone Dec 29, 2025
@DaanHoogland
Copy link
Contributor

@sureshanaparti @abh1sar does this need (any kind of) testing ?

@borisstoyanov
Copy link
Contributor

@sureshanaparti are you planning to address the latest comments from @abh1sar ?

@sureshanaparti
Copy link
Contributor Author

@blueorangutan package

@blueorangutan
Copy link

@sureshanaparti 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 16564

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.

[BUG] VMs stopped after automatic selection of hosts in maintenance for VM migrations away from hosts

6 participants