particle-os-tools/test_dbus_direct.py
Joe Particle 8c470a56b5 feat: Implement production-ready systemd service best practices
- Update systemd service file with Type=simple and comprehensive locking
- Enhance D-Bus service and policy files for proper activation
- Remove OSTree dependency for test mode compatibility
- Implement automated service file installation and cleanup
- Add comprehensive systemd usage documentation
- Update changelog and TODO to reflect completed systemd improvements
- Service now successfully running under systemd management

This completes the systemd service integration with production-ready
configuration and best practices for daemon lifecycle management.
2025-07-16 16:13:35 +00:00

172 lines
No EOL
5.8 KiB
Python

#!/usr/bin/env python3
"""
Direct D-Bus method testing for apt-ostree
"""
import dbus
import sys
import json
def test_dbus_methods():
"""Test all D-Bus methods directly"""
try:
# Connect to system bus
bus = dbus.SystemBus()
# Get the daemon object
daemon = bus.get_object('org.debian.aptostree1', '/org/debian/aptostree1/Sysroot')
print("=== Testing D-Bus Methods ===")
print()
# Test 1: GetStatus
print("1. Testing GetStatus...")
try:
status = daemon.GetStatus(dbus_interface='org.debian.aptostree1.Sysroot')
print(f" ✓ SUCCESS: {status}")
except Exception as e:
print(f" ✗ FAILED: {e}")
print()
# Test 2: GetOS
print("2. Testing GetOS...")
try:
os_list = daemon.GetOS(dbus_interface='org.debian.aptostree1.Sysroot')
print(f" ✓ SUCCESS: {os_list}")
except Exception as e:
print(f" ✗ FAILED: {e}")
print()
# Test 3: Reload
print("3. Testing Reload...")
try:
daemon.Reload(dbus_interface='org.debian.aptostree1.Sysroot')
print(" ✓ SUCCESS")
except Exception as e:
print(f" ✗ FAILED: {e}")
print()
# Test 4: ReloadConfig
print("4. Testing ReloadConfig...")
try:
daemon.ReloadConfig(dbus_interface='org.debian.aptostree1.Sysroot')
print(" ✓ SUCCESS")
except Exception as e:
print(f" ✗ FAILED: {e}")
print()
# Test 5: RegisterClient
print("5. Testing RegisterClient...")
try:
options = dbus.Dictionary({'id': 'test-client'}, signature='sv')
daemon.RegisterClient(options, dbus_interface='org.debian.aptostree1.Sysroot')
print(" ✓ SUCCESS")
except Exception as e:
print(f" ✗ FAILED: {e}")
print()
# Test 6: InstallPackages
print("6. Testing InstallPackages...")
try:
packages = dbus.Array(['curl'], signature='s')
result = daemon.InstallPackages(packages, False, dbus_interface='org.debian.aptostree1.Sysroot')
print(f" ✓ SUCCESS: {result}")
except Exception as e:
print(f" ✗ FAILED: {e}")
print()
# Test 7: RemovePackages
print("7. Testing RemovePackages...")
try:
packages = dbus.Array(['curl'], signature='s')
result = daemon.RemovePackages(packages, False, dbus_interface='org.debian.aptostree1.Sysroot')
print(f" ✓ SUCCESS: {result}")
except Exception as e:
print(f" ✗ FAILED: {e}")
print()
# Test 8: Deploy
print("8. Testing Deploy...")
try:
options = dbus.Dictionary({'test': 'value'}, signature='sv')
result = daemon.Deploy('test-layer', options, dbus_interface='org.debian.aptostree1.Sysroot')
print(f" ✓ SUCCESS: {result}")
except Exception as e:
print(f" ✗ FAILED: {e}")
print()
# Test 9: Upgrade
print("9. Testing Upgrade...")
try:
options = dbus.Dictionary({'test': 'value'}, signature='sv')
result = daemon.Upgrade(options, dbus_interface='org.debian.aptostree1.Sysroot')
print(f" ✓ SUCCESS: {result}")
except Exception as e:
print(f" ✗ FAILED: {e}")
print()
# Test 10: Rollback
print("10. Testing Rollback...")
try:
options = dbus.Dictionary({'test': 'value'}, signature='sv')
result = daemon.Rollback(options, dbus_interface='org.debian.aptostree1.Sysroot')
print(f" ✓ SUCCESS: {result}")
except Exception as e:
print(f" ✗ FAILED: {e}")
print()
# Test 11: CreateComposeFSLayer
print("11. Testing CreateComposeFSLayer...")
try:
result = daemon.CreateComposeFSLayer('/tmp/test-source', '/tmp/test-layer', '/tmp/test-digest', dbus_interface='org.debian.aptostree1.Sysroot')
print(f" ✓ SUCCESS: {result}")
except Exception as e:
print(f" ✗ FAILED: {e}")
print()
# Test 12: UnregisterClient
print("12. Testing UnregisterClient...")
try:
options = dbus.Dictionary({'id': 'test-client'}, signature='sv')
daemon.UnregisterClient(options, dbus_interface='org.debian.aptostree1.Sysroot')
print(" ✓ SUCCESS")
except Exception as e:
print(f" ✗ FAILED: {e}")
print()
# Test Properties
print("=== Testing D-Bus Properties ===")
print()
# Get properties interface
props = dbus.Interface(daemon, 'org.freedesktop.DBus.Properties')
# Test Sysroot properties
properties_to_test = [
'Booted', 'Path', 'ActiveTransaction', 'ActiveTransactionPath',
'Deployments', 'AutomaticUpdatePolicy'
]
for prop in properties_to_test:
print(f"Testing property: {prop}")
try:
value = props.Get('org.debian.aptostree1.Sysroot', prop)
print(f" ✓ SUCCESS: {value}")
except Exception as e:
print(f" ✗ FAILED: {e}")
print()
print("=== Testing Complete ===")
except dbus.exceptions.DBusException as e:
print(f"D-Bus error: {e}")
return 1
except Exception as e:
print(f"Error: {e}")
return 1
return 0
if __name__ == "__main__":
sys.exit(test_dbus_methods())