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

F #1548: Fixed bug with don't have END_TYPE (#2094)

This commit is contained in:
juanmont 2018-05-16 16:58:50 +02:00 committed by Ruben S. Montero
parent cba51889eb
commit 658453c842
2 changed files with 23 additions and 14 deletions

View File

@ -85,9 +85,9 @@ public:
* @param eo end type (date, times) * @param eo end type (date, times)
* @param error in case of error * @param error in case of error
* *
* @return true if days are in range false (error) if not * @return 0 if days are in range -1 (error) if not or -2 (not defined)
*/ */
bool ends_in_range(EndOn eo, std::string& error); int ends_in_range(EndOn eo, std::string& error);
/** /**
* This function parse and checks the sched action attributes: REPEAT, DAYS * This function parse and checks the sched action attributes: REPEAT, DAYS

View File

@ -59,7 +59,7 @@ int SchedAction::endon(EndOn& eo)
if ( et_s.empty() ) if ( et_s.empty() )
{ {
return 0; return -2;
} }
std::istringstream iss(et_s); std::istringstream iss(et_s);
@ -164,7 +164,7 @@ bool SchedAction::days_in_range(Repeat r, std::string& error)
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
bool SchedAction::ends_in_range(EndOn eo, std::string& error) int SchedAction::ends_in_range(EndOn eo, std::string& error)
{ {
int end_value; int end_value;
int rc = vector_value("END_VALUE", end_value); int rc = vector_value("END_VALUE", end_value);
@ -172,13 +172,13 @@ bool SchedAction::ends_in_range(EndOn eo, std::string& error)
if ( rc == -1 && eo != NEVER ) if ( rc == -1 && eo != NEVER )
{ {
error = "Missing END_VALUE"; error = "Missing END_VALUE";
return false; 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 greater than 0";
return false; return -1;
} }
else if ( eo == DATE ) else if ( eo == DATE )
{ {
@ -191,11 +191,11 @@ bool SchedAction::ends_in_range(EndOn eo, std::string& error)
if (out == -1) if (out == -1)
{ {
error = "Error parsing END_VALUE, wrong format for date."; error = "Error parsing END_VALUE, wrong format for date.";
return false; return -1;
} }
} }
return true; return 0;
} }
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
@ -205,6 +205,7 @@ int SchedAction::parse(std::string& error, bool clean)
{ {
Repeat r; Repeat r;
EndOn eo; EndOn eo;
int rc_e, rc_ev;
if ( repeat(r) == -1 ) if ( repeat(r) == -1 )
{ {
@ -212,21 +213,29 @@ int SchedAction::parse(std::string& error, bool clean)
return -1; return -1;
} }
if ( endon(eo) == -1 ) rc_e = endon(eo);
rc_ev = ends_in_range(eo, error);
if ( rc_e == -1 )
{ {
error = "Error parsing END_TYPE attribute"; error = "Error parsing END_TYPE attribute";
return -1; return -1;
} }
else if ( rc_e == -2 && rc_ev != -2 )
{
error = "Error END_VALUE defined but not valid END_TYPE found";
return -1;
}
else if ( rc_e == 0 && rc_ev != 0 )
{
return -1;
}
if ( !days_in_range(r, error) ) if ( !days_in_range(r, error) )
{ {
return -1; return -1;
} }
if ( !ends_in_range(eo, error) )
{
return -1;
}
if (clean) if (clean)
{ {