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
152 changes: 76 additions & 76 deletions test/test_egressip_basic.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,86 +1,86 @@
#!/usr/bin/env python3
#Basic EgressIP Test - No external dependencies
import asyncio
import json
import subprocess
from datetime import datetime
#!/usr/bin/env python3
#Basic EgressIP Test - No external dependencies
import asyncio
import json
import subprocess
from datetime import datetime

async def test_egressip_basic():
"""Test basic EgressIP functionality without dependencies"""
print("🧪 Testing EgressIP Basic Functionality")
async def test_egressip_basic():
"""Test basic EgressIP functionality without dependencies"""
print("🧪 Testing EgressIP Basic Functionality")

try:
# Test 1: Check cluster access
print("\n1️⃣ Testing cluster access...")
result = subprocess.run(['oc', 'get', 'nodes', '--no-headers'],
capture_output=True, text=True)
if result.returncode == 0:
node_count = len([line for line in result.stdout.split('\n') if line.strip()])
print(f"✅ Cluster accessible - Found {node_count} nodes")
else:
print(f"❌ Cluster access failed: {result.stderr}")
return
try:
# Test 1: Check cluster access
print("\n1️⃣ Testing cluster access...")
result = subprocess.run(['oc', 'get', 'nodes', '--no-headers'],
capture_output=True, text=True)
if result.returncode == 0:
node_count = len([line for line in result.stdout.split('\n') if line.strip()])
print(f"✅ Cluster accessible - Found {node_count} nodes")
else:
print(f"❌ Cluster access failed: {result.stderr}")
return

# Test 2: Check EgressIP CRD
print("\n2️⃣ Testing EgressIP CRD availability...")
result = subprocess.run(['oc', 'get', 'crd', 'egressips.k8s.ovn.org'],
capture_output=True, text=True)
if result.returncode == 0:
print("✅ EgressIP CRD is available")
else:
print(f"❌ EgressIP CRD not found: {result.stderr}")
# Test 2: Check EgressIP CRD
print("\n2️⃣ Testing EgressIP CRD availability...")
result = subprocess.run(['oc', 'get', 'crd', 'egressips.k8s.ovn.org'],
capture_output=True, text=True)
if result.returncode == 0:
print("✅ EgressIP CRD is available")
else:
print(f"❌ EgressIP CRD not found: {result.stderr}")

# Test 3: Check existing EgressIPs
print("\n3️⃣ Testing EgressIP objects...")
result = subprocess.run(['oc', 'get', 'egressips', '-o', 'json'],
capture_output=True, text=True)
if result.returncode == 0:
data = json.loads(result.stdout)
egressip_count = len(data.get('items', []))
print(f"✅ Found {egressip_count} EgressIP objects")
# Test 3: Check existing EgressIPs
print("\n3️⃣ Testing EgressIP objects...")
result = subprocess.run(['oc', 'get', 'egressips', '-o', 'json'],
capture_output=True, text=True)
if result.returncode == 0:
data = json.loads(result.stdout)
egressip_count = len(data.get('items', []))
print(f"✅ Found {egressip_count} EgressIP objects")

# Show EgressIP details if any exist
for eip in data.get('items', [])[:3]: # Show first 3
name = eip['metadata']['name']
spec_ips = eip.get('spec', {}).get('egressIPs', [])
status_items = eip.get('status', {}).get('items', [])
print(f" 📋 EgressIP: {name}")
print(f" Spec IPs: {spec_ips}")
print(f" Status Items: {len(status_items)}")
else:
print(f"❌ Could not get EgressIPs: {result.stderr}")
# Show EgressIP details if any exist
for eip in data.get('items', [])[:3]: # Show first 3
name = eip['metadata']['name']
spec_ips = eip.get('spec', {}).get('egressIPs', [])
status_items = eip.get('status', {}).get('items', [])
print(f" 📋 EgressIP: {name}")
print(f" Spec IPs: {spec_ips}")
print(f" Status Items: {len(status_items)}")
else:
print(f"❌ Could not get EgressIPs: {result.stderr}")

# Test 4: Check network type
print("\n4️⃣ Testing network configuration...")
result = subprocess.run(['oc', 'get', 'network.operator', 'cluster',
'-o', 'jsonpath={.spec.defaultNetwork.type}'],
capture_output=True, text=True)
if result.returncode == 0:
network_type = result.stdout.strip()
print(f"✅ Network type: {network_type}")
if network_type == "OVNKubernetes":
print("✅ OVN-Kubernetes detected - EgressIP compatible")
else:
print("⚠️ Non-OVN network - EgressIP may not work properly")
else:
print(f"❌ Could not get network type: {result.stderr}")
# Test 4: Check network type
print("\n4️⃣ Testing network configuration...")
result = subprocess.run(['oc', 'get', 'network.operator', 'cluster',
'-o', 'jsonpath={.spec.defaultNetwork.type}'],
capture_output=True, text=True)
if result.returncode == 0:
network_type = result.stdout.strip()
print(f"✅ Network type: {network_type}")
if network_type == "OVNKubernetes":
print("✅ OVN-Kubernetes detected - EgressIP compatible")
else:
print("⚠️ Non-OVN network - EgressIP may not work properly")
else:
print(f"❌ Could not get network type: {result.stderr}")

# Test 5: Check EgressIP-capable nodes
print("\n5️⃣ Testing EgressIP-capable nodes...")
result = subprocess.run(['oc', 'get', 'nodes', '-l',
'k8s.ovn.org/egress-assignable=true', '--no-headers'],
capture_output=True, text=True)
if result.returncode == 0:
capable_nodes = len([line for line in result.stdout.split('\n') if line.strip()])
print(f"✅ Found {capable_nodes} EgressIP-capable nodes")
else:
print(f"⚠️ Could not check EgressIP-capable nodes: {result.stderr}")
# Test 5: Check EgressIP-capable nodes
print("\n5️⃣ Testing EgressIP-capable nodes...")
result = subprocess.run(['oc', 'get', 'nodes', '-l',
'k8s.ovn.org/egress-assignable=true', '--no-headers'],
capture_output=True, text=True)
if result.returncode == 0:
capable_nodes = len([line for line in result.stdout.split('\n') if line.strip()])
print(f"✅ Found {capable_nodes} EgressIP-capable nodes")
else:
print(f"⚠️ Could not check EgressIP-capable nodes: {result.stderr}")

print(f"\n🎯 EgressIP Basic Test Completed at {datetime.utcnow().isoformat()}")
print("✅ Basic EgressIP environment validation successful!")
print(f"\n🎯 EgressIP Basic Test Completed at {datetime.utcnow().isoformat()}")
print("✅ Basic EgressIP environment validation successful!")

except Exception as e:
print(f"❌ Test failed with error: {e}")
except Exception as e:
print(f"❌ Test failed with error: {e}")

if __name__ == "__main__":
asyncio.run(test_egressip_basic())
if __name__ == "__main__":
asyncio.run(test_egressip_basic())
118 changes: 59 additions & 59 deletions test/test_egressip_metrics_fixed.py
Original file line number Diff line number Diff line change
@@ -1,60 +1,60 @@
#!/usr/bin/env python3
"""
Fixed EgressIP Metrics Test - Handle missing Prometheus URL
"""
import asyncio
import sys
import os

# Add current directory to Python path
sys.path.insert(0, os.getcwd())

try:
from tools.utils.promql_basequery import PrometheusBaseQuery
from tools.utils.promql_utility import mcpToolsUtility

# Try to create PrometheusBaseQuery with a default URL
try:
# Common Prometheus URLs in OpenShift
prometheus_urls = [
"http://prometheus-k8s.openshift-monitoring.svc:9090",
"https://prometheus-k8s.openshift-monitoring.svc:9090",
"http://localhost:9090",
None # Try without URL as fallback
]

prometheus_query = None
for url in prometheus_urls:
try:
if url is None:
# Try without arguments
prometheus_query = PrometheusBaseQuery()
else:
prometheus_query = PrometheusBaseQuery(url)
print(f"✅ PrometheusBaseQuery created with: {url or 'default'}")
break
except Exception as e:
print(f"⚠️ Failed with URL {url}: {e}")
continue

if prometheus_query is None:
print("❌ Could not create PrometheusBaseQuery with any URL")
sys.exit(1)

# Try to create mcpToolsUtility
mcp_utility = mcpToolsUtility()
print("✅ mcpToolsUtility created successfully")

# Now try to create a simplified EgressIP metrics collector
from tools.egressip.egressip_metrics_collector import EgressIPMetricsCollector

# We'll modify the class initialization to handle this
print("⚠️ EgressIPMetricsCollector needs Prometheus URL fix...")

except Exception as e:
print(f"❌ Error creating utilities: {e}")

except Exception as e:
print(f"❌ Import error: {e}")

print("Test completed!")
"""
Fixed EgressIP Metrics Test - Handle missing Prometheus URL
"""
import asyncio
import sys
import os

# Add current directory to Python path
sys.path.insert(0, os.getcwd())

try:
from tools.utils.promql_basequery import PrometheusBaseQuery
from tools.utils.promql_utility import mcpToolsUtility

# Try to create PrometheusBaseQuery with a default URL
try:
# Common Prometheus URLs in OpenShift
prometheus_urls = [
"http://prometheus-k8s.openshift-monitoring.svc:9090",
"https://prometheus-k8s.openshift-monitoring.svc:9090",
"http://localhost:9090",
None # Try without URL as fallback
]

prometheus_query = None
for url in prometheus_urls:
try:
if url is None:
# Try without arguments
prometheus_query = PrometheusBaseQuery()
else:
prometheus_query = PrometheusBaseQuery(url)
print(f"✅ PrometheusBaseQuery created with: {url or 'default'}")
break
except Exception as e:
print(f"⚠️ Failed with URL {url}: {e}")
continue

if prometheus_query is None:
print("❌ Could not create PrometheusBaseQuery with any URL")
sys.exit(1)

# Try to create mcpToolsUtility
mcp_utility = mcpToolsUtility()
print("✅ mcpToolsUtility created successfully")

# Now try to create a simplified EgressIP metrics collector
from tools.egressip.egressip_metrics_collector import EgressIPMetricsCollector

# We'll modify the class initialization to handle this
print("⚠️ EgressIPMetricsCollector needs Prometheus URL fix...")

except Exception as e:
print(f"❌ Error creating utilities: {e}")

except Exception as e:
print(f"❌ Import error: {e}")

print("Test completed!")
Binary file added test_egressip_metrics.db
Binary file not shown.