Skip to content

Add a fake backend for component tests - #78

Open
lforchini wants to merge 2 commits into
create-comptest-utilsfrom
test/fake-backend
Open

lforchini wants to merge 2 commits into
create-comptest-utilsfrom
test/fake-backend

Conversation

@lforchini

Copy link
Copy Markdown
Collaborator

The harness needs a VM the daemon can discover and scale without
libvirt. JSON files carry the snapshot, and set_thread_count records
each target so tests can assert behavior.

Signed-off-by: Leonardo Forchini leonardo.forchini@nutanix.com


Stack created with GitHub Stacks CLI • Give Feedback 💬

@lforchini
lforchini added this pull request to stack #83 October 1, 2026 14:37
@lforchini
lforchini removed this pull request from stack #83 October 1, 2026 14:50
@lforchini
lforchini added this pull request to stack #84 October 1, 2026 14:50
@lforchini
lforchini removed this pull request from stack #84 October 5, 2026 08:12
@lforchini
lforchini changed the base branch from test/refactor to test/remove-to-be-component October 5, 2026 08:16
@lforchini
lforchini added this pull request to stack #87 October 5, 2026 08:16
@lforchini
lforchini marked this pull request as ready for review October 5, 2026 08:28
@lforchini
lforchini force-pushed the test/fake-backend branch 2 times, most recently from 413624e to 707c7bd Compare October 8, 2026 07:30
@lforchini
lforchini removed this pull request from stack #87 October 8, 2026 15:22
@lforchini
lforchini added this pull request to stack #88 October 8, 2026 15:23
@lforchini
lforchini removed this pull request from stack #88 October 13, 2026 12:32
@lforchini
lforchini force-pushed the test/fake-backend branch 2 times, most recently from 1b68f8d to a451ed1 Compare October 23, 2026 08:39
@lforchini
lforchini removed this pull request from stack #152 October 23, 2026 08:44
@lforchini
lforchini changed the base branch from test/remove-to-be-component to create-comptest-utils October 23, 2026 08:44
@lforchini
lforchini added this pull request to stack #157 October 23, 2026 08:45
@lforchini
lforchini removed this pull request from stack #157 October 23, 2026 08:49
@lforchini
lforchini added this pull request to stack #159 October 23, 2026 08:50
@lforchini
lforchini removed this pull request from stack #159 October 30, 2026 10:48
@lforchini
lforchini added this pull request to stack #173 October 30, 2026 10:50
@lforchini
lforchini removed this pull request from stack #173 November 5, 2026 15:02
@lforchini
lforchini added this pull request to stack #176 November 5, 2026 15:03
@lforchini
lforchini removed this pull request from stack #176 November 5, 2026 15:09
@lforchini
lforchini added this pull request to stack #178 November 5, 2026 15:10
The harness needs a VM the daemon can discover and scale without
libvirt. JSON files carry the snapshot, and set_thread_count records
each target so tests can assert behavior.

Signed-off-by: Leonardo Forchini <leonardo.forchini@nutanix.com>
Add a Python component test interface for the FakeBackend. It is able to
read the JSON files used by the backend and provides utilities to modify
the 'VM's as required by tests.

AI-Generated: Most of it
Signed-off-by: Leonardo Forchini <leonardo.forchini@nutanix.com>

@tmakatos tmakatos left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I haven't looked at the methods of the FakeBacked class yet. How do you plan to create the tasks on /proc?

Comment thread src/backends/fake/mod.rs

//! File-backed backend for component tests.
//!
//! Instead of requiring a running QEMU instance, this backend manages

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This reads like we still use QEMU except that we're not running it. I assume you mean that we use a backend that doesn't require QEMU at all. The fact that it's file-based is secondary.

Comment thread src/backends/fake/mod.rs

//! File-backed backend for component tests.
//!
//! Instead of requiring a running QEMU instance, this backend manages

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can you also add a paragraph how this backend behaves? E.g. whether you pre-configure some performance counter values that it will return when queried by the controller etc. I feel like test backend is a more suitable name, and it could be used as a n example backend as well, could you document this in the README?

Comment thread src/backends/fake/mod.rs
//!
//! Instead of requiring a running QEMU instance, this backend manages
//! state through JSON files in `state_dir`. This allows for the external
//! Python component testing harness to manipulate "VM"s as necessary.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

You don't explain what happens after the harness has modified the files, does the backend blindly re-read everything when asked by the controller?

Comment thread src/backends/fake/mod.rs
continue;
};
let Some(vm) = read_vm(&path, id) else {
continue;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why ignore the failure?

Comment thread src/backends/fake/mod.rs
for entry in entries.flatten() {
let path = entry.path();
if path.extension().and_then(|ext| ext.to_str()) != Some("json") {
continue;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Are we expecting irrelevant files which we should ignore?

Comment thread src/backends/fake/mod.rs
#[async_trait]
impl InstanceClient for FakeClient {
async fn set_thread_count(&self, count: u32) -> Result<(), BackendClientError> {
let _guard = LockGuard::acquire(&lock_path_for(&self.vm_path))?;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why not lock the VM json file? Or better the entire VM directory? This way we wouldn't need the read/write methods in impl VmFile?

from harness.common import physical

DEFAULT_VM = "vm-a"
STATE_DIR = "/var/fake"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Shouldn't we use a directory in /tmp?


DEFAULT_VM = "vm-a"
STATE_DIR = "/var/fake"
OWNERSHIP_FILE = "/run/io-thread-controller/vm-ownership.json"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

unused



class FakeBackend:
"""JSON VM directory the ``fake`` backend discovers."""

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This class represents a directory?

self, threads: int, util: float, io: int = 0, vcpu: int = 16
) -> None:
"""Set the default VM's threads, utilisation, vCPU cap, and read I/O."""
self.set_threads(threads)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Not sure we need those function separate if they're used only once, given how simple they are. Can you open code other such functions, if any?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants