Skip to content

feat(qemu): add _extra_qemu_args() hook#122

Merged
ltekieli merged 1 commit into
eclipse-score:mainfrom
Rahul-Sutariya:rasu_extend_itf_qemu_class
Jul 17, 2026
Merged

feat(qemu): add _extra_qemu_args() hook#122
ltekieli merged 1 commit into
eclipse-score:mainfrom
Rahul-Sutariya:rasu_extend_itf_qemu_class

Conversation

@Rahul-Sutariya

@Rahul-Sutariya Rahul-Sutariya commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

feat(qemu): add _extra_qemu_args() hook

Add a single overridable hook _extra_qemu_args() to the Qemu class
that returns additional command-line flags to append after the base
devices. Defaults to [] so existing behavior is unchanged.

@lurtz

lurtz commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

@Rahul-Sutariya What a coincidence. I am also working on extending the QEMU code: #123

@lurtz lurtz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look ok to me, but I am not really a code owner of ITF, thus not approving.

We should have a discussion what features the QEMU plugin should have and how its extension points look like.

@Rahul-Sutariya

Copy link
Copy Markdown
Contributor Author

Changes look ok to me, but I am not really a code owner of ITF, thus not approving.

We should have a discussion what features the QEMU plugin should have and how its extension points look like.

Hi @lurtz, thanks for the feedback.

This PR is focused on making the Qemu class and QemuProcess extensible so that downstream plugins can add custom QEMU devices (for example, ivshmem) through inheritance and dependency injection, instead of having to duplicate the command assembly logic.

Regarding the broader discussion about the QEMU plugin's features and extension points, I think that is a separate design topic and outside the scope of this PR. I'm probably not the right person to drive that discussion, so I'd prefer to keep this change focused on the extensibility improvements it introduces.

@Rahul-Sutariya
Rahul-Sutariya force-pushed the rasu_extend_itf_qemu_class branch 2 times, most recently from a748f87 to fea832a Compare July 16, 2026 12:43
lurtz
lurtz previously approved these changes Jul 16, 2026

@lurtz lurtz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approving because it looks like nobody else is looking at this PR. Might there be another refactoring of this code or is it final now?

@Rahul-Sutariya

Copy link
Copy Markdown
Contributor Author

approving because it looks like nobody else is looking at this PR. Might there be another refactoring of this code or is it final now?

This is final one, Thanks for reveiw!

@lurtz
lurtz added this pull request to the merge queue Jul 17, 2026
@ltekieli
ltekieli removed this pull request from the merge queue due to a manual request Jul 17, 2026
@ltekieli

Copy link
Copy Markdown
Member

@lurtz I will review today.

@ltekieli ltekieli left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR adds two extension points: _extra_qemu_args() on Qemu, and qemu=None injection on QemuProcess.

For the stated goal of allowing downstream plugins to customize QEMU command-line flags, the _extra_qemu_args() hook looks like the key API change. The additional QemuProcess(qemu=...) constructor parameter seems less necessary, because a downstream plugin can already subclass QemuProcess and replace the constructed QEMU instance after calling super().__init__():

class CustomQemuProcess(QemuProcess):
    def __init__(self, path_to_qemu_image, available_ram, available_cores, **kwargs):
        super().__init__(path_to_qemu_image, available_ram, available_cores, **kwargs)
        self._qemu = CustomQemu(
            path_to_qemu_image,
            available_ram,
            available_cores,
            network_adapters=self._network_adapters,
            port_forwarding=self._port_forwarding,
        )

Unless this PR has a concrete composition or testability use case for injecting a prebuilt QEMU object, I would keep the public surface smaller and drop the qemu= constructor change. That would leave the PR focused on the Qemu command-line extension hook, with clearer ownership of the QEMU process lifecycle.

Add a single overridable hook `_extra_qemu_args()` to the Qemu class
that returns additional command-line flags to append after the base
devices. Defaults to [] so existing behavior is unchanged.
@Rahul-Sutariya

Copy link
Copy Markdown
Contributor Author

This PR adds two extension points: _extra_qemu_args() on Qemu, and qemu=None injection on QemuProcess.

For the stated goal of allowing downstream plugins to customize QEMU command-line flags, the _extra_qemu_args() hook looks like the key API change. The additional QemuProcess(qemu=...) constructor parameter seems less necessary, because a downstream plugin can already subclass QemuProcess and replace the constructed QEMU instance after calling super().__init__():

class CustomQemuProcess(QemuProcess):
    def __init__(self, path_to_qemu_image, available_ram, available_cores, **kwargs):
        super().__init__(path_to_qemu_image, available_ram, available_cores, **kwargs)
        self._qemu = CustomQemu(
            path_to_qemu_image,
            available_ram,
            available_cores,
            network_adapters=self._network_adapters,
            port_forwarding=self._port_forwarding,
        )

Unless this PR has a concrete composition or testability use case for injecting a prebuilt QEMU object, I would keep the public surface smaller and drop the qemu= constructor change. That would leave the PR focused on the Qemu command-line extension hook, with clearer ownership of the QEMU process lifecycle.

Agreed — dropped the [qemu] constructor change., Thanks!

@Rahul-Sutariya Rahul-Sutariya changed the title feat(qemu): make Qemu class extensible and QemuProcess injectable feat(qemu): add _extra_qemu_args() hook Jul 17, 2026
@lurtz

lurtz commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

How does it then work, if the subclassed Qemu object cannot be injected?

@ltekieli

Copy link
Copy Markdown
Member

How does it then work, if the subclassed Qemu object cannot be injected?

@lurtz can you elaborate?

@lurtz

lurtz commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

@ltekieli My assumption was the @Rahul-Sutariya intended to subclass the Qemu class. The child class provides an implementation of _extra_qemu_args(self) and thus need to be injected into QemuProcess.

With the removal of the optional constructor argument I fail to understand how the child class can be injected. However I am not a Python expert and there might be another trick you are about to explain to me.

@ltekieli

Copy link
Copy Markdown
Member

How does it then work, if the subclassed Qemu object cannot be injected?

@lurtz can you elaborate?

check the code snippet, instead of injecting the Custom class is instantiated directly in the subclass:

class CustomQemuProcess(QemuProcess):
    def __init__(self, path_to_qemu_image, available_ram, available_cores, **kwargs):
        super().__init__(path_to_qemu_image, available_ram, available_cores, **kwargs)
        self._qemu = CustomQemu(
            path_to_qemu_image,
            available_ram,
            available_cores,
            network_adapters=self._network_adapters,
            port_forwarding=self._port_forwarding,
        )

@lurtz

lurtz commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

@ltekieli I understand now. Thank you, it should work

@ltekieli
ltekieli added this pull request to the merge queue Jul 17, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 17, 2026
@ltekieli
ltekieli added this pull request to the merge queue Jul 17, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 17, 2026
@ltekieli
ltekieli added this pull request to the merge queue Jul 17, 2026
Merged via the queue into eclipse-score:main with commit 54cab4f Jul 17, 2026
7 checks passed
@github-project-automation github-project-automation Bot moved this from Backlog to Done in TST - Testing Community Jul 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants