Skip to content

Don't allow adding of existing host to another zone, pod or cluster#13182

Draft
vishesh92 wants to merge 3 commits into
apache:4.20from
shapeblue:fix-add-host-diff-location
Draft

Don't allow adding of existing host to another zone, pod or cluster#13182
vishesh92 wants to merge 3 commits into
apache:4.20from
shapeblue:fix-add-host-diff-location

Conversation

@vishesh92
Copy link
Copy Markdown
Member

Description

This PR fixes #13080

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?

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

@codecov
Copy link
Copy Markdown

codecov Bot commented May 18, 2026

Codecov Report

❌ Patch coverage is 75.75758% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 17.12%. Comparing base (a7c2a05) to head (6aee0d9).

Files with missing lines Patch % Lines
...n/java/com/cloud/resource/ResourceManagerImpl.java 75.75% 4 Missing and 4 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               4.20   #13182      +/-   ##
============================================
+ Coverage     16.27%   17.12%   +0.85%     
- Complexity    13440    13443       +3     
============================================
  Files          5665     5261     -404     
  Lines        500555   467622   -32933     
  Branches      60789    54902    -5887     
============================================
- Hits          81445    80070    -1375     
+ Misses       410004   378616   -31388     
+ Partials       9106     8936     -170     
Flag Coverage Δ
uitests ?
unittests 17.12% <75.75%> (-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.

@apache apache deleted a comment from blueorangutan May 18, 2026
@vishesh92 vishesh92 force-pushed the fix-add-host-diff-location branch from 2f64bcd to 6bf5881 Compare May 18, 2026 12:06
@apache apache deleted a comment from blueorangutan May 18, 2026
@vishesh92
Copy link
Copy Markdown
Member Author

@blueorangutan package

@blueorangutan
Copy link
Copy Markdown

@vishesh92 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 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 17895

Copy link
Copy Markdown
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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

shwstppr and others added 2 commits May 19, 2026 00:25
@vishesh92
Copy link
Copy Markdown
Member Author

@blueorangutan package

@blueorangutan
Copy link
Copy Markdown

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

Copy link
Copy Markdown
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

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

Comment on lines +2619 to +2629
try {
hostIpOrName = new URI(UriUtils.encodeURIComponent(url)).getHost();
InetAddress ip = InetAddress.getByName(hostIpOrName);
ipAddress = ip.getHostAddress();
} catch (final URISyntaxException | UnknownHostException ignore) {
// unparseable URL or unknown host - discoverer will reject it shortly anyway
}
if (StringUtils.isBlank(hostIpOrName)) {
return;
}
final HostVO existingByIp = _hostDao.findByIp(ipAddress);
Comment on lines +2621 to +2634
InetAddress ip = InetAddress.getByName(hostIpOrName);
ipAddress = ip.getHostAddress();
} catch (final URISyntaxException | UnknownHostException ignore) {
// unparseable URL or unknown host - discoverer will reject it shortly anyway
}
if (StringUtils.isBlank(hostIpOrName)) {
return;
}
final HostVO existingByIp = _hostDao.findByIp(ipAddress);
if (existingByIp != null) {
throw new InvalidParameterValueException(String.format(
"A host with IP address / hostname '%s' (%s) already exists (id: %s). Remove it before adding again.",
hostIpOrName, ipAddress, existingByIp.getUuid()));
}

protected void validateExistingHostLocationImmutable(final HostVO host, final boolean newHost,
final long dcId, final Long podId, final Long clusterId, final StartupCommand startup) {
if (newHost || host == null || host.getType() != Host.Type.Routing) {
final String identity = host.getUuid() != null ? host.getUuid() : host.getGuid();
final String ip = startup != null ? startup.getPrivateIpAddress() : "unknown";
throw new InvalidParameterValueException(String.format(
"Host %s (ip: %s) is already registered in [zone: %d, pod: %d, cluster: %d] and cannot be re-added or reconnected with [zone: %d, pod: %s, cluster: %s]. Zone, pod and cluster of an existing host are immutable.",
verify(hostDao, times(1)).findByIp("10.0.0.30");
}

@Test
@blueorangutan
Copy link
Copy Markdown

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

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.

4 participants