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

Code before:
        if api:
            self.api.network.put(
                iface_id=iface.dev_name,
                host_dev_name=iface.tap_name,
                guest_mac=iface.guest_mac,
                **kwargs,
            )

        return iface

    def start(self):
        """Start the microvm.

        This function validates that the microvm boot succeeds.
        """
        # Check that the VM has not started yet
        assert self.state == "Not started"

        self.api.actions.put(action_type="InstanceStart")

        # Check that the VM has started
        assert self.state == "Running"

        if self.iface:
            self.wait_for_up()

    def pause(self):
        """Pauses the microVM"""
        self.api.vm.patch(state="Paused")

    def resume(self):
        """Resume the microVM"""
        self.api.vm.patch(state="Resumed")

    def make_snapshot(
        self,
        snapshot_type: SnapshotType | str,
        *,
        mem_path: str = "mem",
        vmstate_path="vmstate",
    ):
        """Create a Snapshot object from a microvm.

        The snapshot's memory and vstate files will be saved at the specified paths
        relative to the Microvm's chroot.

        It pauses the microvm before taking the snapshot.
        """
        snapshot_type = SnapshotType(snapshot_type)
        self.pause()
        self.api.snapshot_create.put(

Review comment (suggestion):
Maybe add a comment saying we explicitly wait for SSH to be up. We could have encoded it in the method as `.wait_for_ssh_up` but oh well :)

Just occurred to me that we may want a `wait_for_ssh` parameter maybe at some point. But we don't need it now, so out of scope.

Code after:
        # If api, call it... there may be cases when we don't want it, for
        # example during restore
        if api:
            self.api.network.put(
                iface_id=iface.dev_name,
                host_dev_name=iface.tap_name,
                guest_mac=iface.guest_mac,
                **kwargs,
            )

        return iface

    def start(self):
        """Start the microvm.

        This function validates that the microvm boot succeeds.
        """
        # Check that the VM has not started yet
        assert self.state == "Not started"

        self.api.actions.put(action_type="InstanceStart")

        # Check that the VM has started
        assert self.state == "Running"

        if self.iface:
            self.wait_for_up()

    def pause(self):
        """Pauses the microVM"""
        self.api.vm.patch(state="Paused")

    def resume(self):
        """Resume the microVM"""
        self.api.vm.patch(state="Resumed")

    def make_snapshot(
        self,
        snapshot_type: SnapshotType | str,
        *,
        mem_path: str = "mem",
        vmstate_path="vmstate",
    ):
        """Create a Snapshot object from a microvm.

        The snapshot's memory and vstate files will be saved at the specified paths
        relative to the Microvm's chroot.

        It pauses the microvm before taking the snapshot.
        """
        snapshot_type = SnapshotType(snapshot_type)