Skip to content

Commit 8a5b407

Browse files
authored
feat: [NODE-1859] Update config, regardless of NO keys (#10800)
Bring the HostOS config versions up to the latest version, regardless of the state of the Node Operator private key. (In file, in config, or neither.)
1 parent 3943343 commit 8a5b407

4 files changed

Lines changed: 57 additions & 39 deletions

File tree

rs/ic_os/config/tool/src/main.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -264,33 +264,34 @@ pub fn main() -> Result<()> {
264264
let mut hostos_config: HostOSConfig =
265265
config_tool::deserialize_config(&hostos_config_json_path)?;
266266

267-
if !node_operator_private_key_path.exists() {
268-
println!(
269-
"Node operator private key file not found at {}. Skipping update.",
270-
node_operator_private_key_path.display()
271-
);
267+
if hostos_config.config_version == CONFIG_VERSION {
268+
println!("Config already up to date. Skipping update.");
269+
272270
return Ok(());
273271
}
274272

273+
// Fill the NO key from the old keyfile, only if missing.
275274
if hostos_config
276275
.icos_settings
277276
.node_operator_private_key
278-
.is_some()
277+
.is_none()
279278
{
280-
println!("Node operator private key already present in config. Skipping update.");
281-
return Ok(());
279+
hostos_config.icos_settings.node_operator_private_key =
280+
fs::read_to_string(&node_operator_private_key_path)
281+
.map_err(|_| {
282+
println!(
283+
"Node operator private key file not found at {}.",
284+
node_operator_private_key_path.display()
285+
)
286+
})
287+
.ok();
282288
}
283289

284-
let node_operator_private_key = fs::read_to_string(&node_operator_private_key_path)
285-
.context("unable to read node operator private key")?;
286-
287-
hostos_config.icos_settings.node_operator_private_key = Some(node_operator_private_key);
288290
hostos_config.config_version = CONFIG_VERSION.to_string();
289-
290291
serialize_and_write_config(&hostos_config_json_path, &hostos_config)?;
291292

292293
println!(
293-
"HostOS config updated with node operator private key and written to {}",
294+
"HostOS config updated and written to {}",
294295
hostos_config_json_path.display()
295296
);
296297

rs/ic_os/config/tool/src/setupos/deployment_json.rs

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -63,25 +63,6 @@ mod test {
6363
use super::*;
6464
use config_types::HostOSDevSettings;
6565
use once_cell::sync::Lazy;
66-
use serde_json::{Value, json};
67-
68-
static DEPLOYMENT_VALUE: Lazy<Value> = Lazy::new(|| {
69-
json!({
70-
"deployment": {
71-
"deployment_environment": "mainnet",
72-
"mgmt_mac": null
73-
},
74-
"nns": {
75-
"urls": ["https://icp-api.io", "https://icp0.io", "https://ic0.app"]
76-
},
77-
"dev_vm_resources": {
78-
"memory": "16",
79-
"cpu": "kvm",
80-
"nr_of_vcpus": 64
81-
}
82-
}
83-
)
84-
});
8566

8667
const DEPLOYMENT_STR: &str = r#"{
8768
"deployment": {
@@ -119,14 +100,19 @@ mod test {
119100

120101
#[test]
121102
fn deserialize_deployment() {
122-
let parsed_deployment = { serde_json::from_str(DEPLOYMENT_STR).unwrap() };
103+
let parsed_deployment = serde_json::from_str(DEPLOYMENT_STR).unwrap();
104+
105+
assert_eq!(*DEPLOYMENT_STRUCT, parsed_deployment);
106+
107+
// Exercise DeserializeOwned using serde_json::from_reader. This is the
108+
// main entrypoint of this code, in practice.
109+
let parsed_deployment = serde_json::from_reader(DEPLOYMENT_STR.as_bytes()).unwrap();
123110

124111
assert_eq!(*DEPLOYMENT_STRUCT, parsed_deployment);
125112

126-
// Exercise DeserializeOwned using serde_json::from_value.
127-
// DeserializeOwned is used by serde_json::from_reader, which is the
113+
// Exercise DeserializeOwned using serde_json::from_reader. This is the
128114
// main entrypoint of this code, in practice.
129-
let parsed_deployment = { serde_json::from_value(DEPLOYMENT_VALUE.clone()).unwrap() };
115+
let parsed_deployment = serde_json::from_reader(DEPLOYMENT_STR.as_bytes()).unwrap();
130116

131117
assert_eq!(*DEPLOYMENT_STRUCT, parsed_deployment);
132118
}

rs/ic_os/config/types/compatibility_tests/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ rust_test(
4747
deps = [
4848
":config_types_compatibility_lib",
4949
"//rs/ic_os/config/types:config_types",
50+
"@crate_index//:serde",
5051
"@crate_index//:serde_json",
5152
],
5253
)

rs/ic_os/config/types/compatibility_tests/tests/compatibility_tests.rs

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,41 @@ fn test_backwards_compatibility() {
1313

1414
if filename.starts_with("hostos_") {
1515
serde_json::from_str::<HostOSConfig>(&config_json).unwrap_or_else(|e| {
16-
panic!("Failed to deserialize historical HostOSConfig from {filename}: {e}")
16+
panic!(
17+
"Failed to deserialize historical HostOSConfig from borrowed {filename}: {e}"
18+
)
19+
});
20+
21+
// Exercise DeserializeOwned using serde_json::from_reader. This is
22+
// the main entrypoint of this code, in practice.
23+
let config = serde_json::from_reader::<_, HostOSConfig>(config_json.as_bytes())
24+
.unwrap_or_else(|e| {
25+
panic!(
26+
"Failed to deserialize historical HostOSConfig from owned {filename}: {e}"
27+
)
28+
});
29+
30+
serde_json::to_string_pretty(&config).unwrap_or_else(|e| {
31+
panic!("Failed to serialize HostOSConfig sourced from {filename}: {e}")
1732
});
1833
} else if filename.starts_with("guestos_") {
1934
serde_json::from_str::<GuestOSConfig>(&config_json).unwrap_or_else(|e| {
20-
panic!("Failed to deserialize historical GuestOSConfig from {filename}: {e}")
35+
panic!(
36+
"Failed to deserialize historical GuestOSConfig from borrowed {filename}: {e}"
37+
)
38+
});
39+
40+
// Exercise DeserializeOwned using serde_json::from_reader. This is
41+
// the main entrypoint of this code, in practice.
42+
let config = serde_json::from_reader::<_, GuestOSConfig>(config_json.as_bytes())
43+
.unwrap_or_else(|e| {
44+
panic!(
45+
"Failed to deserialize historical GuestOSConfig from owned {filename}: {e}"
46+
)
47+
});
48+
49+
serde_json::to_string_pretty(&config).unwrap_or_else(|e| {
50+
panic!("Failed to serialize GuestOSConfig sourced from {filename}: {e}")
2151
});
2252
}
2353

0 commit comments

Comments
 (0)