Skip to content

Conversation

weizhouapache
Copy link
Member

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
@weizhouapache
Copy link
Member Author

@blueorangutan package

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

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.

@blueorangutan
Copy link

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

@weizhouapache
Copy link
Member Author

@blueorangutan test

@blueorangutan
Copy link

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

@Pearl1594 Pearl1594 moved this to In Progress in ACS 4.20.1 Mar 17, 2025
@weizhouapache weizhouapache marked this pull request as ready for review March 18, 2025 08:22
@DaanHoogland DaanHoogland modified the milestones: 4.19.3, 4.19.4 May 12, 2025
@rohityadavcloud rohityadavcloud modified the milestones: 4.19.4, 4.20.2 May 16, 2025
Copy link
Contributor

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

@weizhouapache weizhouapache marked this pull request as draft September 3, 2025 07:23
@weizhouapache weizhouapache modified the milestones: 4.20.2, 4.20.3 Sep 10, 2025
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.

5 participants