Skip to content

Commit

Permalink
Disable usage of sum with CPUs
Browse files Browse the repository at this point in the history
  • Loading branch information
Kobzol committed Sep 12, 2023
1 parent 4d87b45 commit 170614f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 9 deletions.
34 changes: 25 additions & 9 deletions crates/hyperqueue/src/client/commands/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,24 +183,40 @@ fn gather_configuration(opts: WorkerStartOpts) -> anyhow::Result<WorkerConfigura
let hostname = get_hostname(hostname);

let mut resources: Vec<_> = resource.into_iter().map(|x| x.into_parsed_arg()).collect();
if !resources.iter().any(|x| x.name == CPU_RESOURCE_NAME) {
resources.push(ResourceDescriptorItem {
name: CPU_RESOURCE_NAME.to_string(),
kind: if let Some(cpus) = cpus {
let cpu_resources = resources.iter().find(|x| x.name == CPU_RESOURCE_NAME);
let specified_cpu_resource = match cpu_resources {
Some(item) => {
if cpus.is_some() {
bail!("Parameters --cpus and --resource cpus=... cannot be combined");
}
item.kind.clone()
}
None => {
let kind = if let Some(cpus) = cpus {
cpus.into_parsed_arg()
} else {
detect_cpus()?
},
})
} else if cpus.is_some() {
bail!("Parameters --cpus and --resource cpus=... cannot be combined");
};
resources.push(ResourceDescriptorItem {
name: CPU_RESOURCE_NAME.to_string(),
kind: kind.clone(),
});
kind
}
};

if matches!(
specified_cpu_resource,
tako::resources::ResourceDescriptorKind::Sum { .. }
) {
bail!("Resource kind `sum` cannot be used with CPUs. CPUs must have identity");
}

if no_hyper_threading {
let cpus = resources
.iter_mut()
.find(|x| x.name == CPU_RESOURCE_NAME)
.unwrap();
.expect("No CPUs resource found");
cpus.kind = prune_hyper_threading(&cpus.kind)?;
}

Expand Down
18 changes: 18 additions & 0 deletions tests/test_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,3 +298,21 @@ def test_resource_name_ensure_normalization(hq_env: HqEnv):

with open(default_task_output()) as f:
assert f.read() == "1 compact\n0\n"


def test_cpu_resource_sum(hq_env: HqEnv):
hq_env.start_server()

hq_env.command(
args=["worker", "start", "--cpus=sum(5)"],
expect_fail="Resource kind `sum` cannot be used with CPUs",
)


def test_manual_cpu_resource_sum(hq_env: HqEnv):
hq_env.start_server()

hq_env.command(
args=["worker", "start", "--resource", "cpus=sum(5)"],
expect_fail="Resource kind `sum` cannot be used with CPUs",
)

0 comments on commit 170614f

Please sign in to comment.