|
30 | 30 | MCTPD_MCTP_I = 'au.com.codeconstruct.MCTP.BusOwner1' |
31 | 31 | MCTPD_ENDPOINT_I = 'au.com.codeconstruct.MCTP.Endpoint1' |
32 | 32 | MCTPD_ENDPOINT_BRIDGE_I = 'au.com.codeconstruct.MCTP.Bridge1' |
| 33 | +OPENBMC_UUID_I = 'xyz.openbmc_project.Common.UUID' |
33 | 34 | DBUS_OBJECT_MANAGER_I = 'org.freedesktop.DBus.ObjectManager' |
34 | 35 | DBUS_PROPERTIES_I = 'org.freedesktop.DBus.Properties' |
35 | 36 |
|
@@ -2396,3 +2397,340 @@ async def test_iface_config_match_path_none(dbus, sysnet, nursery): |
2396 | 2397 |
|
2397 | 2398 | res = await mctpd.stop_mctpd() |
2398 | 2399 | assert res == 0 |
| 2400 | + |
| 2401 | + |
| 2402 | +async def _setup_bridge_with_downstream( |
| 2403 | + dbus, sysnet, nursery, num_downstream=1, downstream_factory=None |
| 2404 | +): |
| 2405 | + """Start mctpd, assign a bridge endpoint, wait for downstream discovery. |
| 2406 | +
|
| 2407 | + downstream_factory(iface) may be given to construct each downstream |
| 2408 | + endpoint; by default a plain Endpoint is used. |
| 2409 | + """ |
| 2410 | + _DOWNSTREAM_POLL_MS = 2500 |
| 2411 | + config = f""" |
| 2412 | + [bus-owner] |
| 2413 | + endpoint_poll_ms = {_DOWNSTREAM_POLL_MS} |
| 2414 | + """ |
| 2415 | + mctpd = MctpdWrapper(dbus, sysnet, config=config) |
| 2416 | + await mctpd.start_mctpd(nursery) |
| 2417 | + |
| 2418 | + iface = mctpd.system.interfaces[0] |
| 2419 | + bridge_ep = mctpd.network.endpoints[0] |
| 2420 | + mctp = await mctpd_mctp_iface_obj(dbus, iface) |
| 2421 | + |
| 2422 | + downstream_eps = [] |
| 2423 | + for _ in range(num_downstream): |
| 2424 | + if downstream_factory: |
| 2425 | + bep = downstream_factory(iface) |
| 2426 | + else: |
| 2427 | + bep = Endpoint(iface, bytes(), types=[0]) |
| 2428 | + mctpd.network.add_endpoint(bep) |
| 2429 | + bridge_ep.add_bridged_ep(bep) |
| 2430 | + downstream_eps.append(bep) |
| 2431 | + |
| 2432 | + # Subscribe to InterfacesAdded AFTER assign_endpoint returns so we don't |
| 2433 | + # accidentally match the bridge's own Endpoint1 signal (emitted before its |
| 2434 | + # separate Bridge1 signal, so it would pass the downstream filter). |
| 2435 | + (_, _, _, new) = await mctp.call_assign_endpoint(bridge_ep.lladdr) |
| 2436 | + assert new |
| 2437 | + |
| 2438 | + mctp_obj = await dbus.get_proxy_object(MCTPD_C, MCTPD_MCTP_P) |
| 2439 | + mctp_objmgr = await mctp_obj.get_interface(DBUS_OBJECT_MANAGER_I) |
| 2440 | + |
| 2441 | + downstream_paths = [] |
| 2442 | + discovered = trio.Semaphore(initial_value=0) |
| 2443 | + |
| 2444 | + def ep_added(ep_path, content): |
| 2445 | + if ( |
| 2446 | + MCTPD_ENDPOINT_I in content |
| 2447 | + and MCTPD_ENDPOINT_BRIDGE_I not in content |
| 2448 | + ): |
| 2449 | + downstream_paths.append(ep_path) |
| 2450 | + discovered.release() |
| 2451 | + |
| 2452 | + await mctp_objmgr.on_interfaces_added(ep_added) |
| 2453 | + |
| 2454 | + with trio.move_on_after(_DOWNSTREAM_POLL_MS / 1000 * 3) as scope: |
| 2455 | + for _ in range(num_downstream): |
| 2456 | + await discovered.acquire() |
| 2457 | + |
| 2458 | + assert not scope.cancelled_caught, ( |
| 2459 | + "Timed out waiting for downstream EP discovery" |
| 2460 | + ) |
| 2461 | + |
| 2462 | + return mctpd, bridge_ep, downstream_eps, downstream_paths |
| 2463 | + |
| 2464 | + |
| 2465 | +async def test_recover_downstream_present( |
| 2466 | + dbus, sysnet, nursery, autojump_clock |
| 2467 | +): |
| 2468 | + """Test Downstream peer still alive: recovery transitions Connectivity to Available.""" |
| 2469 | + _DOWNSTREAM_TRECLAIM = 5 |
| 2470 | + ( |
| 2471 | + mctpd, |
| 2472 | + bridge_ep, |
| 2473 | + downstream_eps, |
| 2474 | + downstream_paths, |
| 2475 | + ) = await _setup_bridge_with_downstream(dbus, sysnet, nursery) |
| 2476 | + |
| 2477 | + ds_path = downstream_paths[0] |
| 2478 | + ep_obj = await dbus.get_proxy_object(MCTPD_C, ds_path) |
| 2479 | + ep_props = await ep_obj.get_interface(DBUS_PROPERTIES_I) |
| 2480 | + ep_cc = await ep_obj.get_interface(MCTPD_ENDPOINT_I) |
| 2481 | + |
| 2482 | + recovered = trio.Semaphore(initial_value=0) |
| 2483 | + |
| 2484 | + def on_connectivity_changed(iface, changed, _invalidated): |
| 2485 | + if iface == MCTPD_ENDPOINT_I and 'Connectivity' in changed: |
| 2486 | + if changed['Connectivity'].value == 'Available': |
| 2487 | + recovered.release() |
| 2488 | + |
| 2489 | + await ep_props.on_properties_changed(on_connectivity_changed) |
| 2490 | + await ep_cc.call_recover() |
| 2491 | + |
| 2492 | + with trio.move_on_after(4 * _DOWNSTREAM_TRECLAIM) as scope: |
| 2493 | + await recovered.acquire() |
| 2494 | + |
| 2495 | + assert not scope.cancelled_caught, ( |
| 2496 | + "Downstream peer did not recover to Available" |
| 2497 | + ) |
| 2498 | + |
| 2499 | + res = await mctpd.stop_mctpd() |
| 2500 | + assert res == 0 |
| 2501 | + |
| 2502 | + |
| 2503 | +async def test_recover_downstream_no_get_uuid( |
| 2504 | + dbus, sysnet, nursery, autojump_clock |
| 2505 | +): |
| 2506 | + """Test a downstream peer that does not implement Get Endpoint UUID: |
| 2507 | + a successful liveness probe is sufficient for recovery.""" |
| 2508 | + _DOWNSTREAM_TRECLAIM = 5 |
| 2509 | + ( |
| 2510 | + mctpd, |
| 2511 | + bridge_ep, |
| 2512 | + downstream_eps, |
| 2513 | + downstream_paths, |
| 2514 | + ) = await _setup_bridge_with_downstream( |
| 2515 | + dbus, |
| 2516 | + sysnet, |
| 2517 | + nursery, |
| 2518 | + downstream_factory=lambda iface: CommandUnimplementedEndpoint( |
| 2519 | + 0x03, iface, bytes(), types=[0] |
| 2520 | + ), |
| 2521 | + ) |
| 2522 | + |
| 2523 | + ds_path = downstream_paths[0] |
| 2524 | + ep_obj = await dbus.get_proxy_object(MCTPD_C, ds_path) |
| 2525 | + ep_props = await ep_obj.get_interface(DBUS_PROPERTIES_I) |
| 2526 | + ep_cc = await ep_obj.get_interface(MCTPD_ENDPOINT_I) |
| 2527 | + |
| 2528 | + mctp_obj = await dbus.get_proxy_object(MCTPD_C, MCTPD_MCTP_P) |
| 2529 | + mctp_objmgr = await mctp_obj.get_interface(DBUS_OBJECT_MANAGER_I) |
| 2530 | + |
| 2531 | + recovered = trio.Semaphore(initial_value=0) |
| 2532 | + removed = [] |
| 2533 | + |
| 2534 | + def on_connectivity_changed(iface, changed, _invalidated): |
| 2535 | + if iface == MCTPD_ENDPOINT_I and 'Connectivity' in changed: |
| 2536 | + if changed['Connectivity'].value == 'Available': |
| 2537 | + recovered.release() |
| 2538 | + |
| 2539 | + def on_removed(path, interfaces): |
| 2540 | + if path == ds_path: |
| 2541 | + removed.append(path) |
| 2542 | + |
| 2543 | + await ep_props.on_properties_changed(on_connectivity_changed) |
| 2544 | + await mctp_objmgr.on_interfaces_removed(on_removed) |
| 2545 | + await ep_cc.call_recover() |
| 2546 | + |
| 2547 | + with trio.move_on_after(4 * _DOWNSTREAM_TRECLAIM) as scope: |
| 2548 | + await recovered.acquire() |
| 2549 | + |
| 2550 | + assert not scope.cancelled_caught, ( |
| 2551 | + "Downstream peer without Get Endpoint UUID did not recover" |
| 2552 | + ) |
| 2553 | + assert not removed, "Downstream peer was removed during recovery" |
| 2554 | + |
| 2555 | + res = await mctpd.stop_mctpd() |
| 2556 | + assert res == 0 |
| 2557 | + |
| 2558 | + |
| 2559 | +async def test_recover_downstream_removed( |
| 2560 | + dbus, sysnet, nursery, autojump_clock |
| 2561 | +): |
| 2562 | + """Test if downstream peer gone while bridge is up: peer is removed after all retries.""" |
| 2563 | + _DOWNSTREAM_TRECLAIM = 5 |
| 2564 | + ( |
| 2565 | + mctpd, |
| 2566 | + bridge_ep, |
| 2567 | + downstream_eps, |
| 2568 | + downstream_paths, |
| 2569 | + ) = await _setup_bridge_with_downstream(dbus, sysnet, nursery) |
| 2570 | + |
| 2571 | + ds_path = downstream_paths[0] |
| 2572 | + ep_obj = await dbus.get_proxy_object(MCTPD_C, ds_path) |
| 2573 | + ep_props = await ep_obj.get_interface(DBUS_PROPERTIES_I) |
| 2574 | + ep_cc = await ep_obj.get_interface(MCTPD_ENDPOINT_I) |
| 2575 | + |
| 2576 | + degraded = trio.Semaphore(initial_value=0) |
| 2577 | + removed = trio.Semaphore(initial_value=0) |
| 2578 | + |
| 2579 | + def on_connectivity_changed(iface, changed, _invalidated): |
| 2580 | + if iface == MCTPD_ENDPOINT_I and 'Connectivity' in changed: |
| 2581 | + if changed['Connectivity'].value == 'Degraded': |
| 2582 | + degraded.release() |
| 2583 | + |
| 2584 | + await ep_props.on_properties_changed(on_connectivity_changed) |
| 2585 | + |
| 2586 | + mctp_obj = await dbus.get_proxy_object(MCTPD_C, MCTPD_MCTP_P) |
| 2587 | + mctp_objmgr = await mctp_obj.get_interface(DBUS_OBJECT_MANAGER_I) |
| 2588 | + |
| 2589 | + def on_ep_removed(ep_path, interfaces): |
| 2590 | + if ep_path == ds_path and MCTPD_ENDPOINT_I in interfaces: |
| 2591 | + removed.release() |
| 2592 | + |
| 2593 | + await mctp_objmgr.on_interfaces_removed(on_ep_removed) |
| 2594 | + |
| 2595 | + # Disconnect downstream — bridge mock stops routing EID-addressed packets to it. |
| 2596 | + bridge_ep.bridged_eps.remove(downstream_eps[0]) |
| 2597 | + |
| 2598 | + await ep_cc.call_recover() |
| 2599 | + |
| 2600 | + with trio.move_on_after(4 * _DOWNSTREAM_TRECLAIM) as scope: |
| 2601 | + await removed.acquire() |
| 2602 | + await degraded.acquire() |
| 2603 | + |
| 2604 | + assert not scope.cancelled_caught, ( |
| 2605 | + "Downstream peer was not removed after losing connectivity" |
| 2606 | + ) |
| 2607 | + |
| 2608 | + res = await mctpd.stop_mctpd() |
| 2609 | + assert res == 0 |
| 2610 | + |
| 2611 | + |
| 2612 | +async def test_recover_downstream_bridge_unreachable( |
| 2613 | + dbus, sysnet, nursery, autojump_clock |
| 2614 | +): |
| 2615 | + """Test if bridge unreachable: downstream peer is removed when physical probe fails.""" |
| 2616 | + _DOWNSTREAM_TRECLAIM = 5 |
| 2617 | + ( |
| 2618 | + mctpd, |
| 2619 | + bridge_ep, |
| 2620 | + downstream_eps, |
| 2621 | + downstream_paths, |
| 2622 | + ) = await _setup_bridge_with_downstream(dbus, sysnet, nursery) |
| 2623 | + |
| 2624 | + ds_path = downstream_paths[0] |
| 2625 | + ep_obj = await dbus.get_proxy_object(MCTPD_C, ds_path) |
| 2626 | + ep_props = await ep_obj.get_interface(DBUS_PROPERTIES_I) |
| 2627 | + ep_cc = await ep_obj.get_interface(MCTPD_ENDPOINT_I) |
| 2628 | + |
| 2629 | + degraded = trio.Semaphore(initial_value=0) |
| 2630 | + removed = trio.Semaphore(initial_value=0) |
| 2631 | + |
| 2632 | + def on_connectivity_changed(iface, changed, _invalidated): |
| 2633 | + if iface == MCTPD_ENDPOINT_I and 'Connectivity' in changed: |
| 2634 | + if changed['Connectivity'].value == 'Degraded': |
| 2635 | + degraded.release() |
| 2636 | + |
| 2637 | + await ep_props.on_properties_changed(on_connectivity_changed) |
| 2638 | + |
| 2639 | + mctp_obj = await dbus.get_proxy_object(MCTPD_C, MCTPD_MCTP_P) |
| 2640 | + mctp_objmgr = await mctp_obj.get_interface(DBUS_OBJECT_MANAGER_I) |
| 2641 | + |
| 2642 | + def on_ep_removed(ep_path, interfaces): |
| 2643 | + if ep_path == ds_path and MCTPD_ENDPOINT_I in interfaces: |
| 2644 | + removed.release() |
| 2645 | + |
| 2646 | + await mctp_objmgr.on_interfaces_removed(on_ep_removed) |
| 2647 | + |
| 2648 | + mctpd.network.endpoints.remove(bridge_ep) |
| 2649 | + |
| 2650 | + await ep_cc.call_recover() |
| 2651 | + |
| 2652 | + with trio.move_on_after(4 * _DOWNSTREAM_TRECLAIM) as scope: |
| 2653 | + await removed.acquire() |
| 2654 | + await degraded.acquire() |
| 2655 | + |
| 2656 | + assert not scope.cancelled_caught, ( |
| 2657 | + "Downstream peer was not removed after bridge became unreachable" |
| 2658 | + ) |
| 2659 | + |
| 2660 | + res = await mctpd.stop_mctpd() |
| 2661 | + assert res == 0 |
| 2662 | + |
| 2663 | + |
| 2664 | +async def test_recover_downstream_exchange( |
| 2665 | + dbus, sysnet, nursery, autojump_clock |
| 2666 | +): |
| 2667 | + """Test if bridge reassigns pool EID to a new device, old peer removed, new peer added.""" |
| 2668 | + _DOWNSTREAM_TRECLAIM = 5 |
| 2669 | + ( |
| 2670 | + mctpd, |
| 2671 | + bridge_ep, |
| 2672 | + downstream_eps, |
| 2673 | + downstream_paths, |
| 2674 | + ) = await _setup_bridge_with_downstream(dbus, sysnet, nursery) |
| 2675 | + |
| 2676 | + ds_path = downstream_paths[0] |
| 2677 | + ep_obj = await dbus.get_proxy_object(MCTPD_C, ds_path) |
| 2678 | + ep_props = await ep_obj.get_interface(DBUS_PROPERTIES_I) |
| 2679 | + ep_cc = await ep_obj.get_interface(MCTPD_ENDPOINT_I) |
| 2680 | + |
| 2681 | + degraded = trio.Semaphore(initial_value=0) |
| 2682 | + removed = trio.Semaphore(initial_value=0) |
| 2683 | + added = trio.Semaphore(initial_value=0) |
| 2684 | + added_uuid = [] |
| 2685 | + |
| 2686 | + def on_connectivity_changed(iface, changed, _invalidated): |
| 2687 | + if iface == MCTPD_ENDPOINT_I and 'Connectivity' in changed: |
| 2688 | + if changed['Connectivity'].value == 'Degraded': |
| 2689 | + degraded.release() |
| 2690 | + |
| 2691 | + await ep_props.on_properties_changed(on_connectivity_changed) |
| 2692 | + |
| 2693 | + mctp_obj = await dbus.get_proxy_object(MCTPD_C, MCTPD_MCTP_P) |
| 2694 | + mctp_objmgr = await mctp_obj.get_interface(DBUS_OBJECT_MANAGER_I) |
| 2695 | + |
| 2696 | + def on_ep_removed(ep_path, interfaces): |
| 2697 | + if ep_path == ds_path and MCTPD_ENDPOINT_I in interfaces: |
| 2698 | + removed.release() |
| 2699 | + |
| 2700 | + def on_ep_added(ep_path, content): |
| 2701 | + if ep_path == ds_path and MCTPD_ENDPOINT_I in content: |
| 2702 | + if OPENBMC_UUID_I in content and 'UUID' in content[OPENBMC_UUID_I]: |
| 2703 | + added_uuid.append(content[OPENBMC_UUID_I]['UUID'].value) |
| 2704 | + added.release() |
| 2705 | + |
| 2706 | + await mctp_objmgr.on_interfaces_removed(on_ep_removed) |
| 2707 | + await mctp_objmgr.on_interfaces_added(on_ep_added) |
| 2708 | + |
| 2709 | + old_ds = downstream_eps[0] |
| 2710 | + new_ds = Endpoint(old_ds.iface, bytes(), types=[0]) |
| 2711 | + new_ds.eid = old_ds.eid # same pool EID, fresh UUID |
| 2712 | + |
| 2713 | + bridge_ep.bridged_eps.remove(old_ds) |
| 2714 | + bridge_ep.bridged_eps.append(new_ds) |
| 2715 | + mctpd.network.add_endpoint(new_ds) |
| 2716 | + |
| 2717 | + await ep_cc.call_recover() |
| 2718 | + |
| 2719 | + with trio.move_on_after(4 * _DOWNSTREAM_TRECLAIM) as scope: |
| 2720 | + await removed.acquire() |
| 2721 | + await added.acquire() |
| 2722 | + await degraded.acquire() |
| 2723 | + |
| 2724 | + assert not scope.cancelled_caught, ( |
| 2725 | + "Downstream peer exchange did not emit Remove + Add" |
| 2726 | + ) |
| 2727 | + |
| 2728 | + # Verify the re-added peer carries the new device's UUID, not the old one. |
| 2729 | + assert added_uuid, "InterfacesAdded did not include a UUID property" |
| 2730 | + assert added_uuid[0] == str(new_ds.uuid), ( |
| 2731 | + f"New peer UUID {added_uuid[0]!r} does not match " |
| 2732 | + f"replacement device UUID {new_ds.uuid!r}" |
| 2733 | + ) |
| 2734 | + |
| 2735 | + res = await mctpd.stop_mctpd() |
| 2736 | + assert res == 0 |
0 commit comments