Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

cloudstack-setup-databases: get local address instead of 127.0.1.1 #10571

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

Draft
weizhouapache wants to merge 3 commits into apache:4.19
base: 4.19
Choose a base branch
Loading
from weizhouapache:4.19-fix-cluster-node-ip-127.0.1.1

Conversation

@weizhouapache
Copy link
Contributor

@weizhouapache weizhouapache commented Mar 14, 2025

Description

This PR fixes the issue which has been mentioned in #8218 #9880 #7533 #10384

In some linux setup, the server has the line in /etc/hosts

127.0.1.1 <hostname>

If the mgmt serve IP is not specified when run cloudstack-setup-databases, ACS detects the host ip in python, however there is an issue with it.

>>> import socket
>>> socket.gethostbyname(socket.gethostname())
'127.0.1.1' <<<<=======================this is not good
>>> socket.gethostbyname(socket.gethostname() + ".local")
'10.0.100.100' <<<========================this is good

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?

In some linux setup, the server has the line in /etc/hosts
```
127.0.1.1 <hostname>
```
If the mgmt serve IP is not specified when run cloudstack-setup-databases, ACS detects the host ip in python, however there is an issue with it.
```
>>> import socket
>>> socket.gethostbyname(socket.gethostname())
'127.0.1.1' <<<<=======================this is not good
>>> socket.gethostbyname(socket.gethostname() + ".local")
'10.0.100.100' <<<========================this is good
```
@weizhouapache weizhouapache added this to the 4.19.3 milestone Mar 14, 2025
Copy link
Contributor Author

@blueorangutan package

Copy link

@weizhouapache 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

codecov bot commented Mar 14, 2025
edited
Loading

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 15.17%. Comparing base (95c2481) to head (3efd24b).
⚠️ Report is 118 commits behind head on 4.19.

Additional details and impacted files
@@ Coverage Diff @@
## 4.19 #10571 +/- ##
==========================================
 Coverage 15.16% 15.17% 
- Complexity 11326 11347 +21 
==========================================
 Files 5414 5416 +2 
 Lines 474804 475621 +817 
 Branches 57909 58054 +145 
==========================================
+ Hits 72002 72157 +155 
- Misses 394749 395393 +644 
- Partials 8053 8071 +18 
Flag Coverage Δ
uitests 4.28% <ø> (-0.01%) ⬇️
unittests 15.89% <ø> (+<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

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

Copy link
Contributor Author

Copy link

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

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 the issue where the CloudStack database setup script incorrectly detects the management server IP address as 127.0.1.1 on some Linux systems due to hostname resolution returning localhost addresses instead of the actual network interface IP.

Key changes:

  • Replace simple hostname resolution with comprehensive IP address detection
  • Filter out localhost addresses (127.0.0.1 and 127.0.1.1) to find actual network interface IP
  • Fallback to 127.0.0.1 if no valid external IP is found

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +331 to +335
hostname, aliases, addresses = socket.gethostbyname_ex(socket.gethostname())
for address in addresses:
if address != "127.0.0.1" and address != "127.0.1.1":
return address
return "127.0.0.1"
Copy link

Copilot AI Sep 3, 2025

Choose a reason for hiding this comment

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

The hardcoded IP address strings should be replaced with constants or use the ipaddress module for better maintainability. Consider using ipaddress.ip_address(address).is_loopback to check for all loopback addresses, not just the two specific ones.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@yadvr yadvr yadvr left review comments

@DaanHoogland DaanHoogland DaanHoogland left review comments

Copilot code review Copilot Copilot left review comments

Assignees

No one assigned

Projects

None yet

Milestone

4.20.3

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /