Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 40 additions & 2 deletions crates/quake/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,9 +344,23 @@ pub(crate) fn generate_jwt_secret(testnet_dir: &Path, force: bool) -> Result<()>
/// can write to mounted volumes. Required on Linux where bind-mount permissions are strict.
pub(crate) fn set_local_testnet_directory_permissions(
testnet_dir: &Path,
monitoring_dir: &Path,
node_names: &[String],
) -> Result<()> {
let logs_dir = testnet_dir.join("logs");
let writable_dirs = [
logs_dir.clone(),
monitoring_dir.join("data").join("grafana"),
monitoring_dir.join("data").join("prometheus"),
testnet_dir.join("blockscout").join("logs"),
testnet_dir.join("blockscout").join("dets"),
Comment on lines +353 to +356
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Monitoring directories should not be created here. There's a setup method in MonitoringManager for that.

];

for dir in &writable_dirs {
fs::create_dir_all(dir)
.with_context(|| format!("Failed to create directory: {}", dir.display()))?;
}

for name in node_names {
let reth_dir = testnet_dir.join(name).join("reth");
fs::create_dir_all(&reth_dir)
Expand All @@ -358,8 +372,6 @@ pub(crate) fn set_local_testnet_directory_permissions(
#[cfg(unix)]
{
let perms = fs::Permissions::from_mode(0o777);
fs::set_permissions(&logs_dir, perms.clone())
.with_context(|| format!("Failed to set permissions on {}", logs_dir.display()))?;
for name in node_names {
let node_dir = testnet_dir.join(name);
if node_dir.exists() {
Expand All @@ -374,6 +386,10 @@ pub(crate) fn set_local_testnet_directory_permissions(
})?;
}
}
for dir in &writable_dirs {
fs::set_permissions(dir, perms.clone())
.with_context(|| format!("Failed to set permissions on {}", dir.display()))?;
}
}
Ok(())
}
Expand Down Expand Up @@ -1237,6 +1253,28 @@ mod tests {
);
}

#[test]
fn local_testnet_directory_permissions_create_service_volume_dirs() {
let dir = tempdir().unwrap();
let testnet_dir = dir.path().join("localdev");
let monitoring_dir = dir.path().join("monitoring");
let node_names = vec!["validator1".to_string()];

set_local_testnet_directory_permissions(&testnet_dir, &monitoring_dir, &node_names)
.unwrap();

for path in [
monitoring_dir.join("data").join("grafana"),
monitoring_dir.join("data").join("prometheus"),
testnet_dir.join("blockscout").join("logs"),
testnet_dir.join("blockscout").join("dets"),
testnet_dir.join("validator1").join("reth"),
testnet_dir.join("validator1").join("sockets"),
] {
assert!(path.is_dir(), "expected {} to exist", path.display());
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Extend the test to also verify that the directories have the correct permissions.

Suggested change
}
#[cfg(unix)]
{
use std::os::unix::fs::PermissionsExt;
let writable_dirs = [
testnet_dir.join("logs"),
monitoring_dir.join("data").join("grafana"),
monitoring_dir.join("data").join("prometheus"),
testnet_dir.join("blockscout").join("logs"),
testnet_dir.join("blockscout").join("dets"),
];
for path in &writable_dirs {
let mode = fs::metadata(path).unwrap().permissions().mode() & 0o777;
assert_eq!(mode, 0o777, "{} mode = {:o}, want 0o777", path.display(), mode);
}
}
}


#[test]
fn generate_app_private_keys_creates_correct_number() {
let dir = tempdir().unwrap();
Expand Down
7 changes: 6 additions & 1 deletion crates/quake/src/testnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,12 @@ impl Testnet {
// For local testnets, create EL reth dirs and set permissions so containers (user arc) can write
if self.infra_data.infra_type == InfraType::Local {
let node_names: Vec<String> = self.manifest.nodes.keys().cloned().collect();
setup::set_local_testnet_directory_permissions(&self.dir, &node_names)?;
let monitoring_dir = self.quake_dir.join("monitoring");
setup::set_local_testnet_directory_permissions(
&self.dir,
&monitoring_dir,
&node_names,
)?;
}

// In remote mode, provision the Control Center server
Expand Down