Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 18 additions & 14 deletions src/main/omnia.sh
Original file line number Diff line number Diff line change
Expand Up @@ -118,19 +118,19 @@ validate_env() {

export SYSTEM_ADMIN_NIC_IPV4

# --- Validate hostname matches system (hostname -s) ---
# --- Validate hostname matches system (hostnamectl hostname) ---
local actual_hostname
actual_hostname="$(hostname -s 2>/dev/null || hostname 2>/dev/null)"
actual_hostname="$(hostnamectl hostname 2>/dev/null)"
if [ -n "$actual_hostname" ] && [ "$actual_hostname" != "$SYSTEM_HOSTNAME" ]; then
echo -e "${RED}ERROR: SYSTEM_HOSTNAME (${SYSTEM_HOSTNAME}) does not match actual hostname (${actual_hostname})${NC}"
echo -e "${YELLOW} Fix: update SYSTEM_HOSTNAME in omnia.env${NC}"
echo -e "${YELLOW} Or: hostnamectl set-hostname ${SYSTEM_HOSTNAME}${NC}"
errors=$((errors + 1))
fi

# --- Validate domain matches system (hostname -d) ---
# --- Validate domain matches system (hostnamectl --static) ---
local actual_domain
actual_domain="$(hostname -d 2>/dev/null || true)"
actual_domain="$(hostnamectl --static 2>/dev/null | cut -s -d. -f2-)"
if [ -n "$actual_domain" ] && [ "$actual_domain" != "$SYSTEM_DOMAIN_NAME" ]; then
echo -e "${YELLOW}WARNING: SYSTEM_DOMAIN_NAME (${SYSTEM_DOMAIN_NAME}) does not match system domain (${actual_domain})${NC}"
echo -e "${YELLOW} Fix: update SYSTEM_DOMAIN_NAME in omnia.env${NC}"
Expand All @@ -140,7 +140,7 @@ validate_env() {

# --- Validate admin IP is assigned to a local interface ---
local all_ips
all_ips="$(hostname -I 2>/dev/null || ip -4 addr show | grep -oP '(?<=inet\s)\d+\.\d+\.\d+\.\d+' 2>/dev/null || true)"
all_ips="$(ip -4 addr show 2>/dev/null | awk '/inet / {print $2}' | cut -d/ -f1 | tr '\n' ' ')"
if [ -n "$all_ips" ]; then
local ip_found=false
for ip in $all_ips; do
Expand All @@ -152,7 +152,7 @@ validate_env() {
if [ "$ip_found" = false ]; then
echo -e "${RED}ERROR: SYSTEM_ADMIN_NIC_IPV4 (${SYSTEM_ADMIN_NIC_IPV4}) is not assigned to any local interface${NC}"
echo -e "${YELLOW} Available IPs: ${all_ips}${NC}"
echo -e "${YELLOW} Fix: update SYSTEM_ADMIN_NIC_IPV4 in omnia.env${NC}"
echo -e "${YELLOW} Fix: update SYSTEM_ADMIN_NIC_IPV4 in ${SYSTEM_ENV_FILE}${NC}"
errors=$((errors + 1))
fi
fi
Expand Down Expand Up @@ -184,18 +184,22 @@ readonly PROFILE_DROP_IN="/etc/profile.d/omnia-env.sh"
install_system_env() {
local env_file="$SCRIPT_DIR/omnia.env"

if [ ! -f "$env_file" ]; then
echo -e "${YELLOW}WARNING: src/main/omnia.env not found — skipping system env install${NC}"
return 0
fi

echo -e "${BLUE}Installing environment to system...${NC}"

mkdir -p "$SYSTEM_ENV_DIR"
cp -f "$env_file" "$SYSTEM_ENV_FILE"
chmod 0644 "$SYSTEM_ENV_FILE"

echo -e " ${GREEN}Installed: ${SYSTEM_ENV_FILE}${NC}"
if [ -f "$SYSTEM_ENV_FILE" ]; then
echo -e " ${YELLOW}Existing: ${SYSTEM_ENV_FILE} (not overwritten)${NC}"
echo -e " ${YELLOW} Edit ${SYSTEM_ENV_FILE} to change settings.${NC}"
else
if [ ! -f "$env_file" ]; then
echo -e "${YELLOW}WARNING: src/main/omnia.env not found — skipping env file install${NC}"
return 0
fi
cp -f "$env_file" "$SYSTEM_ENV_FILE"
chmod 0644 "$SYSTEM_ENV_FILE"
echo -e " ${GREEN}Installed: ${SYSTEM_ENV_FILE}${NC}"
fi

cat > "$PROFILE_DROP_IN" <<'PROFILE_EOF'
#!/bin/bash
Expand Down
4 changes: 2 additions & 2 deletions test/discovery/library/vars/common_vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@
),

# --- System ---
"hostname_cmd": "hostname 2>/dev/null",
"hostname_ip": "hostname -I 2>/dev/null",
"hostname_cmd": "hostnamectl hostname 2>/dev/null",
"hostname_ip": "ip -4 addr show 2>/dev/null | awk '/inet / {print $2}' | cut -d/ -f1 | tr '\\n' ' '",
"rpm_check": "rpm -q {package} 2>/dev/null",
"which_cmd": "which {binary} 2>/dev/null",

Expand Down
11 changes: 6 additions & 5 deletions test/image_build_manager/library/functions/build_image_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -1765,8 +1765,9 @@ def check_env_vars_present(host) -> Dict[str, Any]:
def check_hostname_domain(host) -> Dict[str, Any]:
"""Verify hostname and domain match configured env vars on target.

Uses ``hostname -s`` (short hostname) and ``hostname -d`` (domain)
to compare against SYSTEM_HOSTNAME and SYSTEM_DOMAIN_NAME.
Uses ``hostnamectl hostname`` (short hostname) and
``hostnamectl --static`` (domain) to compare against
SYSTEM_HOSTNAME and SYSTEM_DOMAIN_NAME.

Returns:
Dict with 'success', 'results', 'details'.
Expand Down Expand Up @@ -1807,13 +1808,13 @@ def check_hostname_domain(host) -> Dict[str, Any]:
if not hostname_match:
error = (
f"Hostname mismatch: SYSTEM_HOSTNAME={cfg_hostname}, "
f"actual hostname -s={actual_hostname}. "
f"actual hostnamectl hostname={actual_hostname}. "
"Fix: hostnamectl set-hostname <name> or update omnia.env"
)
elif not domain_match:
error = (
f"Domain mismatch: SYSTEM_DOMAIN_NAME={cfg_domain}, "
f"actual hostname -d={actual_domain}. "
f"actual hostnamectl --static (domain)={actual_domain}. "
"Fix: update SYSTEM_DOMAIN_NAME in omnia.env or "
f"hostnamectl set-hostname {cfg_hostname}.{cfg_domain}"
)
Expand All @@ -1830,7 +1831,7 @@ def check_admin_ip(host) -> Dict[str, Any]:
"""Verify SYSTEM_ADMIN_NIC_IPV4 is assigned to a local interface.

Reads SYSTEM_ADMIN_NIC_IPV4 from the target and verifies the IP is
present in the output of ``hostname -I``.
present in the output of ``ip -4 addr show``.

Returns:
Dict with 'success', 'details', 'error'.
Expand Down
4 changes: 2 additions & 2 deletions test/image_build_manager/library/messages/build_image_msgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@
"\u2551 {error}\n"
"\u2551\n"
"\u2551 HOW TO FIX:\n"
"\u2551 1. Check actual: hostname -s (short), hostname -d (domain)\n"
"\u2551 1. Check actual: hostnamectl hostname (short), hostnamectl --static (FQDN)\n"
"\u2551 2. Update SYSTEM_HOSTNAME / SYSTEM_DOMAIN_NAME in omnia.env\n"
"\u2551 3. Or: hostnamectl set-hostname <hostname>.<domain>\n"
"\u2551 4. Re-run: omnia.sh --setup-venv\n"
Expand All @@ -439,7 +439,7 @@
"\u2551 {error}\n"
"\u2551\n"
"\u2551 HOW TO FIX:\n"
"\u2551 1. Check assigned IPs: hostname -I\n"
"\u2551 1. Check assigned IPs: ip -4 addr show\n"
"\u2551 2. Verify SYSTEM_ADMIN_NIC_IPV4 in omnia.env matches one of them\n"
"\u2551 3. Re-run: omnia.sh --setup-venv\n"
"\u255a" + _BORDER + "\u255d\n"
Expand Down
8 changes: 4 additions & 4 deletions test/image_build_manager/library/vars/common_vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,10 @@
" --tags {tag} -v 2>&1"
),
# --- System ---
"hostname_short": "hostname -s 2>/dev/null",
"hostname_domain": "hostname -d 2>/dev/null",
"hostname_fqdn": "hostname -f 2>/dev/null",
"hostname_ip": "hostname -I 2>/dev/null",
"hostname_short": "hostnamectl hostname 2>/dev/null | cut -d. -f1",
"hostname_domain": "hostnamectl --static 2>/dev/null | cut -s -d. -f2-",
"hostname_fqdn": "hostnamectl --static 2>/dev/null",
"hostname_ip": "ip -4 addr show 2>/dev/null | awk '/inet / {print $2}' | cut -d/ -f1 | tr '\\n' ' '",
"rpm_check": "rpm -q {package} 2>/dev/null",
"which_cmd": "which {binary} 2>/dev/null",
# --- Systemd ---
Expand Down
2 changes: 1 addition & 1 deletion test/main/library/vars/common_vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@
" -type f 2>/dev/null | wc -l"
),
# --- System ---
"hostname_cmd": "hostname 2>/dev/null",
"hostname_cmd": "hostnamectl hostname 2>/dev/null",
"which_cmd": "which {binary} 2>/dev/null",
# --- omnia-cli execution ---
"omnia_cli_help": (
Expand Down
4 changes: 2 additions & 2 deletions test/orchestrator/library/vars/common_vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@
),

# --- System ---
"hostname_cmd": "hostname 2>/dev/null",
"hostname_ip": "hostname -I 2>/dev/null",
"hostname_cmd": "hostnamectl hostname 2>/dev/null",
"hostname_ip": "ip -4 addr show 2>/dev/null | awk '/inet / {print $2}' | cut -d/ -f1 | tr '\\n' ' '",
"rpm_check": "rpm -q {package} 2>/dev/null",
"which_cmd": "which {binary} 2>/dev/null",

Expand Down
6 changes: 4 additions & 2 deletions test/plugins/omnia_auto/functions/host_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"""

import os
import re
import subprocess
import tempfile
from typing import Dict, Any, Optional, Tuple
Expand Down Expand Up @@ -247,10 +248,11 @@ def _is_local_ip(ip: str) -> bool:
return True
try:
result = subprocess.run(
["hostname", "-I"],
["ip", "-4", "addr", "show"],
capture_output=True, text=True, timeout=5, check=False,
)
return ip in result.stdout.strip().split()
ips = re.findall(r'\binet (\d+\.\d+\.\d+\.\d+)/', result.stdout)
return ip in ips
except (OSError, subprocess.SubprocessError):
return False

Expand Down
Loading