Skip to content

Commit

Permalink
Move global RCC configuration to dedicated struct
Browse files Browse the repository at this point in the history
In the next commit, we will extend this struct to include a RCC profile
path.

CMK-15162
  • Loading branch information
jherbel committed Dec 4, 2023
1 parent ba6d550 commit 87d95ce
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 19 deletions.
19 changes: 13 additions & 6 deletions v2/robotmk/src/bin/scheduler/internal_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::results::suite_results_directory;
use crate::rf::robot::Robot;
use crate::sessions::session::Session;
use robotmk::{
config::{Config, WorkingDirectoryCleanupConfig},
config::{Config, RCCConfig, WorkingDirectoryCleanupConfig},
lock::Locker,
section::Host,
};
Expand All @@ -16,7 +16,7 @@ use tokio_util::sync::CancellationToken;
pub struct GlobalConfig {
pub working_directory: Utf8PathBuf,
pub results_directory: Utf8PathBuf,
pub rcc_binary_path: Utf8PathBuf,
pub rcc_config: RCCConfig,
pub cancellation_token: CancellationToken,
pub results_directory_locker: Locker,
}
Expand Down Expand Up @@ -64,7 +64,7 @@ pub fn from_external_config(
},
environment: Environment::new(
&suite_id,
&external_config.rcc_binary_path,
&external_config.rcc_config.binary_path,
&suite_config.environment_config,
),
session: Session::new(&suite_config.session_config),
Expand All @@ -80,7 +80,7 @@ pub fn from_external_config(
GlobalConfig {
working_directory: external_config.working_directory,
results_directory: external_config.results_directory,
rcc_binary_path: external_config.rcc_binary_path,
rcc_config: external_config.rcc_config,
cancellation_token,
results_directory_locker,
},
Expand Down Expand Up @@ -155,7 +155,9 @@ mod tests {
Config {
working_directory: Utf8PathBuf::from("/working"),
results_directory: Utf8PathBuf::from("/results"),
rcc_binary_path: Utf8PathBuf::from("/bin/rcc"),
rcc_config: RCCConfig {
binary_path: Utf8PathBuf::from("/bin/rcc"),
},
suites: HashMap::from([
(String::from("system"), system_suite_config()),
(String::from("rcc"), rcc_suite_config()),
Expand All @@ -166,7 +168,12 @@ mod tests {
);
assert_eq!(global_config.working_directory, "/working");
assert_eq!(global_config.results_directory, "/results");
assert_eq!(global_config.rcc_binary_path, "/bin/rcc");
assert_eq!(
global_config.rcc_config,
RCCConfig {
binary_path: Utf8PathBuf::from("/bin/rcc"),
}
);
assert_eq!(suites.len(), 2);
assert_eq!(suites[0].id, "rcc");
assert_eq!(suites[0].working_directory, "/working/suites/rcc");
Expand Down
10 changes: 5 additions & 5 deletions v2/robotmk/src/bin/scheduler/setup/rcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use std::collections::HashMap;
use std::fs::{create_dir_all, remove_dir_all};

pub fn setup(global_config: &GlobalConfig, suites: Vec<Suite>) -> Result<Vec<Suite>> {
adjust_rcc_binary_permissions(&global_config.rcc_binary_path)
adjust_rcc_binary_permissions(&global_config.rcc_config.binary_path)
.context("Failed to adjust permissions of RCC binary")?;
clear_rcc_setup_working_directory(&rcc_setup_working_directory(
&global_config.working_directory,
Expand Down Expand Up @@ -121,7 +121,7 @@ fn disable_rcc_telemetry(
global_config,
suites,
&CommandSpec {
executable: global_config.rcc_binary_path.to_string(),
executable: global_config.rcc_config.binary_path.to_string(),
arguments: vec![
"configure".into(),
"identity".into(),
Expand All @@ -140,7 +140,7 @@ fn enable_long_path_support(
global_config,
suites,
&CommandSpec {
executable: global_config.rcc_binary_path.to_string(),
executable: global_config.rcc_config.binary_path.to_string(),
arguments: vec!["configure".into(), "longpaths".into(), "--enable".into()],
},
"long_path_support_enabling",
Expand All @@ -155,7 +155,7 @@ fn shared_holotree_init(
global_config,
suites,
&CommandSpec {
executable: global_config.rcc_binary_path.to_string(),
executable: global_config.rcc_config.binary_path.to_string(),
arguments: vec![
"holotree".into(),
"shared".into(),
Expand All @@ -175,7 +175,7 @@ fn holotree_init(
global_config,
suites,
&CommandSpec {
executable: global_config.rcc_binary_path.to_string(),
executable: global_config.rcc_config.binary_path.to_string(),
arguments: vec!["holotree".into(), "init".into()],
},
"holotree_initialization",
Expand Down
7 changes: 6 additions & 1 deletion v2/robotmk/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@ pub fn load(path: &Utf8Path) -> Result<Config> {
pub struct Config {
pub working_directory: Utf8PathBuf,
pub results_directory: Utf8PathBuf,
pub rcc_binary_path: Utf8PathBuf,
pub rcc_config: RCCConfig,
pub suites: HashMap<String, SuiteConfig>,
}

#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct RCCConfig {
pub binary_path: Utf8PathBuf,
}

#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct SuiteConfig {
pub robot_framework_config: RobotFrameworkConfig,
Expand Down
16 changes: 9 additions & 7 deletions v2/robotmk/tests/test_scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use anyhow::Result;
use assert_cmd::cargo::cargo_bin;
use camino::{Utf8Path, Utf8PathBuf};
use robotmk::config::{
Config, EnvironmentConfig, ExecutionConfig, RCCEnvironmentConfig, RetryStrategy,
Config, EnvironmentConfig, ExecutionConfig, RCCConfig, RCCEnvironmentConfig, RetryStrategy,
RobotFrameworkConfig, SessionConfig, SuiteConfig, UserSessionConfig,
WorkingDirectoryCleanupConfig,
};
Expand Down Expand Up @@ -34,7 +34,7 @@ async fn test_scheduler() -> Result<()> {

assert_working_directory(&config.working_directory, &current_user_name).await?;
assert_results_directory(&config.results_directory);
assert_rcc(&config.rcc_binary_path).await?;
assert_rcc(&config.rcc_config).await?;

Ok(())
}
Expand All @@ -48,7 +48,9 @@ fn create_config(
Config {
working_directory: test_dir.join("working"),
results_directory: test_dir.join("results"),
rcc_binary_path: rcc_binary_path.into(),
rcc_config: RCCConfig {
binary_path: rcc_binary_path.into(),
},
suites: [
(
String::from("rcc_headless"),
Expand Down Expand Up @@ -249,10 +251,10 @@ fn assert_results_directory(results_directory: &Utf8Path) {
);
}

async fn assert_rcc(rcc_binary_path: impl AsRef<OsStr>) -> Result<()> {
assert_rcc_binary_permissions(&rcc_binary_path).await?;
assert_rcc_configuration(&rcc_binary_path).await?;
assert_rcc_longpath_support_enabled(&rcc_binary_path).await
async fn assert_rcc(rcc_config: &RCCConfig) -> Result<()> {
assert_rcc_binary_permissions(&rcc_config.binary_path).await?;
assert_rcc_configuration(&rcc_config.binary_path).await?;
assert_rcc_longpath_support_enabled(&rcc_config.binary_path).await
}

async fn assert_rcc_binary_permissions(rcc_binary_path: impl AsRef<OsStr>) -> Result<()> {
Expand Down

0 comments on commit 87d95ce

Please sign in to comment.