#!/bin/bash # D-Bus Method Testing Script for apt-ostree # Tests all available D-Bus methods set -e # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color # Configuration SERVICE_NAME="org.debian.aptostree1" SYSROOT_PATH="/org/debian/aptostree1/Sysroot" OS_PATH="/org/debian/aptostree1/OS/default" echo -e "${BLUE}=== apt-ostree D-Bus Method Testing ===${NC}" echo # Function to test a D-Bus method test_method() { local method_name="$1" local interface="$2" local path="$3" local args="$4" local description="$5" echo -e "${YELLOW}Testing: $description${NC}" echo "Method: $method_name" echo "Interface: $interface" echo "Path: $path" echo "Args: $args" echo if busctl call "$SERVICE_NAME" "$path" "$interface" "$method_name" $args 2>/dev/null; then echo -e "${GREEN}✓ SUCCESS${NC}" else echo -e "${RED}✗ FAILED${NC}" fi echo } # Function to test a D-Bus property test_property() { local property_name="$1" local interface="$2" local path="$3" local description="$4" echo -e "${YELLOW}Testing Property: $description${NC}" echo "Property: $property_name" echo "Interface: $interface" echo "Path: $path" echo if busctl get-property "$SERVICE_NAME" "$path" "$interface" "$property_name" 2>/dev/null; then echo -e "${GREEN}✓ SUCCESS${NC}" else echo -e "${RED}✗ FAILED${NC}" fi echo } # Check if daemon is running echo -e "${BLUE}Checking daemon status...${NC}" if ! busctl list | grep -q "$SERVICE_NAME"; then echo -e "${RED}Error: Daemon not found on D-Bus${NC}" echo "Make sure the daemon is running with:" echo "sudo python3 src/apt-ostree.py/python/apt_ostree.py --daemon" exit 1 fi echo -e "${GREEN}✓ Daemon found on D-Bus${NC}" echo # Test 1: GetStatus method test_method "GetStatus" "org.debian.aptostree1.Sysroot" "$SYSROOT_PATH" "" "Get daemon status" # Test 2: GetOS method test_method "GetOS" "org.debian.aptostree1.Sysroot" "$SYSROOT_PATH" "" "Get OS instances" # Test 3: Reload method test_method "Reload" "org.debian.aptostree1.Sysroot" "$SYSROOT_PATH" "" "Reload sysroot state" # Test 4: ReloadConfig method test_method "ReloadConfig" "org.debian.aptostree1.Sysroot" "$SYSROOT_PATH" "" "Reload configuration" # Test 5: RegisterClient method test_method "RegisterClient" "org.debian.aptostree1.Sysroot" "$SYSROOT_PATH" "dict:string:test,string:test-client" "Register client" # Test 6: InstallPackages method (with curl as test package) test_method "InstallPackages" "org.debian.aptostree1.Sysroot" "$SYSROOT_PATH" "array:string:curl boolean:false" "Install packages (curl)" # Test 7: RemovePackages method (with curl as test package) test_method "RemovePackages" "org.debian.aptostree1.Sysroot" "$SYSROOT_PATH" "array:string:curl boolean:false" "Remove packages (curl)" # Test 8: Deploy method test_method "Deploy" "org.debian.aptostree1.Sysroot" "$SYSROOT_PATH" "string:test-layer dict:string:test,string:value" "Deploy layer" # Test 9: Upgrade method test_method "Upgrade" "org.debian.aptostree1.Sysroot" "$SYSROOT_PATH" "dict:string:test,string:value" "System upgrade" # Test 10: Rollback method test_method "Rollback" "org.debian.aptostree1.Sysroot" "$SYSROOT_PATH" "dict:string:test,string:value" "System rollback" # Test 11: CreateComposeFSLayer method test_method "CreateComposeFSLayer" "org.debian.aptostree1.Sysroot" "$SYSROOT_PATH" "string:/tmp/test-source string:/tmp/test-layer string:/tmp/test-digest" "Create ComposeFS layer" # Test 12: UnregisterClient method test_method "UnregisterClient" "org.debian.aptostree1.Sysroot" "$SYSROOT_PATH" "dict:string:test,string:test-client" "Unregister client" # Test Properties echo -e "${BLUE}=== Testing D-Bus Properties ===${NC}" echo # Test Sysroot properties test_property "Booted" "org.debian.aptostree1.Sysroot" "$SYSROOT_PATH" "Booted property" test_property "Path" "org.debian.aptostree1.Sysroot" "$SYSROOT_PATH" "Path property" test_property "ActiveTransaction" "org.debian.aptostree1.Sysroot" "$SYSROOT_PATH" "ActiveTransaction property" test_property "ActiveTransactionPath" "org.debian.aptostree1.Sysroot" "$SYSROOT_PATH" "ActiveTransactionPath property" test_property "Deployments" "org.debian.aptostree1.Sysroot" "$SYSROOT_PATH" "Deployments property" test_property "AutomaticUpdatePolicy" "org.debian.aptostree1.Sysroot" "$SYSROOT_PATH" "AutomaticUpdatePolicy property" # Test OS properties (if OS interface exists) test_property "BootedDeployment" "org.debian.aptostree1.OS" "$OS_PATH" "BootedDeployment property" test_property "DefaultDeployment" "org.debian.aptostree1.OS" "$OS_PATH" "DefaultDeployment property" test_property "RollbackDeployment" "org.debian.aptostree1.OS" "$OS_PATH" "RollbackDeployment property" test_property "CachedUpdate" "org.debian.aptostree1.OS" "$OS_PATH" "CachedUpdate property" test_property "HasCachedUpdateRpmDiff" "org.debian.aptostree1.OS" "$OS_PATH" "HasCachedUpdateRpmDiff property" test_property "Name" "org.debian.aptostree1.OS" "$OS_PATH" "Name property" # Test OS methods (if OS interface exists) echo -e "${BLUE}=== Testing OS Interface Methods ===${NC}" echo test_method "GetDeployments" "org.debian.aptostree1.OS" "$OS_PATH" "" "Get deployments" test_method "GetBootedDeployment" "org.debian.aptostree1.OS" "$OS_PATH" "" "Get booted deployment" test_method "Deploy" "org.debian.aptostree1.OS" "$OS_PATH" "string:test-revision dict:string:test,string:value" "Deploy revision" test_method "Upgrade" "org.debian.aptostree1.OS" "$OS_PATH" "dict:string:test,string:value" "OS upgrade" test_method "Rollback" "org.debian.aptostree1.OS" "$OS_PATH" "dict:string:test,string:value" "OS rollback" test_method "PkgChange" "org.debian.aptostree1.OS" "$OS_PATH" "dict:string:test,string:value" "Package change" test_method "Rebase" "org.debian.aptostree1.OS" "$OS_PATH" "string:test-refspec dict:string:test,string:value" "Rebase" # Test D-Bus introspection echo -e "${BLUE}=== Testing D-Bus Introspection ===${NC}" echo echo -e "${YELLOW}Introspecting Sysroot interface...${NC}" if busctl introspect "$SERVICE_NAME" "$SYSROOT_PATH" 2>/dev/null | head -20; then echo -e "${GREEN}✓ Introspection successful${NC}" else echo -e "${RED}✗ Introspection failed${NC}" fi echo echo -e "${YELLOW}Introspecting OS interface...${NC}" if busctl introspect "$SERVICE_NAME" "$OS_PATH" 2>/dev/null | head -20; then echo -e "${GREEN}✓ Introspection successful${NC}" else echo -e "${RED}✗ Introspection failed${NC}" fi echo echo -e "${BLUE}=== Testing Complete ===${NC}" echo -e "${GREEN}All D-Bus method tests completed!${NC}"