particle-os-tools/test_dbus_properties.py
Joe Particle b31b64d600
Some checks failed
Compile apt-layer (v2) / compile (push) Has been cancelled
fix: Resolve D-Bus property serialization issues
- Fix Deployments property to always return JSON string
- Resolve TypeError and ValueError in D-Bus property serialization
- Add JSON serialization for complex data structures
- Implement fallback values for empty collections
- Update TODO and changelogs to reflect completion
- Ensure full compliance with D-BUS.md and daemon-notes.md
2025-07-16 06:27:39 +00:00

82 lines
No EOL
2.9 KiB
Python

#!/usr/bin/env python3
"""
Test script to verify D-Bus properties are working correctly
"""
import dbus
import json
import sys
def test_dbus_properties():
"""Test D-Bus properties interface"""
try:
# Connect to system bus
bus = dbus.SystemBus()
# Get the daemon object
daemon = bus.get_object('org.debian.aptostree1', '/org/debian/aptostree1')
# Get the properties interface
props = dbus.Interface(daemon, 'org.freedesktop.DBus.Properties')
print("Testing D-Bus properties...")
# Test individual properties
properties_to_test = [
'Booted',
'Path',
'ActiveTransaction',
'ActiveTransactionPath',
'Deployments',
'AutomaticUpdatePolicy'
]
for prop in properties_to_test:
try:
value = props.Get('org.debian.aptostree1.Sysroot', prop)
print(f"{prop}: {value} (type: {type(value).__name__})")
# Special check for Deployments - should be a string
if prop == 'Deployments':
if isinstance(value, str):
print(f" ✓ Deployments is correctly returned as JSON string")
try:
parsed = json.loads(value)
print(f" ✓ JSON is valid: {parsed}")
except json.JSONDecodeError as e:
print(f" ✗ JSON parsing failed: {e}")
else:
print(f" ✗ Deployments should be a string, got {type(value).__name__}")
except Exception as e:
print(f"{prop}: Error - {e}")
# Test GetAll
print("\nTesting GetAll...")
try:
all_props = props.GetAll('org.debian.aptostree1.Sysroot')
print(f"✓ GetAll returned {len(all_props)} properties")
# Check Deployments in GetAll
if 'Deployments' in all_props:
deployments = all_props['Deployments']
if isinstance(deployments, str):
print(f"✓ Deployments in GetAll is correctly a JSON string")
else:
print(f"✗ Deployments in GetAll should be a string, got {type(deployments).__name__}")
else:
print("✗ Deployments not found in GetAll")
except Exception as e:
print(f"✗ GetAll failed: {e}")
except Exception as e:
print(f"Failed to connect to D-Bus: {e}")
return False
return True
if __name__ == "__main__":
print("Testing apt-ostree D-Bus properties...")
success = test_dbus_properties()
sys.exit(0 if success else 1)