Skip to content

Commit

Permalink
Rename suite name --> suite ID
Browse files Browse the repository at this point in the history
Suite names are handled by Robot Framework, suite IDs are part of our
configuration.
  • Loading branch information
jherbel committed Nov 27, 2023
1 parent ef121e4 commit d5fdc2e
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 43 deletions.
18 changes: 9 additions & 9 deletions v2/robotmk/src/bin/scheduler/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,30 +49,30 @@ fn build_environment(
) -> Result<Option<Suite>> {
let suite = match suite.environment.build_instructions() {
Some(build_instructions) => {
info!("Building environment for suite {}", suite.name);
info!("Building environment for suite {}", suite.id);
let start_time = Utc::now().timestamp();
environment_build_states_administrator
.update(&suite.name, EnvironmentBuildStatus::InProgress(start_time))?;
.update(&suite.id, EnvironmentBuildStatus::InProgress(start_time))?;
let environment_build_status = run_environment_build(
ChildProcessSupervisor {
command_spec: &build_instructions.command_spec,
stdio_paths: Some(StdioPaths {
stdout: stdio_directory.join(format!("{}.stdout", suite.name)),
stderr: stdio_directory.join(format!("{}.stderr", suite.name)),
stdout: stdio_directory.join(format!("{}.stdout", suite.id)),
stderr: stdio_directory.join(format!("{}.stderr", suite.id)),
}),
timeout: build_instructions.timeout,
termination_flag: &suite.termination_flag,
},
start_time,
)?;
let drop_suite = matches!(environment_build_status, EnvironmentBuildStatus::Failure(_));
environment_build_states_administrator.update(&suite.name, environment_build_status)?;
environment_build_states_administrator.update(&suite.id, environment_build_status)?;
(!drop_suite).then_some(suite)
}
None => {
debug!("Nothing to do for suite {}", suite.name);
debug!("Nothing to do for suite {}", suite.id);
environment_build_states_administrator
.update(&suite.name, EnvironmentBuildStatus::NotNeeded)?;
.update(&suite.id, EnvironmentBuildStatus::NotNeeded)?;
Some(suite)
}
};
Expand Down Expand Up @@ -144,7 +144,7 @@ pub struct RCCEnvironment {

impl Environment {
pub fn new(
suite_name: &str,
suite_id: &str,
rcc_binary_path: &Utf8Path,
environment_config: &EnvironmentConfig,
) -> Self {
Expand All @@ -154,7 +154,7 @@ impl Environment {
binary_path: rcc_binary_path.to_path_buf(),
robot_yaml_path: rcc_environment_config.robot_yaml_path.clone(),
controller: String::from("robotmk"),
space: suite_name.to_string(),
space: suite_id.to_string(),
build_timeout: rcc_environment_config.build_timeout,
env_json_path: rcc_environment_config.env_json_path.clone(),
}),
Expand Down
22 changes: 11 additions & 11 deletions v2/robotmk/src/bin/scheduler/internal_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub struct GlobalConfig {

#[derive(Clone)]
pub struct Suite {
pub name: String,
pub id: String,
pub working_directory: Utf8PathBuf,
pub results_file: Utf8PathBuf,
pub execution_interval_seconds: u32,
Expand All @@ -46,14 +46,14 @@ pub fn from_external_config(
let mut suites: Vec<Suite> = external_config
.suites
.into_iter()
.map(|(suite_name, suite_config)| Suite {
name: suite_name.clone(),
.map(|(suite_id, suite_config)| Suite {
id: suite_id.clone(),
working_directory: external_config
.working_directory
.join("suites")
.join(&suite_name),
.join(&suite_id),
results_file: suite_results_directory(&external_config.results_directory)
.join(format!("{}.json", suite_name)),
.join(format!("{}.json", suite_id)),
execution_interval_seconds: suite_config.execution_config.execution_interval_seconds,
timeout: suite_config.execution_config.timeout,
robot: Robot {
Expand All @@ -63,7 +63,7 @@ pub fn from_external_config(
retry_strategy: suite_config.execution_config.retry_strategy,
},
environment: Environment::new(
&suite_name,
&suite_id,
&external_config.rcc_binary_path,
&suite_config.environment_config,
),
Expand All @@ -75,7 +75,7 @@ pub fn from_external_config(
results_directory_locker: results_directory_locker.clone(),
})
.collect();
sort_suites_by_name(&mut suites);
sort_suites_by_id(&mut suites);
(
GlobalConfig {
working_directory: external_config.working_directory,
Expand All @@ -88,8 +88,8 @@ pub fn from_external_config(
)
}

pub fn sort_suites_by_name(suites: &mut [Suite]) {
suites.sort_by_key(|suite| suite.name.to_string());
pub fn sort_suites_by_id(suites: &mut [Suite]) {
suites.sort_by_key(|suite| suite.id.to_string());
}

#[cfg(test)]
Expand Down Expand Up @@ -169,7 +169,7 @@ mod tests {
assert_eq!(global_config.results_directory, "/results");
assert_eq!(global_config.rcc_binary_path, "/bin/rcc");
assert_eq!(suites.len(), 2);
assert_eq!(suites[0].name, "rcc");
assert_eq!(suites[0].id, "rcc");
assert_eq!(suites[0].working_directory, "/working/suites/rcc");
assert_eq!(suites[0].results_file, "/results/suites/rcc.json");
assert_eq!(suites[0].execution_interval_seconds, 300);
Expand Down Expand Up @@ -204,7 +204,7 @@ mod tests {
suites[0].working_directory_cleanup_config,
WorkingDirectoryCleanupConfig::MaxExecutions(50),
);
assert_eq!(suites[1].name, "system");
assert_eq!(suites[1].id, "system");
assert_eq!(suites[1].working_directory, "/working/suites/system");
assert_eq!(suites[1].results_file, "/results/suites/system.json");
assert_eq!(suites[1].execution_interval_seconds, 300);
Expand Down
8 changes: 4 additions & 4 deletions v2/robotmk/src/bin/scheduler/results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl<'a> EnvironmentBuildStatesAdministrator<'a> {
) -> Result<EnvironmentBuildStatesAdministrator<'a>> {
let build_states: HashMap<_, _> = suites
.iter()
.map(|suite| (suite.name.to_string(), EnvironmentBuildStatus::Pending))
.map(|suite| (suite.id.to_string(), EnvironmentBuildStatus::Pending))
.collect();
let path = results_directory.join("environment_build_states.json");
BuildStates(&build_states).write(&path, locker)?;
Expand All @@ -73,8 +73,8 @@ impl<'a> EnvironmentBuildStatesAdministrator<'a> {
})
}

pub fn update(&mut self, suite_name: &str, build_status: EnvironmentBuildStatus) -> Result<()> {
self.build_states.insert(suite_name.into(), build_status);
pub fn update(&mut self, suite_id: &str, build_status: EnvironmentBuildStatus) -> Result<()> {
self.build_states.insert(suite_id.into(), build_status);
BuildStates(&self.build_states).write(&self.path, self.locker)
}
}
Expand All @@ -97,7 +97,7 @@ pub enum EnvironmentBuildStatusError {

#[derive(Serialize)]
pub struct SuiteExecutionReport {
pub suite_name: String,
pub suite_id: String,
pub outcome: ExecutionReport,
}

Expand Down
4 changes: 2 additions & 2 deletions v2/robotmk/src/bin/scheduler/scheduling/cleanup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ pub fn cleanup_working_directories<'a>(suites: impl Iterator<Item = &'a Suite>)
for suite in suites {
debug!(
"Cleaning up working directory {} of suite {}",
suite.working_directory, suite.name
suite.working_directory, suite.id
);
let _ = cleanup_working_directory(
&suite.working_directory,
&suite.working_directory_cleanup_config,
)
.context(format!(
"Error while cleaning up working directory of suite {}",
suite.name
suite.id
))
.map_err(log_and_return_error);
}
Expand Down
2 changes: 1 addition & 1 deletion v2/robotmk/src/bin/scheduler/scheduling/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ fn wait_until_all_suites_have_terminated(suites: &[Suite]) {
let mut still_running = vec![];
for suite in still_running_suites {
let _ = try_acquire_suite_lock(suite).map_err(|_| {
error!("Suite {} is still running", suite.name);
error!("Suite {} is still running", suite.id);
still_running.push(suite)
});
}
Expand Down
16 changes: 8 additions & 8 deletions v2/robotmk/src/bin/scheduler/scheduling/suites.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub fn run_suite(suite: &Suite) -> Result<()> {
// We hold the lock as long as `_non_parallel_guard` is in scope
let _non_parallel_guard = try_acquire_suite_lock(suite).map_err(|err| {
let report = SuiteExecutionReport {
suite_name: suite.name.clone(),
suite_id: suite.id.clone(),
outcome: ExecutionReport::AlreadyRunning,
};
report
Expand All @@ -32,9 +32,9 @@ pub fn run_suite(suite: &Suite) -> Result<()> {
.unwrap_or(err)
})?;

debug!("Running suite {}", &suite.name);
debug!("Running suite {}", &suite.id);
let report = SuiteExecutionReport {
suite_name: suite.name.clone(),
suite_id: suite.id.clone(),
outcome: ExecutionReport::Executed(produce_suite_results(suite)?),
};
report
Expand All @@ -44,7 +44,7 @@ pub fn run_suite(suite: &Suite) -> Result<()> {
&suite.results_directory_locker,
)
.context("Reporting suite results failed")?;
debug!("Suite {} finished", &suite.name);
debug!("Suite {} finished", &suite.id);

Ok(())
}
Expand All @@ -56,11 +56,11 @@ pub fn try_acquire_suite_lock(suite: &Suite) -> Result<MutexGuard<usize>> {
TryLockError::WouldBlock => {
bail!(
"Failed to acquire lock for suite {}, skipping this run",
suite.name
suite.id
);
}
TryLockError::Poisoned(poison_error) => {
error!("Lock for suite {} poisoned, unpoisoning", suite.name);
error!("Lock for suite {} poisoned, unpoisoning", suite.id);
Ok(poison_error.into_inner())
}
},
Expand Down Expand Up @@ -129,10 +129,10 @@ fn run_attempt(
attempt: Attempt,
output_directory: &Utf8Path,
) -> Result<(AttemptOutcome, Option<Utf8PathBuf>)> {
let log_message_start = format!("Suite {}, attempt {}", suite.name, attempt.index);
let log_message_start = format!("Suite {}, attempt {}", suite.id, attempt.index);

let run_outcome = match suite.session.run(&RunSpec {
id: &format!("robotmk_suite_{}_attempt_{}", suite.name, attempt.index),
id: &format!("robotmk_suite_{}_attempt_{}", suite.id, attempt.index),
command_spec: &suite.environment.wrap(attempt.command_spec),
base_path: &output_directory.join(attempt.index.to_string()),
timeout: suite.timeout,
Expand Down
2 changes: 1 addition & 1 deletion v2/robotmk/src/bin/scheduler/setup/general.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn setup_working_directories(working_directory: &Utf8Path, suites: &[Suite]) ->
for suite in suites {
create_dir_all(&suite.working_directory).context(format!(
"Failed to create working directory {} of suite {}",
suite.working_directory, suite.name
suite.working_directory, suite.id
))?;
}
create_dir_all(environment_building_stdio_directory(working_directory))
Expand Down
13 changes: 6 additions & 7 deletions v2/robotmk/src/bin/scheduler/setup/rcc.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::icacls::run_icacls_command;
use crate::command_spec::CommandSpec;
use crate::environment::Environment;
use crate::internal_config::{sort_suites_by_name, GlobalConfig, Suite};
use crate::internal_config::{sort_suites_by_id, GlobalConfig, Suite};
use crate::logging::log_and_return_error;
use crate::results::RCCSetupFailures;
use crate::sessions::session::{CurrentSession, RunOutcome, RunSpec, Session};
Expand All @@ -24,7 +24,7 @@ pub fn setup(global_config: &GlobalConfig, suites: Vec<Suite>) -> Result<Vec<Sui
.into_iter()
.partition(|suite| matches!(suite.environment, Environment::Rcc(_)));
surviving_suites.append(&mut rcc_setup(global_config, rcc_suites)?);
sort_suites_by_name(&mut surviving_suites);
sort_suites_by_id(&mut surviving_suites);
Ok(surviving_suites)
}

Expand Down Expand Up @@ -62,7 +62,7 @@ fn rcc_setup(global_config: &GlobalConfig, rcc_suites: Vec<Suite>) -> Result<Vec
let (sucessful_suites, failed_suites) = disable_rcc_telemetry(global_config, rcc_suites)
.context("Disabling RCC telemetry failed")?;
rcc_setup_failures.telemetry_disabling =
failed_suites.into_iter().map(|suite| suite.name).collect();
failed_suites.into_iter().map(|suite| suite.id).collect();
if !rcc_setup_failures.telemetry_disabling.is_empty() {
error!(
"Dropping the following suites due to RCC telemetry disabling failure: {}",
Expand All @@ -75,7 +75,7 @@ fn rcc_setup(global_config: &GlobalConfig, rcc_suites: Vec<Suite>) -> Result<Vec
enable_long_path_support(global_config, sucessful_suites)
.context("Enabling support for long paths failed")?;
rcc_setup_failures.long_path_support =
failed_suites.into_iter().map(|suite| suite.name).collect();
failed_suites.into_iter().map(|suite| suite.id).collect();
if !rcc_setup_failures.long_path_support.is_empty() {
error!(
"Dropping the following suites due to long path support enabling failure: {}",
Expand All @@ -86,8 +86,7 @@ fn rcc_setup(global_config: &GlobalConfig, rcc_suites: Vec<Suite>) -> Result<Vec
debug!("Initializing shared holotree");
let (sucessful_suites, failed_suites) = shared_holotree_init(global_config, sucessful_suites)
.context("Shared holotree initialization failed")?;
rcc_setup_failures.shared_holotree =
failed_suites.into_iter().map(|suite| suite.name).collect();
rcc_setup_failures.shared_holotree = failed_suites.into_iter().map(|suite| suite.id).collect();
if !rcc_setup_failures.shared_holotree.is_empty() {
error!(
"Dropping the following suites due to shared holotree initialization failure: {}",
Expand All @@ -98,7 +97,7 @@ fn rcc_setup(global_config: &GlobalConfig, rcc_suites: Vec<Suite>) -> Result<Vec
debug!("Initializing holotree");
let (sucessful_suites, failed_suites) =
holotree_init(global_config, sucessful_suites).context("Holotree initialization failed")?;
rcc_setup_failures.holotree_init = failed_suites.into_iter().map(|suite| suite.name).collect();
rcc_setup_failures.holotree_init = failed_suites.into_iter().map(|suite| suite.id).collect();
if !rcc_setup_failures.holotree_init.is_empty() {
error!(
"Dropping the following suites due to holotree initialization failure: {}",
Expand Down

0 comments on commit d5fdc2e

Please sign in to comment.