1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-12 09:17:41 +03:00

B #6861: Check termination time for scheduled actions

* ScheduledAction::is_due check termination time
* VM is Make sure VM is updated when EndOn==TIMES

co-author: Michal Opala <mopala@opennebula.io>
This commit is contained in:
Ruben S. Montero 2023-04-18 14:53:48 +02:00
parent 4a017a891f
commit 7f2a35b1ba
No known key found for this signature in database
GPG Key ID: A0CEA6FA880A1D87

View File

@ -177,9 +177,9 @@ int SchedAction::ends_in_range(EndOn eo, std::string& error)
return -2;
}
if ( eo == TIMES && end_value <= 0 )
if ( eo == TIMES && end_value < 0 )
{
error = "Error parsing END_VALUE, times has to be greater than 0";
error = "Error parsing END_VALUE, times has to be >= 0";
return -1;
}
else if ( eo == DATE )
@ -328,17 +328,63 @@ time_t SchedAction::get_time(time_t stime)
bool SchedAction::is_due(time_t stime)
{
time_t action_time, done_time;
int repeat;
// -------------------------------------------------------------------------
// Check action has already finished (END_TYPE and END_VALUE defined)
// -------------------------------------------------------------------------
Repeat r;
EndOn eo;
bool has_done = vector_value("DONE", done_time) == 0;
bool has_repeat = vector_value("REPEAT", repeat) == 0;
if ( repeat(r) == -1 )
{
return false; //Parse error - consistency check
}
action_time = get_time(stime);
bool has_repeat = r != NONE;
bool has_ended = false;
return (action_time != -1)
&& ((!has_done || done_time < action_time || has_repeat)
&& action_time < time(0));
time_t end_value;
if (endon(eo) == 0 && vector_value("END_VALUE", end_value) != -1)
{
switch (eo)
{
case END_NONE:
case NEVER:
has_ended = false;
break;
case TIMES:
has_ended = end_value <= 0;
break;
case DATE:
has_ended = time(0) > end_value;
break;
}
}
if (has_repeat && has_ended)
{
return false;
}
// -------------------------------------------------------------------------
// Check if the action has been completed
// -------------------------------------------------------------------------
time_t due_time, done_time;
bool has_done = vector_value("DONE", done_time) == 0;
due_time = get_time(stime);
if (due_time == -1)
{
return false; //Parse error
}
if (has_done && done_time >= due_time)
{
return false; //Action has been already completed
}
return due_time < time(0); //Action is due
}
/* -------------------------------------------------------------------------- */