Repository: firecracker-microvm/firecracker
File: tests/framework/microvm.py (Python)

Code before:
        # Create network interfaces.
        for iface in snapshot.net_ifaces:
            self.add_net_iface(iface, api=False)

        mem_backend = {"backend_type": "File", "backend_path": str(jailed_mem)}
        if uffd_path is not None:
            mem_backend = {"backend_type": "Uffd", "backend_path": str(uffd_path)}

        for key, value in snapshot.meta.items():
            setattr(self, key, value)
        # Adjust things just in case
        self.kernel_file = Path(self.kernel_file)

        iface_overrides = []
        if rename_interfaces is not None:
            iface_overrides = [
                {"iface_id": k, "host_dev_name": v}
                for k, v in rename_interfaces.items()
            ]

        self.api.snapshot_load.put(
            mem_backend=mem_backend,
            snapshot_path=str(jailed_vmstate),
            enable_diff_snapshots=snapshot.is_diff,
            resume_vm=resume,
            network_overrides=iface_overrides,
        )
        # This is not a "wait for boot", but rather a "VM still works after restoration"
        if snapshot.net_ifaces and resume:
            self.wait_for_ssh_up()
        return jailed_snapshot

    def enable_entropy_device(self):
        """Enable entropy device for microVM"""
        self.api.entropy.put()

    def restore_from_path(self, snap_dir: Path, **kwargs):
        """Restore snapshot from a path"""
        return self.restore_from_snapshot(Snapshot.load_from(snap_dir), **kwargs)

    @lru_cache
    def ssh_iface(self, iface_idx=0):
        """Return a cached SSH connection on a given interface id."""
        guest_ip = list(self.iface.values())[iface_idx]["iface"].guest_ip
        self.ssh_key = Path(self.ssh_key)
        connection = net_tools.SSHConnection(
            netns=self.netns.id,
            ssh_key=self.ssh_key,
            user="root",
            host=guest_ip,
            control_path=Path(self.chroot()) / f"ssh-{iface_idx}.sock",

Review comment (suggestion):
To avoid sending `network_overrides` if it's empty do something like this.

```
kwargs = {}
if network_overrides:
    kwargs["network_overrides"] = network_overrides

self.api.snapshot_load.put(
    ...
    **kwargs,
)
```

Code after:
        for disk in snapshot_disks:
            jailed_disks.append(self.create_jailed_resource(disk))
        self.disks = snapshot.disks
        self.ssh_key = snapshot.ssh_key

        # Create network interfaces.
        for iface in snapshot.net_ifaces:
            self.add_net_iface(iface, api=False)

        mem_backend = {"backend_type": "File", "backend_path": str(jailed_mem)}
        if uffd_path is not None:
            mem_backend = {"backend_type": "Uffd", "backend_path": str(uffd_path)}

        for key, value in snapshot.meta.items():
            setattr(self, key, value)
        # Adjust things just in case
        self.kernel_file = Path(self.kernel_file)

        iface_overrides = []
        if rename_interfaces is not None:
            iface_overrides = [
                {"iface_id": k, "host_dev_name": v}
                for k, v in rename_interfaces.items()
            ]

        optional_kwargs = {}
        if iface_overrides:
            # For backwards compatibility ab testing we want to avoid adding
            # new parameters until we have a release baseline with the new
            # parameter. Once the release baseline has moved, this assignment
            # can be inline in the snapshot_load command below
            optional_kwargs["network_overrides"] = iface_overrides

        self.api.snapshot_load.put(
            mem_backend=mem_backend,
            snapshot_path=str(jailed_vmstate),
            enable_diff_snapshots=snapshot.is_diff,
            resume_vm=resume,
            **optional_kwargs,
        )
        # This is not a "wait for boot", but rather a "VM still works after restoration"
        if snapshot.net_ifaces and resume:
            self.wait_for_ssh_up()
        return jailed_snapshot

    def enable_entropy_device(self):
        """Enable entropy device for microVM"""
        self.api.entropy.put()

    def restore_from_path(self, snap_dir: Path, **kwargs):
        """Restore snapshot from a path"""