Commit baf8d886 authored by Kamil Iskra's avatar Kamil Iskra

Merge branch 'fail-empty-sets' into 'master'

Strengthen tests for invalid input

Closes #2

See merge request !5
parents a09400ed a22998a9
......@@ -454,17 +454,22 @@ bool Container_manager::is_legal_create_command(String_parser& sp)
if(sp.get_string("name", name))
HANDLE_CM_ERROR_IF(!is_name_available(name), this,
string("Another container already has the name ") + strval);
else
THROW_ON_BAD_INPUT("name is missing");
bval = false;
bval = true;
sp.get_bool("cpu_exclusive", bval);
if(sp.get_int_list("cpus", intvect))
{
HANDLE_CM_ERROR_IF(!are_resources_available<int>(_cpu_ownerships,
intvect, bval), this,
string("At least part of the requested CPU cores is unavailable") +
(bval? string(" exclusively.") : string(".")));
HANDLE_CM_ERROR_IF(intvect.size() == 0, this, "cpu list is empty");
}
else
THROW_ON_BAD_INPUT("cpu list is missing");
bval = false;
sp.get_bool("cpu_exclusive", bval);
if(sp.get_added_int_list("cpus", intvect))
HANDLE_CM_ERROR_IF(!are_resources_available<int>(_cpu_ownerships,
intvect, bval), this,
......@@ -474,13 +479,16 @@ bool Container_manager::is_legal_create_command(String_parser& sp)
bval = false;
sp.get_bool("mem_exclusive", bval);
if(sp.get_int_list("mems", intvect))
{
HANDLE_CM_ERROR_IF(!are_resources_available<int>(_mem_ownerships,
intvect, bval), this,
string("At least part of the requested memory nodes is unavailable") +
(bval? string(" exclusively.") : string(".")));
HANDLE_CM_ERROR_IF(intvect.size() == 0, this, "memory list is empty");
}
else
THROW_ON_BAD_INPUT("memory list is missing");
bval = false;
sp.get_bool("mem_exclusive", bval);
if(sp.get_added_int_list("mems", intvect))
HANDLE_CM_ERROR_IF(!are_resources_available<int>(_mem_ownerships,
intvect, bval), this,
......@@ -778,19 +786,29 @@ void Container_manager::create_service_os(string command)
vector<int> cpus;
sp.get_int_list("cpus", cpus);
if(sp.get_int_list("cpus", cpus))
{
THROW_ON_FORBIDDEN_ACTION_IF(!are_resources_available<int>(_cpu_ownerships,
cpus, true),
string("At least part of the requested CPU cores is unavailable"));
THROW_ON_FORBIDDEN_ACTION_IF(!_cpu_ownerships.are_unused(cpus),
"Some of the CPU cores requested are already in use");
THROW_ON_FORBIDDEN_ACTION_IF(cpus.size() == 0, "cpu list is empty");
}
else
THROW_ON_FORBIDDEN_ACTION("cpu list is missing");
vector<int> mems;
sp.get_int_list("mems", mems);
if (sp.get_int_list("mems", mems))
{
THROW_ON_FORBIDDEN_ACTION_IF(!are_resources_available<int>(_mem_ownerships,
mems, true),
string("At least part of the requested memory nodes is unavailable"));
THROW_ON_FORBIDDEN_ACTION_IF(!_cpu_ownerships.are_unused(cpus),
"Some of the CPU cores requested are already in use");
THROW_ON_FORBIDDEN_ACTION_IF(!_mem_ownerships.are_unused(cpus),
"Some of the memory nodes requested are already in use");
THROW_ON_FORBIDDEN_ACTION_IF(mems.size() == 0, "memory list is empty");
}
else
THROW_ON_FORBIDDEN_ACTION("memory list is missing");
_cpu_ownerships.transfer_to(cpus, _sos_cpu_ownerships);
_mem_ownerships.transfer_to(mems, _sos_mem_ownerships);
_argo_containers_root->remove_cpus(cpus);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment