add a per-agent nix builds mode, host or none, carried like privateUsers
This commit is contained in:
parent
b9484e62a0
commit
5485151ba6
2 changed files with 618 additions and 58 deletions
|
|
@ -9,6 +9,8 @@
|
|||
//! Keyed by the agent alone, like [`crate::agent_limits`]: an agent can move
|
||||
//! between hives, and its closure goes with it.
|
||||
|
||||
use hive_types::NixBuilds;
|
||||
|
||||
/// The KV bucket closures are recorded in, keyed by agent name.
|
||||
pub const BUCKET: &str = "agent-closures";
|
||||
|
||||
|
|
@ -42,6 +44,11 @@ pub struct AgentClosure {
|
|||
/// false, which keeps the agent out of one.
|
||||
#[serde(default)]
|
||||
pub private_users: bool,
|
||||
/// The agent's `services.hyperhive.agent.nixBuilds`: where its nix builds
|
||||
/// run. A record written before the field existed reads as
|
||||
/// [`NixBuilds::Host`], which is what every agent did before it.
|
||||
#[serde(default)]
|
||||
pub nix_builds: NixBuilds,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
@ -63,6 +70,7 @@ mod tests {
|
|||
built_unix: 7,
|
||||
cached: true,
|
||||
private_users: true,
|
||||
nix_builds: NixBuilds::Disabled,
|
||||
};
|
||||
let wire = serde_json::json!({
|
||||
"meta_rev": "abc",
|
||||
|
|
@ -71,6 +79,7 @@ mod tests {
|
|||
"built_unix": 7,
|
||||
"cached": true,
|
||||
"private_users": true,
|
||||
"nix_builds": "none",
|
||||
});
|
||||
assert_eq!(serde_json::to_value(&value).expect("encodes"), wire);
|
||||
assert_eq!(
|
||||
|
|
@ -80,7 +89,7 @@ mod tests {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn a_record_without_the_fields_reads_as_not_cached_and_not_namespaced() {
|
||||
fn a_record_without_the_fields_reads_as_not_cached_not_namespaced_and_host_builds() {
|
||||
let old = serde_json::json!({
|
||||
"meta_rev": "abc",
|
||||
"store_path": "/nix/store/x",
|
||||
|
|
@ -90,5 +99,6 @@ mod tests {
|
|||
let record = serde_json::from_value::<AgentClosure>(old).expect("decodes");
|
||||
assert!(!record.cached);
|
||||
assert!(!record.private_users);
|
||||
assert_eq!(record.nix_builds, NixBuilds::Host);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
use std::time::Duration;
|
||||
|
||||
use hive_types::NixBuilds;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// The subject every build goes to. The controller is its one publisher and
|
||||
|
|
@ -154,6 +155,11 @@ pub enum FromMetaReply {
|
|||
/// predates the field answers without it, which reads as false.
|
||||
#[serde(default)]
|
||||
private_users: bool,
|
||||
/// The agent's `services.hyperhive.agent.nixBuilds`. A builder that
|
||||
/// predates the field answers without it, which reads as
|
||||
/// [`NixBuilds::Host`].
|
||||
#[serde(default)]
|
||||
nix_builds: NixBuilds,
|
||||
},
|
||||
/// The build did not succeed: the last lines `nix` printed, or why it
|
||||
/// stopped (it timed out, or could not start). The controller holds the
|
||||
|
|
@ -268,6 +274,7 @@ mod tests {
|
|||
system: "x86_64-linux".to_owned(),
|
||||
cached: true,
|
||||
private_users: true,
|
||||
nix_builds: NixBuilds::Disabled,
|
||||
},
|
||||
json!({
|
||||
"state": "built",
|
||||
|
|
@ -275,6 +282,7 @@ mod tests {
|
|||
"system": "x86_64-linux",
|
||||
"cached": true,
|
||||
"private_users": true,
|
||||
"nix_builds": "none",
|
||||
}),
|
||||
),
|
||||
(
|
||||
|
|
@ -299,7 +307,8 @@ mod tests {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn a_built_reply_from_a_builder_without_the_fields_reads_as_not_cached_and_not_namespaced() {
|
||||
fn a_built_reply_from_a_builder_without_the_fields_reads_as_not_cached_not_namespaced_and_host_builds()
|
||||
{
|
||||
let old = json!({"state": "built", "out_path": "/nix/store/x", "system": "s"});
|
||||
assert_eq!(
|
||||
serde_json::from_value::<FromMetaReply>(old).expect("decodes"),
|
||||
|
|
@ -308,6 +317,7 @@ mod tests {
|
|||
system: "s".to_owned(),
|
||||
cached: false,
|
||||
private_users: false,
|
||||
nix_builds: NixBuilds::Host,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue